troubleshooting Question

Windows backup script - Better way to determine current day?

Avatar of Ubertam
UbertamFlag for United States of America asked on
Windows BatchWindows Server 2003Shell Scripting
4 Comments2 Solutions1761 ViewsLast Modified:
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
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.
ASKER CERTIFIED SOLUTION
MAdS

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros