We help IT Professionals succeed at work.
Get Started

Windows backup script - Better way to determine current day?

1,760 Views
Last Modified: 2012-04-24
I've got this backup script I use to back up using ntbackup to our NAS and have it automatically cull old files.  The backups are growing and I needed to eliminate the number of normal backups by one and increase retention to 2 weeks (normal backup every other week).  I changed the backup script to go for 2 full weeks, but out of the blue, it created empty folders for 11-Wednesday and 13-Friday (on the 11th and the 13th, in fact).  I think it's related to how the batch file is determining the day of the week.

Is there a better way to do this?

:HOME
net use G: /delete /y
net use \\YoyosRUsbackup\backup /delete /y
IF NOT EXIST G:\ net use G: \\YoyosRUsbackup\backup /user:admin YoyosRUsPassword
g:
cd\
IF NOT EXIST Weekly CALL d:\cycle.bat
cd Weekly
IF NOT EXIST 0 CALL d:\cycle.bat
cd 0

IF NOT EXIST 01-Sunday GOTO SUNDAY

:DATES
for /f %%a in ('date /t') do set DAY=%%a
IF %DAY%==Sun EXIT
IF %DAY%==Mon GOTO MONDAY
IF %DAY%==Tue GOTO TUESDAY
IF %DAY%==Wed GOTO WEDNESDAY
IF %DAY%==Thu GOTO THURSDAY
IF %DAY%==Fri GOTO FRIDAY
IF %DAY%==Sat GOTO SUNDAY

:SUNDAY
IF EXIST 01-Sunday GOTO SATURDAY
md 01-Sunday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\Full.bks" /n "Backup created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m normal /j "Full" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\01-Sunday\YoyosRUsfull.bkf"
exit

:MONDAY
IF EXIST 02-Monday GOTO MONDAY2
md 02-Monday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\02-Monday\YoyosRUsinc.bkf"
exit

:TUESDAY
IF EXIST 03-Tuesday GOTO TUESDAY2
md 03-Tuesday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\03-Tuesday\YoyosRUsinc.bkf"
exit

:WEDNESDAY
IF EXIST 04-Wednesday GOTO WEDNESDAY2
md 04-Wednesday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\04-Wednesday\YoyosRUsinc.bkf"
exit

:THURSDAY
IF EXIST 05-Thursday GOTO THURSDAY2
md 05-Thursday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\05-Thursday\YoyosRUsinc.bkf"
exit

:FRIDAY
IF EXIST 06-Friday GOTO FRIDAY2
md 06-Friday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\06-Friday\YoyosRUsinc.bkf"
exit

:SATURDAY
IF EXIST 07-Saturday GOTO SUNDAY2
md 07-Saturday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\02-Monday\YoyosRUsinc.bkf"
exit

:SUNDAY2
IF EXIST 08-Sunday GOTO SATBREAK
md 08-Sunday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\03-Tuesday\YoyosRUsinc.bkf"
exit

:MONDAY2
IF EXIST 09-Monday GOTO SATBREAK
md 09-Monday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\04-Wednesday\YoyosRUsinc.bkf"
exit

:TUESDAY2
IF EXIST 10-Tuesday GOTO SATBREAK
md 10-Tuesday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\05-Thursday\YoyosRUsinc.bkf"
exit

:WEDNESDAY2
IF EXIST 11-Wednesday GOTO SATBREAK
md 11-Wednesday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\06-Friday\YoyosRUsinc.bkf"
exit

:THURSDAY2
IF EXIST 12-Thursday GOTO SATBREAK
md 12-Thursday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\05-Thursday\YoyosRUsinc.bkf"
exit

:FRIDAY2
IF EXIST 13-Friday GOTO SATBREAK
md 13-Friday
C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\ChiqutaBanana\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\YoyosRUsDiff.bks" /n "YoyosRUsinc.bkf created %DATE% at %TIME%" /d "Set created 7/20/2010" /v:no /r:yes /rs:no /hc:off /m incremental /j "YoyosRUsInc" /l:s /f "\\YoyosRUsbackup\backup\Weekly\0\06-Friday\YoyosRUsinc.bkf"
exit

:SATBREAK
CALL d:\cycle.bat
GOTO HOME

Open in new window

This script runs every day at 6:00PM.  It also runs Saturday at 3AM (so it can run it's full backup, which would go into the 01-Sunday folder).  The full backup usually takes around 60 hours to run (hence why I want it to start right after the differential backup should be finished).

Any hints on how to run this better?  Am I getting the days wrong?  Is there a VB version that works better?  Thanks.
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE