Refresh.cmd. Depending on your hardware, RSM isn't always able to detect when tapes are inserted and removed. Thus, before running a backup job, it's important to perform a refresh operation to ensure that the database contains the tape drive's actual state. Refresh.cmd refreshes the tape drive. If the refresh operation is successful, Refresh.cmd uses sleep.exe to pause the script so that the database will return up-to-date information.
Eject.cmd. Eject.cmd ejects the tape after the backup is complete. The script then calls Refresh.cmd to refresh the tape drive to ensure the Removable Storage service's database will return up-to-date information.
ShowLog.cmd. ShowLog.cmd outputs the most recent NTBackup log file (i.e., the log you'd see in the NTBackup GUI) to the screen. If you run ShowLog.cmd with the /f option, it will output the log's full path and filename instead.
PrintLog.cmd. PrintLog.cmd uses Notepad to print the most recent NTBackup log file. You need to configure a default printer before PrintLog.cmd will work. Summary logs (/L:s) are recommend if you use PrintLog.cmd.
MailLog.cmd. MailLog.cmd uses blat.exe to email the most recent NTBackup log file to the specified person (e.g., the administrator). Blat.exe is a free utility that lets you send mail messages from a command script.
SetupVars.cmd. SetupVars.cmd defines the settings of key environment variables used in the other scripts. This setup makes the scripts easily portable to different computers. You just need to modify the settings in one script (i.e., in SetupVars.cmd) rather than 13 scripts. (In Step 3, I discuss the settings you need to modify.)
TapePrep.cmd. When you have one or more new tapes you want to label and allocate to NTBackup, you can use TapePrep.cmd. This script runs NTBackup in unmanaged mode so that NTBackup can use whatever tape happens to be inserted. The script labels the tape with the text you specify.
You run TapePrep.cmd at the command line and not in a script such as Backup.cmd because you need to use the script only once per tape. The command to launch TapePrep.cmd is
TapePrep media_label
where media_label is the text you want to use as the label. If the text contains spaces, you must enclose it in quotes.
Step 2. Understand How the Main Script Works
As I mentioned previously, Backup.cmd runs a backup that overwrites the inserted tape, without changing the tape's media label. This script either directly or indirectly uses all the other scripts, except for TapePrep.cmd.
Listing 1 contains Backup.cmd. Callout A in Listing 1 shows the environment variables that direct its operation. To use this script, you need to customize these variables, which you'll do in Step 3.
After defining the variables, Backup.cmd uses Refresh.cmd to refresh the tape drive. The script then performs three important operations. First, Backup.cmd uses PhysicalMedia.cmd to see whether a tape is inserted in the tape drive. Then, Backup.cmd uses MediaName.cmd to determine the tape's media label. Finally, Backup.cmd uses MediaGUID.cmd to determine the tape's logical-media GUID.
If all three operations succeed, Backup.cmd defines the COMMAND variable, which contains the NTBackup command, as callout B in Listing 1 shows. The script records the NTBackup command in the script's log file named backup.log, then executes the command. After NTBackup completes the backup, Backup.cmd writes NTBackup's exit code to backup.log. Finally, Backup.cmd checks the EJECT, MAILLOG, and PRINTLOG variables, as the code at callout C in Listing 1 shows. If any of these variables are set to YES, Backup.cmd calls the appropriate scripts.
If any of the three operations fail (i.e., the script can't detect the tape's physical-media GUID, media label, or logical-media GUID), Backup.cmd calls the :DIE subroutine, which callout D in Listing 1 shows. This code displays an error message, creates the error.log file in the NTBackup data directory, and writes the same error message to error.log and backup.log. Depending on the values set for the MAILLOG and PRINTLOG variables, the code might also email and/or print the most recent NTBackup log file, which contains the error message.
Step 3. Prepare the Environment and Scripts
You can find the 14 scripts on the Windows IT Pro Web site. Go to http://www.windowsitpro.com, enter InstantDoc ID 44990 in the InstantDoc ID text box, then click the 44990.zip hotlink. After you create a directory to hold the scripts (e.g., C:\NTBackup), extract them into that directory. When you schedule a job that uses the scripts, make sure you specify this directory as the Start in directory for the scheduled task.
The 44990.zip file includes the sleep.zip file, which contains sleep.exe. Unzip this file and extract its contents into the directory you just created. If you want to email the most recent NTBackup log file to your administrator after the backup is complete, you need to obtain blat.exe. You can download blat.exe from http://www.blat.net. This utility requires no installation, registry entries, or support files. Just place it in the same directory as the scripts.
After the scripts and utilities are in place, you need to customize SetupVars.cmd and Backup.cmd:
HalJordan January 25, 2005 (Article Rating: