Nt backup isn’t pretty, it can be a little temperamental and requires you to keep on top of it at all times… but so is every other product on the market.
I have chosen to keep a network location for all the backups you will create for your servers, this will aid in organizing log files, and backing up each daily backup from one resource. There are so many options available, with incremental s, dailies, full and shadow copies i have decided to keep it simple with full backups daily, but once you have an idea of how the script works theres nothing stopping you from configuring it to suit yourself.
To kick off the guts of this three parter I’ll start with writing the script you will need to backup your infrastructure to a single disk space.
Well to begin, lets start with some simple variables:
set logfiledir=”%userprofile%Local SettingsApplication DataMicrosoftwindows ntNTBackupdata”
FOR /F “usebackq tokens=1-4 delims=/ ” %%d IN (`date /t`) DO set cdate=%%d%%e%%f
FOR /F “usebackq tokens=1,2 delims=: ” %%t IN (`time /t`) do set ctime=%%t%%u
del /q %logfiledir%*.log
well with the above, i am specifying that the %logfiledir% is where ntbackup saves its log files. i will use this var to copy the log files out and have them available for a quick “once a day” review to make sure the backups ran. %logdest% & %backdes% are variables for defining where you are going to store your log files, and backup files respectively.
The two For commands are used to create a cdate and ctime variable for the current date and time, we will use this to rename the files later on in the script.
the del statement simply cleans up the log file dir before we begin to ensure there are no old logs.
Rem — System state backup —
ntbackup backup systemstate /f %backdes%%computername%-systemstate-%cdate%.bkf /j “systemstate” /l:s
FOR /F “usebackq tokens=1″ %%n IN (`dir %logfiledir% /b`) DO ren %logfiledir%%%n %computername%-“systemstate”-%cdate%.log
move /y %logfiledir%*.log %logdest%
Kicking off with systemstate, ntbackup runs taking a snapshot of the servers system state and saving it as servername-systemstate-date.bkf in the folder you defined in %backdes%.
The for statement after the script may look a little strange, this is old code i have used before to save a file using the date and time as a file name. all this simply says is: for all the files in %logfiledir% rename them to servername-systemstate-date.log
Once the file is renamed, the script moves the logfile off to the %logdest%, creating a report of your system state backup.
Rem — hard drive backup —
Rem — Copy and paste from here downwards for multiple drives—
ntbackup backup c: /f %backdes%%computername%-cdrive-%cdate%.bkf /j “C Drive” /l:s
FOR /F “usebackq tokens=1″ %%n IN (`dir %logfiledir% /b`) DO ren %logfiledir%%%n %computername%-“Cdrive“-%cdate%.log
move /y %logfiledir%*.log %logdest%
Rem — end copy —
Now the above is a drive backup, as with the last portion, the script kicks off a backup of the system drive c: calling the file computername%-cdrive-date.bkf saving it in %backdes%. Once the backup is complete it will rename the logfile to servername-“Cdrive”-date.log and move it to the logdest folder.
if you wish to backup more than one drive, i.e. C:, D: and E: simply copy and paste from the Rem’s specified above changing the bold text.
And thats it! you now have a fully functioning backup script that will backup system state and the drives you specify and will save them in a network folder for you to commit to tape, or move off site each day.
The script in full is available here: