1) Copy robocopy.exe from the Resource Kit to something like c:\backup\tools. This is used in step 5 below.
2) Create a backup list using the GUI version. Save a system state only as night.bks, save all the drives and system state as night-all.bks. Make sure you use the backup directory path listed below in the script or modify to a SAN location.
3) Use the follow for the required .bat file
C:\backup\tools\nightlybackup.bat:
*** BEGIN BAT FILE ***
@ECHO OFF
REM
REM Build Date String yyyymmddhhmm
REM
for /F "usebackq tokens=2" %%i IN (`DATE /T`) DO Set TIMESTR=%%i%
for /F "usebackq tokens=1,2,3 delims=/" %%i IN ('%TIMESTR%') DO SET MONTH=%%i%
for /F "usebackq tokens=1,2,3 delims=/" %%i IN ('%TIMESTR%') DO SET DAY=%%j%
for /F "usebackq tokens=1,2,3 delims=/" %%i IN ('%TIMESTR%') DO SET YEAR=%%k%
for /F "usebackq" %%i IN (`Time /T`) DO Set TIMESTR=%%i%
for /F "usebackq tokens=1,2* delims=:" %%i IN ('%TIMESTR%') DO SET HOUR=%%i%
for /F "usebackq tokens=1,2* delims=:" %%i IN ('%TIMESTR%') DO SET MINUTE=%%j%
SET DIRSTR=%YEAR%%MONTH%%DAY%%HOUR%%MINUTE%
SET TIMESTR=
SET MONTH=
SET DAY=
SET YEAR=
SET HOUR=
SET MINUTE=
@ECHO Directory String %DIRSTR%
IF NOT EXIST “c:\backup\tools\nightlybackup.bat” GOTO SKIP
C:\WINDOWS\system32\ntbackup.exe backup "@\\DOMAINCONTROLLERNAME\c$\Backup_DCNAME\night-all.bks" /n "DCNAME.bkf" /d "Nightly" /v:yes /r:no /rs:no /hc:off /m normal /j "Nightly" /l:s /f "\\DOMAINCONTROLLERNAME\C$\Backup_DCNAME\%DIRSTR%DCNAME.bkf"
EXIT
:SKIP
C:\WINDOWS\system32\ntbackup.exe backup "@\\DOMAINCONTROLLERNAME \c$\Backup_DCNAME \night.bks" /n "DCNAME.bkf" /d "SS_Nightly" /v:yes /r:no /rs:no /hc:off /m normal /j "SS_Nightly" /l:s /f "\\DOMAINCONTROLLERNAME\C$\Backup_DCNAME\%DIRSTR%DCNAME.bkf"
EXIT
*** END BAT FILE ***
Comments and legend for the above batch file.
First I turn of echo
Next section builds the current date, we will use this to sort the backup and delete ones older than 7 days.
If not exist statement is useful if you store anything on a SAN drive. If they SAN is down normally the backup will fail, so I check before and then just run night to just backup the system state.
First backup runs a backup of the DOMAINCONTROLLERNAME (replace with a real name), creates a new file called DCNAME.bkf (replace with server name), next I label the backup Nightly, verify is then turned on, restricted access is NOT turned on – you may want it though (so /r:yes would turn it on), hardware compression is turned off, the backup type is set to normal, next the job name is set for backup reporting, next logging is set to summary, and finally the file name is created with the date and time stamp at the front (again for sorting and deleting older files later).
4) To schedule a task to automatically backup a machine. Go to Start-> Control Panel -> Scheduled Tasks -> Add Scheduled Task. During the configuration the following options are selected:
|
Scheduled Task Wizard |
Next |
|
Scheduled Task Wizard Application |
Browse C:\backup\tools\nightlybackup.bat Open |
|
Scheduled Task Wizard Type a name for this task Perform this task |
Nightly Daily Next |
|
Scheduled Task Wizard Start Time Perform this task Start date |
3:15 AM Every Day (today) Next |
|
Scheduled Task Wizard Enter the user name Enter the password Confirm password |
Next |
|
Scheduled Task Wizard Open advanced… |
Unchecked Finish |
5) Finally I use robocopy to clean up, so the backup won’t fill up the disk.
c:\backup\tools\robocopy c:\backup\ c:\backup\t *.bkf /MOV /MINAGE:10 rd /q /s c:\backup\t
I use Robocopy to look at the c:\backup and create a c:\backup\t folder (for temporary). I look for anything that ends with .bkf which is then Moved to the temporary (c:\backup\t) folder, if it is at least 10 days old. This process is done quietly and uses a sub directory of c:\backup\t.
Enjoy, let me know if you have any questions or issues.