Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


Return to article

Scheduling Command-Line Win2K Backups
 

The arrival of a new Windows 2000 server outfitted with Quantum's DLT 7000 tape drive convinced me that it was time to retire the old Windows NT 4.0 server that I'd been using to do tape backups. So, I needed to rescript my backups for Win2K. I didn't expect Win2K's NTBackup to be much different from NT's, but I discovered they are quite different.

My backup approach is simple: Every Monday, I put a tape in the drive. That night, I run at.exe and use the Schedule service to erase the tape and do a full backup. Every subsequent night of the week, I schedule a differential backup. I rotate several tapes and keep a recent backup offsite. Although my approach isn't enterprise-level, it works—and it requires that I write only two batch files: one for the complete backup and one for the differential backup.

The bare minimum syntax for a command-line backup is

ntbackup backup <directory> <tapetype>

where directory is the name of the directory you want to back up (I explain the tapetype value later). Win2K lets you specify the name of a backup selection (.bks) file, which contains a list of directories and files to back up. To indicate that the file is a .bks file, you prefix the file's name with the at (@) character. To make a .bks file, open Notepad and list the directories or files that you want to back up, one to a line. You can add the line

systemstate

to back up the registry and—if the server is a domain controller (DC)—Active Directory (AD). To skip a file or directory, add a line that specifies the name of the file or directory that you want to skip, followed by the /exclude parameter. If I want to back up C:\stuff, C:\mystuff, and the registry but not the C:\mystuff\pst directory, I'd type

c:\stuffc:\mystuffc:\mystuff\pst\ /exclude
systemstate

Next, I'd save the file—I'll call mine C:\files.bks. The only catch is that when I save the file in Notepad, I need to choose Unicode encoding (from the Encoding drop-down list box in the Save As dialog box) instead of the default ASCII encoding. After saving the .bks file, I put it into action by starting NTBackup:

ntbackup backup @c:\files.bks <tapetype>

NTBackup has many other options. I usually add the following options to my differential backup:

/v:yes /hc:on /a /m differential /l:f

The /v:yes option tells NTBackup to verify the backup. The /hc:on option activates hardware compression on tapes that support it. The /a option appends the backup to the tape without erasing existing data—if you don't use the /a option, your backup will overwrite other backups on the tape. The /m differential option tells NTBackup to copy files whose archive bits are set but not to clear those bits. Alternative values for this option are normal, which specifies a full backup and is the default; incremental, which is similar to differential but clears the archive bits; daily, which copies only files that have changed that day (and doesn't clear the archive bits); and copy, which is like a full backup but doesn't reset the archive bits. The /l:f option creates an extensive (i.e., complete) log file. Alternatively, you can opt for /l:s (summary log—the default) or /l:n (no log).

Speaking of log files, another oddity about Win2K's NTBackup program is its hidden log files. You'd expect the log files to be easy to find, but Microsoft has put them in a hidden folder inside a hidden folder inside a hidden folder. Whenever you create a backup, NTBackup creates a log file named backupnn.log, where nn can range from 01 to 10. NTBackup keeps only the last 10 logs, rotating the numbers and overwriting older logs as necessary. You can view the logs by starting the Backup GUI application and choosing Tools/Reports, or you can find the files in Documents and Settings\username\LocalSettings\ApplicationData\Microsoft\Windows NT\Ntbackup\Data (where username is the username of the person who initiated the backup). However, if you use at.exe to schedule the backup, the logs go into Documents and Settings\Default User\Local Settings\Application Data\Microsoft\Windows NT\Ntbackup\Data.

Finally, specify the tape drive to use for the backup. Although you usually have only one tape drive, you still need to specify it. Unlike NT's NTBackup, Win2K's utility delegates control of the tape drive to a subsystem, called the Remote Storage Manager (RSM). And RSM's way of managing tape drives has a side effect: You use different syntax to tell NTBackup to overwrite data on the tape than you use to append a backup. To tell NTBackup to overwrite data, you use

ntbackup backup @c:\files.bks
  /v:yes /hc:on /m differential
  /l:f /p "<tapetype>" /um

where the /p switch specifies that you want to use media from the media pool, and tapetype is a tape-drive description (e.g., DLT, 4 millimeter—mm—DDS). The /um switch tells NTBackup to find the first available media of the specified type, format it, and use it for the backup.



To determine what type your tape is, first—if you've never done so on your system before—start Backup (click Start, Programs, Accessories, System Tools, Backup), then close it. Next, right-click My Computer, select Manage, and navigate to Storage\Removable Storage\Media Pools\Backup. You should see one or more folders, and one of those folders' names is your tape type. My system, for example, has a folder named DLT under Backup. If you see no folder under Backup, RSM doesn't have a driver for your tape drive.

Thus, if I have a 4mm DAT tape whose type shows up as 4mm DDS, I would use the following command to tell NTBackup to wipe whatever is on the tape and do a full backup of my files:

ntbackup backup @c:\files.bks
  /v:yes /hc:on /m normal /l:f
  /p "4mm DDS" /um

I'd put that command in my batch file and tell at.exe to run that batch file every Monday morning.

Next, I want to tell the system to do daily differential backups to the same tape the rest of the week. To append backups, you use the /g option instead of the /p "tapetype" /um syntax:

ntbackup backup @c:\files.bks
  /v:yes /hc:on /a /m differential
  /l:f /g "<guid>"

where guid is the tape drive's globally unique identifier (GUID). Win2K is rife with GUIDs. Each removable storage device gets a GUID, and every tape that you format on a Win2K system gets a "physical media" GUID. Like hard disks, each tape has partitions—typically one per tape—and every partition gets a partition GUID. Within that partition is one "logical media," which gets a logical media GUID. NTBackup needs that logical media GUID.

Acquiring that GUID is the stumbling block in the otherwise simple process of building the batch file. To fetch GUIDs, you use the Rsm View command:

rsm view /t<object-type>
  [/guiddisplay] [/cg<guid>]

Choices for object-type include library (to list your drives), physical_media (to show the tapes in a drive), partition (to get the tape's partition) and logical_media (to show the tape's logical media). The /guiddisplay parameter lists objects and their GUIDs. The /cg parameter lets you specify what object you want to examine; guid is the object's GUID. To find the GUID of your tape drive, type

rsm view /tlibrary /guiddisplay

RSM will probably list several drives. The 32-character string to the right of your tape drive's name is the drive's GUID.

Then, create the diff.cmd batch file that Listing 1 shows. Locate the line that corresponds to callout A in Listing 1 and replace the string that follows the equal sign (=) with your drive's GUID. This GUID will never change. (Logical media GUIDs change every time you erase the tape, but diff.cmd handles those changes.)

Ugly as it is, diff.cmd is fairly simple. It uses the drive's GUID to ask RSM for the GUID of the tape that's in the drive, uses the tape's GUID to find the tape partition's GUID, then uses that GUID to get the logical media's GUID. Diff.cmd reformats the GUID to the format that NTBackup requires by adding hyphens in certain places in the GUID string (e.g., E30ADF03-E801-4BA4-BB82-4AD69B39FBE7).

Before I finish, let me pass along three Win2K NTBackup anomalies. First, typical backups have a bug that causes them to fail to reset archive bits on random files. (Let's hope for a Service Pack 3—SP3—fix.) Second, NTBackup won't back up to CD-R discs, CD-RWs, DVD-RWs, or similar drives. And third, you can use the command line only to back up; to restore, you must use the GUI.







Reader Comments

Excellent article. I wish I'd seen it before. I've never been able to correctly schedule a backup since my migration to Win2K (of course, previous batch files didn't work anymore) Thanks

Raymond Warichet -August 22, 2002

I know this is oriented toward W2K, but does it apply to WXP as well, or have things changed yet again?

Tom Stewart -August 27, 2002

This was useful, but doesn't address the issue of ejecting tapes for operators, this is explained at http://www.jsiinc.com/SUBE/tip2200/rh2265.htm Also RSM is the 'Removable' Storage Manager.

Nick Swinney -August 28, 2002

It would have been helpful to talk about the /UM switch. It stops prompts for user input. Essential to automating backups.

ryan ware -October 01, 2002

Excellent! I've trying for two weeks to figure this thing out. One of the stumbling blocks appears to be a mis-print in the SBS Help file. It says the RSM View switch is "/guid_display" instead of the "/guiddisplay" that Mark has demonstrated...I could never get the thing to work. Mark's explanation is perfect!

Gavin Rumble -January 11, 2003

Wonderfull !!!! I can´t even imagine the work you had to discover all this !! It works very well !!

Nuno Sobral -January 21, 2003

How about to create Emergency disk? Can we schedule it?

Cora Li -March 02, 2003

This article contains an example that doesn't work. The option to exclude files or directories is /Exclude, not /exclude. Lowercase is rejected by ntbackup.

Peter Shute -April 06, 2003

Good article clear and concise - easy to work with, unlike MS Windows Help Topics!

Eddie Martin -November 06, 2003

Pretty smart I must say. Found this very useful. Thanx.

Sugeesh Ariyaratna -November 06, 2003

Finally some info on what contains what. The help files on Windows are very poor. I think this solved my problem.

steve -December 11, 2003

Thanks - extremely helpful - goes way beyond standard MS documentation. Great job!

Jeff Murphy -January 09, 2004

Thanks very much for this post - i have been trying for two days to do something very similar to what you sre doing and I think you have solved my problems.

mistert -January 15, 2004

I'm trying to run the diff.cmd script mentioned in this article on a Win2k Pro system with a Travan drive in it, and the 'cmd' environment doesn't know how to handle those "BEGIN CALLOUT" "END CALLOUT" and some of the syntax in the other lines. What might be missing from my environment? I've tried running the script as .vbs and .wsh files, but that didn't help.

Dave -January 20, 2004

The description above is ok for W2000, but in W2003 i am not able to find the parameter /um. What are the Differences between NTBackup W2000 versus W2003

Eusterholz -January 27, 2004

The article "Scheduling Command-Line Win2K Backups " by Mark Minasi really helped me a lot. Thank you so much.

Mitch -February 11, 2004

This article was the light at the end of the tunnel. Thank you very much. Now, at 4:40am, after hours and hours of fighting with ntbackup & RSM, i can go to bed. Thanks again.

Alvaro Ojopi -February 28, 2004

This is the most helpful article on the whole tape backup issues with win2k I have come across - and I have been searching for two days for an answer! Trouble is, even with the diff.cmd and all that Mark Minasi suggests, I still get the error "The operation was not performed because no unused media was available.". What am I missing?

Jonathen Winterburn -April 19, 2004

Great article. Immense help in trying to get Server 2003 to back up to a single Sony DAT24 drive (referred to in the RSM docs as a 'Standalone Library'!) - the /um switch is undocumented in 2003 but still works. I guess if /UM is finally withdrawn I'll have to use the excellently researched example GUID calls given by Mark in diff.cmd - let's hope Microsoft doesn't do it on an automated update and unexpectedly break the backups!

Chris Burr -April 20, 2004

how can i backup my database from d:\database folder to my tape drive (4mm DDS) using batch file.? can you give some tips.? thank you...

fernan velasco -April 20, 2004

Help me with a command to eject the backup tape in win2k server. Using scheduler task able to do the backup ok. Thanks, Path.

Path -May 13, 2004

This is an outstanding article that goes a long way towards using ntbackup a great deal simpler. However, I am also suffering from the error "The operation was not performed because no unused media was available." As noted above by Jonathen Winterburn. Upon further searching though, I found the following article (I apologise for referencing a different Web site here) which seems to be a perfect addendum to Mark Minasi's guide here - at least for that particular error message: http://www.helpforums.co.uk/forum/viewtopic.php?t=6576 Jonathen and others, I hope this helps you out, but please note, none of that content is my work, and I have not personally conducted those steps myself as yet. I just think it is worth drawing attention to.

Gavin Landless -May 20, 2004

Great article. I didn't know why Ntbackup didn't work twice. Just because /um option not exist when you use ntbasckup interface. Thk a lot. Do you know how eject media when finish ?

Ludovic -June 15, 2004

exlnt

Anonymous User -October 12, 2004

A very clear help file, much better than Windows help file. Thaaaaaanks

Anonymous User -October 18, 2004

See a couple of comments about ejecting the tape. I don't want to write a whole article here, but some quick tips that should get you going: Ejecting the tape requires that you script a RSM command in your batch file. Specifically: rsm eject /pf "name of you bacup tape" /astart Watch out for these issues: 1> You must know the name of the tape that you are creating, since rsm eject will not simply eject the tape in the drive even on a single tape system (big change from NT4!). What this means is that you must specifically name your tape with the /n switch on your backup job. I capture the date to a variable (which I call now) so that I can have unique tape names. Why not just use %date% instead of creating a new variable? That is because %date% may not be the same when you start the job as when you finish it. 2> The second thing to watch out for is that rsm will append " - 1", " - 2", etc. at the end of the tape name if you have duplicates names. It also appears that rsm will add these on if you run multiple (appended) jobs to the same tape. Hope this helps!

Anonymous User -October 30, 2004

The batche file is OK but I'm heving problems runnig that batche file on scheduled bases, when I try to run it by my self it runs without any problem but scheduled it dosent start????

Anonymous User -November 21, 2004

Concise and well written. Why can't the technical writers at Microsoft ,who are partners with the creators of the software discussed above, do as good a job of explaining the syntax and creating useful examples?

Anonymous User -March 01, 2005

As always, Mark Minasi rules!

Anonymous User -March 28, 2005
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement