Much of this four-part series on automating complex backups has focused on how you can interact with the Removable Storage Manager (RSM) via either a command prompt or a script. Part one provided a crash course on RSM. Part two explained how to create a script to leverage the power of RSM. Part three showed you how to take a GUID that you extracted from the RSM and put it into a format that The NTBACKUP command in Windows Server 2003...
can use. Here in part four, I will show what to do with that GUID now that it is in the proper format.
The trick to scripting backup operations is in realizing that NTBackup can be called from the command line and that there are a bunch of switches you can use with it. Since this series discusses the backup tape's GUID in so much detail, I might as well let the cat out of the bag and say that you can supply NTBACKUP with the tape's GUID by using the /G switch. The GUID itself must be surrounded by quotation marks and must be hyphenated in the manner discussed in part three. Furthermore, the /G switch cannot be used in conjunction with the /P switch, because if you use the /P switch, NTBackup will expect you to supply the name of a media pool.
Now let's look at the other switches that NTBACKUP will accept. (Keep in mind that not every switch listed here is required.)
- /J "job name": Tells NTBACKUP the name of the backup job.
- /T "tape name": Specifies the name of the tape that you want to use. But, as explained earlier in the series, if you are using a script, you will almost always want to use a GUID in place of a tape name.
- /N "tape name": Assigns a name to a new tape.
- /F "file name": Tells NTBACKUP to back up data to a file instead of to a tape.
- /D "description": Allows you to specify a backup description such as "full backup of server1 from 1-2-2006."
- /A: Causes the backup operation to append the new backup to any data previously existing on the tape.
- /v:yes: Tells NTBACKUP to verify the integrity of the backup.
- /R:yes: Tells NTBACKUP that the backup tape should be accessible only to its owner and to members of the Administrators group.
- /L:f,s or n: Tells NTBACKUP which logging level to use: (F)ull, (S)ummary or (N)one.
- /M backup type: Specifies the backup type. Valid parameters for the /M switch include Normal, Copy, Incremental, Differential and Daily.
- /RS:yes: Tells NTBACKUP that you want to back up the removable storage database.
- /hc:on: Enables your tape drive's hardware compression.
- /SNAP:on: Tells NTBACKUP to use Volume Shadow Copy should it need to backup an open file.
Note: If ON is listed as a parameter for a switch, you can achieve the opposite effect by specifying OFF instead. Likewise, if YES is used as a parameter for a switch, you can get the opposite effect by using NO.
Three other parameters to know about
There are three other parameters you need to know about: the Backup parameter, the BKS filename parameter and the SystemState parameter.
Specifying the Backup parameter after the NTBackup command places NTBackup in backup mode (as opposed to restore mode).
With the BKS filename parameter, prior to creating your script, you can open NTBackup and create a BKS file that says which files you want to include in the backup job. Suppose you wanted to back up the full contents of the C drive. You could open NTBACKUP, select the C drive and save the job as Backup.BKS. You could then call the job from within your script.
The SystemState parameter specifies that the computer's system state data should be backed up.
Now that I've gone through the syntax of the NTBACKUP command, let's discuss how you would use the command in a real-life situation. As mentioned earlier, most of the parameters described above are optional. Typical usage of the NTBACKUP command would look something like this: NTBACKUP backup @c:\files\backup.bks /g "GUID" /a /v:yes /hc:on /m normal
After the NTBACKUP command is issued, the first thing I do is use the Backup parameter to put NTBACKUP into backup mode. Next, I specify the location of the Backup.BKS file, which tells NTBACKUP which files to back up. The next thing in the command is the /G "GUID" switch. In real life, you would replace the word GUID with the actual GUID. But since we are deriving our GUID from a script, you'll need to keep reading. The remaining switches tell NTBACKUP to append the job to whatever is on the backup media, verify the backup once it is completed, use hardware compression and perform a normal backup.
The script from part three of this article produced a variable called BKUPGUID, which contains the GUID that will be used by NTBACKUP. To make NTBACKUP use this GUID, simply replace the word GUID in the example above with the BKUPGUID variable. It would look something like this: /G "%bkupguid%" You can now complete the script by appending the NTBACKUP command to the end of the script as shown here:
@echo off Set drvguid= d5696cdcaf9b45f9b74f078cb6854fdd FOR /F "usebackq delims==" %%x IN ('rsm view /tphysical_media /cg%drvguid% /guiddisplay /b') DO set tapeguid=%%x FOR /F "usebackq delims==" %%x IN ('rsm view /tpartition /cg%tapeguid% /guiddisplay /b') DO set partguid=%%x FOR /F "usebackq delims==" %%x IN ('rsm view /tlogical_media /cg%partguid% /guiddisplay /b') DO set logguid=%%x Set part1=%logguid:~0,8% Set part2=%logguid:~8,4% Set part3=%logguid:~12,4% Set part4=%logguid:~16,4% Set part5=%logguid:~20,12% Set bkupguid=%part1%-%part2%-%part3%-%part4%-%part5% NTBACKUP backup @c:\files\backup.bks /g "%bkupguid%" /a /v:yes /hc:on /m normal
About the author: Brien M. Posey, MCSE, is a Microsoft Most Valuable Professional for his work with Windows 2000 Server and IIS. He has served as CIO for a nationwide chain of hospitals and was once in charge of IT security for Fort Knox. He currently writes for SearchWinComputing.com, as well as other TechTarget sites.
Step-by-Step Guide: Automating Backups
Automating complex backups, part 1: Crash course on RSM
Automating backups, Part 2: Creating a script to leverage RSM
Automating backups, Part 3: Building on your script
Automating backups, Part 4: The trick to scripting