Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



Batch file for Daily backup with Robocopy

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-08-2007
Dave Allen
 
Posts: n/a
Batch file for Daily backup with Robocopy

I need assistance writing a daily backup batch file using Robocopy
What I want to do is back to a destination of YYYY-MO\YYYY-MO-DY\

For example
Robocopy D:\Data\ E:\Backup\YYYY-MO\YYYY-MO-DA\ /a /s /b /r:2 /w:1

How do I pass the month day and year?
Reply With Quote
  #2  
Old 07-08-2007
Joshua Bynon
 
Posts: n/a
Re: Batch file for Daily backup with Robocopy

You can use the variables %date% and %time%, but I am not sure whether you
can customise the format.

echo Time is %time% on the %date%

mkdir D:\Data\ E:\Backup\%date%

"Dave Allen" <nomail@namail.com> wrote in message
news:%23lWXymH2HHA.1484@TK2MSFTNGP06.phx.gbl...
>I need assistance writing a daily backup batch file using Robocopy
> What I want to do is back to a destination of YYYY-MO\YYYY-MO-DY\
>
> For example
> Robocopy D:\Data\ E:\Backup\YYYY-MO\YYYY-MO-DA\ /a /s /b /r:2 /w:1
>
> How do I pass the month day and year?


Reply With Quote
  #3  
Old 07-08-2007
JakeDAHS
 
Posts: n/a
Re: Batch file for Daily backup with Robocopy

On Aug 6, 6:31 pm, "Dave Allen" <nom...@namail.com> wrote:
> I need assistance writing a daily backup batch file using Robocopy
> What I want to do is back to a destination of YYYY-MO\YYYY-MO-DY\
>
> For example
> Robocopy D:\Data\ E:\Backup\YYYY-MO\YYYY-MO-DA\ /a /s /b /r:2 /w:1
>
> How do I pass the month day and year?


Probably not the best way to do it but..

set owsh = createobject("wscript.shell")

sSourceFolder = "C:\temp\temp\temp123\"
sDestinationFolder = "C:\temp\" & year(now) & "-" & month(now) & "\" &
year(now) & "-" & month(now) & "-" & day(now) & "\"

wscript.echo sdestinationfolder

sCommand = "%comspec% /c Robocopy "
sCommand = sCommand & sSourceFolder & " "
sCommand = sCommand & sDestinationFolder & " "
sCommand = sCommand & " /a /s /b /r:2 /w:1"

wscript.echo sCommand

set x = owsh.exec(sCommand)

do until x.stdout.atendofstream
wscript.echo x.stdout.readline
loop


-j

Reply With Quote
  #4  
Old 08-01-2009
Member
 
Join Date: Jan 2009
Posts: 1
Re: Batch file for Daily backup with Robocopy

I use this batch file with xcopy. Here is how I solve the date issue. I plan to use robocopy now intsead of xcopy.

@echo off
color 0A
:: Make Dated Backup File
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set cdate=%%c-%%a
for /f "tokens=1-3 delims=/ " %%a in ('DATE/T') do set ddate=%%c-%%a
for /f "tokens=1-3 delims=/: " %%a in ('TIME/T') do set hdate=%%c%%a
for /f "tokens=2-4 delims=/: " %%a in ('TIME/T') do set tdate=%%c-%%a
echo %ddate% ddate
echo %cdate% Cdate
echo %hdate% HDate
echo %tdate% Tdate

mkdir \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\


echo "%cdate%_%ddate%"_"%hdate%%tdate%" commencing Stecey Goffs bacup >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\Master.backuplog\Master-bacup.log


:: copy documents
Echo Commencing backup of \\192.168.1.2\Documents and Settings
Echo Commencing backup of My Documents > \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt
xcopy "\\192.168.1.2\Documents and Settings\john.doe\*.*" \\Hidta-d96h99f1\hidta-isc-backup\john.doe\ /c /s /r /d /y /i/h/z >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt 2>> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-errors.txt
Echo Backup of \\192.168.1.2\Documents and Settings
Echo Backup of \\192.168.1.2\Documents and Settings >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt


:: copy V-ONE
Echo Commencing backup of V-ONE
Echo Commencing backup of V-ONE >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt
xcopy "\\192.168.1.2\V-ONE\*.*" \\Hidta-d96h99f1\hidta-isc-backup\john.doe\V-ONE\ /c /s /r /d /y /i/h/z >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt 2>> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-errors.txt
Echo Backup of V-ONE Complete
Echo Backup of V-ONE Complete >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt

:: copy mail
Echo Commencing backup of mail
Echo Commencing backup of mail >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt
xcopy "\\192.168.1.2\mail\*.*" \\Hidta-d96h99f1\hidta-isc-backup\john.doe\mail\ /c /s /r /d /y /i/h/z >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt 2>> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-errors.txt
Echo Backup of mail Complete
Echo Backup of mail Complete >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt

:: copy all
Echo Commencing backup of all
Echo Commencing backup of all >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt
xcopy "\\192.168.1.2\all\*.*" \\Hidta-d96h99f1\hidta-isc-backup\john.doe\all\ /c /s /r /d /y /i/h/z >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt 2>> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-errors.txt
Echo Backup of all Complete
Echo Backup of all Complete >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt



:: hostname
hostname >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt 2>> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-errors.txt
ipconfig >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt 2>> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-errors.txt

dir /s\\Hidta-d96h99f1\hidta-isc-backup\john.doe >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\john.doe\"%cdate%_%ddate%"_"%hdate%%tdate%"\stacey-xcopy.txt


echo "%cdate%_%ddate%"_"%hdate%%tdate%" finished john doe bacup >> \\Hidta-d96h99f1\hidta-isc-backup\hidta_backup_logs\Master.backuplog\Master-bacup.log
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Batch file for Daily backup with Robocopy"
Thread Thread Starter Forum Replies Last Post
Please help me with daily scoop and removing backup assistant from my LG phone Gag$nesh Portable Devices 5 08-07-2011 11:43 AM
Windows Server Backup using Robocopy Botan Windows Server Help 6 22-03-2011 02:37 AM
Backup Batch File Problem columbo1977 Software Development 1 08-10-2010 04:47 AM
How use Robocopy and incremental backup MarcusB Windows Server Help 7 26-03-2009 01:18 AM
Task Scheduler and Robocopy Batch Job bobneedshelp Vista Help 5 29-11-2007 09:58 PM


All times are GMT +5.5. The time now is 04:43 PM.