Home > Batch Scripting, Microsoft, NT Backup, Scripting > Ntbackup Part 1: Scripting Nt backup

Ntbackup Part 1: Scripting Nt backup

With the cost of newer backup software being very pricey to the small organization, its a wonder that the beautifully simple solution that is NTbackup has been overlooked so many times!

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 Settings\Application Data\Microsoft\windows nt\NTBackup\data”
set logdest=\\ient1dfs002\j$\backups\logs
set backdes=\\ient1dfs002\j$\backups

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:

  1. Derek
    February 25, 2009 at 3:14 pm

    Hello, I have stumbled upon you site from google,

    Question I have for you is regarding a network wide backup of workstations \Documents and Settings\%current user%\Application Data, and \Documents and Settings\%current user%\Local Data\Application Data\ using a similar script to yours just backup the user profile?

    First with your genius do you think this is possible? I know that if a script can be made for this we could setup the scheduled task remotely using at.exe. If you do not think this is possible please let me know as soon as possible so I can stop searching endlessly online for a possible solution using ntbackup and a network shared script. I appreciate you assistance thank you.

  2. Andrew Morgan
    February 25, 2009 at 3:51 pm

    Hi Derek,

    Its more than possible. I’ll send you an email.


  3. Anthony Paul
    May 25, 2009 at 10:35 pm

    I’m trying to use NTBackup to back up SBS 2003, I’ve been doing a lot of reading, but it is not clear to me if I can completely exclude the exchange DBs from the backup. It makes sense to me that this would be ok, as I figure when NTBackup backs up the Storage group, it is making a backup of these DB files? Is this correct? What other files can/should be excluded?


  4. Andrew Morgan
    June 2, 2009 at 7:42 am

    Hi Anthony, I’ve moved company to a Lotus Notes house and dont have full access to an exchange server anymore. If you wish I could install it at home and look into it further for you?

  5. December 6, 2012 at 11:59 pm

    Hi Andrew – I know this is an old post, but I’m also trying to backup Windows XP profiles (similar to post #1) and your document has been great at getting me started. One problem I’m having is the .bks file is created with my user profile and I need this to point to the logged on user’s profile. I edited the .BKS file and replaced C:\Documents and Settings\BillL with %userprofile%, but now NTBACKUP isn’t picking up the files to backup. I saved the BKS as UNICODE, and I also tried editing it in notepad++ unsuccessfully. Is there a way to do this?

    Thanks for any suggestions you might have.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: