Wednesday, March 17, 2010

NTBackup Batch Script - File Names by Date

I had a client that needed a NTBackup Script that created backup file names by date. I wrote one but it took me 45 minutes so I thought I'd put it on the internet.

for /f "tokens=2-4" %%i in ('echo %date%') do (
set today=%%i
)
for /f "tokens=1-3 delims=/" %%a in ('echo %today%') do (
set month=%%a
set day=%%b
set year=%%c
)

C:\WINDOWS\system32\ntbackup.exe backup "@C:\BackupSelection.bks" /v:yes /r:no /rs:no /hc:off /m normal /j "BackupJob" /l:s /f "C:\%year%-%month%-%day%.bkf"

4 comments:

  1. I have been using a scrip like this for FTP downloads. I am needing to add 4 days to todays date. Any Ideas?

    @Echo Off

    Echo Setting Date Variables...

    for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
    for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
    for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b

    Echo Building FTP Text File...

    set ftpascii=bmfm.txt

    echo XXXXXXX>%ftpascii%
    echo XXXXXXX>>%ftpascii%
    echo lcd d:\bmfm>>%ftpascii%
    echo bin>>%ftpascii%
    echo hash>>%ftpascii%
    echo cd /focus/us/custom-programs/WIBI/bmfm/>>%ftpascii%
    echo mget bmfm-WIBI-%month%-%day%.mp2>>%ftpascii%
    echo close>>%ftpascii%
    echo bye>>%ftpascii%

    ReplyDelete
  2. That's a bit nice that is.
    I ended up modifying it a bit, but this was a very useful starting point.
    Thank you!

    ReplyDelete
  3. great job, that is what i need ;-) thanks

    ReplyDelete