Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


February 2005

Want a Flexible Automated Backup Solution?

Overcome NTBackup’s shortcomings with these scripts
RSS
Subscribe to Windows IT Pro | See More Backup and Recovery Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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:

   Previous  1  [2]  3  Next 


Reader Comments
Looks great. Where's the hotlink?

HalJordan January 25, 2005 (Article Rating: )


Like he said. Good article, but where's the scripts? And what the *hell* is up with the BS advertisement links littering your articles?
"You can find the 14 scripts on the Windows IT Pro <link>Web site</link>" - That was really a shameless one!

MightyGorilla January 26, 2005 (Article Rating: )


Same thing, great article, but where is the hot link??????

haber2112 January 26, 2005 (Article Rating: )


Emailed the author, he said he notified the editor...

haber2112 January 26, 2005 (Article Rating: )


The scripts are there; just no link. I found them at http://windowsitpro.com/Files/44990/44990.zip by trial and error. They're nested 3 zipfiles deep, though.

Thrush January 26, 2005 (Article Rating: )


You can find the scripts if you go to the top of the article and click the 44990.zip hotlink under Download the Code. The scripts are in a .zip file that you need to download.

Anonymous User January 31, 2005


Thanks for your comments, and sorry the scripts weren't easier to find. In addition to the link at the top, I've liked the word 'scripts' within the article so other readers can find it more easily.

acarheden January 31, 2005 (Article Rating: )


This was a great article and I had no problem finding the scripts. Thank you.

rayman13 March 30, 2005 (Article Rating: )


everything seems to work great, except that, unless i manually start the Removable Storage mmc snap-in, the media is not detected. I tried setting the Removable Storage service to automatic startup, but it still turns itself off... anyone else have this problem?

acorn June 27, 2005 (Article Rating: )


I got my previous problem solved, still not sure how. I notice in the third page of this article, however, an error:

<snip>
You can use the NTBACKUP_DATAPATH variable as well. For example, if your filename is Weekly full.bks, you'd set the BACKUP variable to

"@%NTBACKUP_DATAPATH%\Weekly full.bks"
</snip>

However, in SetupVars.cmd, the variable is NTBACKUP_DATA, and not NTBACKUP_DATAPATH.

Just letting everyone know about this gotcha. I've worked around this several times, but just noticed today.

Awesome scripts, tho! I'm currently modifying them to backup to file, and still email/print logs.

acorn November 03, 2005 (Article Rating: )


 See More Comments  1   2 

You must log on before posting a comment.

If you don't have a username & password, please register now.




Learning Path If you want to find other useful command scripts, check out the Windows Scripting Solutions print newsletter:
"Windows Scripting Solutions"


If you want to learn how to write command scripts, check out:
"“Shell Scripting 101,” Web-exclusive series (Access all 10 articles in this series from this article.)"

"“Getting Started in NT Shell Scripting, Part 1”"

"“Getting Started in NT Shell Scripting, Part 2”"


If you want to run NTBackup from its GUI rather than a script but are having trouble, see:
"“NTBackup Won’t Work?”"


Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

How can I stop and start services from the command line?

...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events SQL Server 2008 – Can You Wait? | Philadelphia

Virtualization, Automation and Databases

SQL Server 2008 – Can You Wait? | Atlanta

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing