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?
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?
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?
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
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
Bookmarks