Jump to content

Recommended Posts

Posted

I am finally trying to get everything sorted with the backups here. What I use currently on each day is

 

C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\admin\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\daily.bks" /a /d "Set created %date:-=-%" /v:yes /r:no /hc:off /m differential /j "Daily Diff Backup" /l:s /f "\\san\storage\backup\monday.bkf"

 

Then for each day monday, becomes tuesday etc. But this means I need 4 scheduled tasks for Mon to Thur and a 5th for the Full backup on a Friday. What would be better is on task but it will put something like Monday_15/11/2010.bkf. Anyone have any ideas?

 

Thanks

Posted
Can't get the monday, tuesday etc. But have managed to get the date working. It's better than nothing, but if someone does know how to get the day in there aswell that would be great.
Posted
if someone does know how to get the day in there as well that would be great.

This will do it...

 

 

DailyDiff.cmd

@echo off & setlocal ENABLEEXTENSIONS

:: Functions
call :GetDate y m d
call :DateToDOW %y% %m% %d% dow
call :DayName %dow% day

:: Variables
SET BKSPATH=%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\Data\Daily.bks
SET BKFPATH=\\SAN\Storage\Backup\%day%.bkf

:: Start NTBackup
ntbackup.exe backup "@%BKSPATH%" /a /d "Set created %Date:/=-%" /v:yes /r:no /hc:off /m differential /j "Daily Diff Backup" /l:s /f "%BKFPATH%"

goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDate yy mm dd
::
:: Func: Loads local system date components into args 1 to 3.
::       For NT4/2000/XP/2003.
:: 
:: Args: %1 var to receive year, 4 digits (by ref)
::       %2 var to receive month, 2 digits, 01 to 12 (by ref)
::       %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
 for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
   set %%a=%%d&set %%b=%%e&set %%c=%%f))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DateToDOW %yy% %mm% %dd% dow
::
:: Func: Creates a day of week number from a calendar date, where 1 = Mon
::       and 7 = Sun. For NT4/2000/XP/2003.
:: 
:: Args: %1 year component to be converted, 2 or 4 digits (by val)
::       %2 month component to be converted, leading zero ok (by val)
::       %3 day of month to be converted, leading zero ok (by val)
::       %4 var to receive day of week number, 1 to 7 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,dow=153*m+2
set /a dow=dow/5+dd+y*365+y/4-y/100+y/400-2472630,dow%%=7,dow+=1
endlocal&set %4=%dow%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DayName %d% day
::
:: Func: Returns the day of week from the day number, 1=Monday, 7=Sunday.
::       For NT4/2000/XP/2003.
:: 
:: Args: %1 day number to convert to name of day of week, 1 to 7 (by val)
::       %2 var to receive name of day of week (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS
for /f "tokens=%1" %%a in ('echo/Monday Tuesday Wednesday Thursday Friday^
 Saturday Sunday') do endlocal&set %2=%%a&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: N.B. The functions above are from commandline.co.uk

  • Thanks 1
Posted

Very good point. That's actually what I do too since it ensures Windows sorts the files properly. To do this in the batch file I posted above, just replace line 10 with the code below...

 

SET BKFPATH=\\SAN\Storage\Backup\%y%-%m%-%d%_%day%.bkf

 

 

The filename for todays backup would become: 2010-11-15_Monday.bkf instead of just Monday.bkf. :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...