.Net ramblings
# Tuesday, 14 September 2004
A sample NTbackup script, with the current date/time in the filename and backup label

This script is based on the FAQ on http://www.jsiinc.com/SUBE/tip2200/rh2265.htm.

If you ever tried to automate NTbackup, you probably got it up and running, scheduled every day or week, but then noticed over time that the date and time labels that go on the backup file are the current date/time of when you created the backup set.  This useful shell script provides a more intelligent solution by parsing the current date and time and inserting them into the filename and backup label.  This makes the backups much easier to identify in the case where you need to restore some files.

The script below makes a full backup (not differential) of the files specified in the backup set.bks. It doesn't verify the backup, and lastly it sends a copy of the backup file to another computer (just in case), that's what the last 3 lines are for.  You can obviously remove this step if you don't want it.

If you don't fully understand all the parameters of the NTbackup.exe... command, it's explained well here.

Save the following text as a .cmd file and add it is a scheduled task in Windows.

@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  @set dt=%%i-%%j-%%k-%%l
@for /f "Tokens=1" %%i in ('time /t') do @set tm=-%%i
@set tm=%tm::=-%
@set dtt=%dt%%tm%
@echo Copying backup set: %dtt%.
@echo Please wait...
@C:\WINDOWS\system32\ntbackup.exe backup "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\backup set.bks" /a /d "Backup %dtt%" /v:no /r:no /rs:no /hc:off /m normal /j "%dtt%" /l:s /f "G:\Auto Backups\Backup %dtt%.bkf"

@echo Sending backup file to Server2. Please wait...
@xcopy "@G:\Auto Backups\Backup %dtt%.bkf" "@\\Server2\Backup_Copy" /Y
@echo Finished.

Tuesday, 14 September 2004 11:18:09 (GMT Daylight Time, UTC+01:00)  #    Comments [17]  Windows Server

Friday, 07 July 2006 21:42:23 (GMT Daylight Time, UTC+01:00)
This script won't work with Server 2003. You need to prepend the .bks path with an @ sign.


@C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\Ad...
Thursday, 09 August 2007 03:52:34 (GMT Daylight Time, UTC+01:00)
Nice and simple.. well put.

I also posted one:
Thursday, 09 August 2007 03:52:54 (GMT Daylight Time, UTC+01:00)
Nice and simple! I posted a more advanced one myself.
Tuesday, 02 October 2007 09:09:54 (GMT Daylight Time, UTC+01:00)
Thanks, Tim. It's a great script .
Tuesday, 01 April 2008 01:35:47 (GMT Daylight Time, UTC+01:00)
Thanks Is there way to disable pop-up of dialog box during execution of this script. I wish we have /dev/null in windows!
Sakharam G
Tuesday, 01 April 2008 08:09:20 (GMT Daylight Time, UTC+01:00)
hi sakharam. i don't know, try ntbackup.exe /?
Tuesday, 01 April 2008 09:04:16 (GMT Daylight Time, UTC+01:00)
hi sakharam. i doubt it but try ntbackup.exe /? or the newsgroups.
Good luck
Tuesday, 09 September 2008 05:00:38 (GMT Daylight Time, UTC+01:00)
I have written a little Visual FoxPro program to help the scripting process. Check it out and see if it works for you.

Tuesday, 28 October 2008 13:39:42 (GMT Standard Time, UTC+00:00)
hi there i used tha code on the top of the page change it little bit and it works perfect on winxp then i move it to serverwin2003 and it just not working at all i am kind of lost and truly i have no ide about coding at all just put oieces together can someone advice me what is wrong with this "my script"

the code:

@for /f "Tokens=1-4 Delims=. " %%i in ('date /t') do set yymmdd=%%l%%k%%j
@echo Copying backup set: %yymmdd%.
@time /t >> D:\backup\log.txt
@echo Please wait...
@C:\WINDOWS\system32\ntbackup.exe backup "@C:\Documents and Settings\USERNAME\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\backup.bks" /a /d "backup %dt%" /v:no /r:no /rs:no /hc:off /m normal /j "%dt%" /l:s /f "D:\backup\%computername%_C_%yymmdd%.bkf"
@echo Sending backup file to Server2. Please wait...
@xcopy "@D:\backup\%computername%_Css_%yymmdd%.bkf" "@\\serverhostname\Backup\backupfolder" /Y
Tuesday, 28 October 2008 13:40:51 (GMT Standard Time, UTC+00:00)
hi pete, the code works fine (as posted) on server 2003, if you broke it you broke it!!! the newsgroups might help you. good luck.
tim mackey
Sunday, 16 November 2008 07:10:00 (GMT Standard Time, UTC+00:00)
i have a script that i use for multiple servers and could be of use to others: its all cmd based, and uses ntbackup so completely free. i have it running on about 90 servers for various clients and all their output comes back to me, and is automatically processed into sharepoint on my own sbs server.

id welcome comment if anyone uses it or wants more information


general overview of script abilities:
variables based operations from control file
email logs to centralised support email, and multiple additional email if required
stop and restart services specified befor backup
stop and restart services specified for duration of backup
support for tape and disk backups
automatic archiving of disk backups for specified itterations
refresh rsm library for tape problems fix, vss errors fix, and tape log history fix to 100
display directory listing to check file dates into backup log (to check output of dirctory eg sql bkup files)
output log file formatted to include source server, client information, date, times, and ntbackup output.
automatic updates!!!! ftp based updates to centralised server for new editions and backup services in files.
tape ejection
Tuesday, 25 November 2008 10:29:59 (GMT Standard Time, UTC+00:00)
Can any send me a script according to my requirement:

Data to be backed up : D:/Archives

Data backup on ; E:/Backup/


Monday, 06 July 2009 23:56:41 (GMT Daylight Time, UTC+01:00)
Will this script work for a 4mm dat drive?

Paul Aeschliman
Thursday, 13 August 2009 14:44:00 (GMT Daylight Time, UTC+01:00)
This script works well for a 4mm Dat drive and makes it eject when done so you know the backup completed. Use it if you need it.

@echo off

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j-%%k-%%l
for /f "Tokens=1" %%i in ('time /t') do set tm=-%%i
set tm=%tm::=-%
set dtt=%dt%%tm%
c:\winnt\system32\ntbackup.exe backup "@c:\backup\backup.bks" /n "%computername%-%dtt%" /d "full %dtt%" /v:no /r:no /rs:no /hc:on /m normal /j "full %dtt%" /l:f /p "4mm DDS" /UM
rsm.exe eject /PF"%computername%-%dtt% - 1" /astart

Paul Aeschliman
Thursday, 14 January 2010 09:33:35 (GMT Standard Time, UTC+00:00)
Thanks!!!That's great...
Friday, 08 October 2010 17:10:25 (GMT Daylight Time, UTC+01:00)
Thanks dude it is very useful script.
Friday, 05 August 2011 09:44:25 (GMT Daylight Time, UTC+01:00)
This is really help ful, thanks for sharing
Please login with either your OpenID above, or your details below.
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview