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

Customizing SetupVars.cmd. Open SetupVars.cmd, which Listing 2 shows, in Notepad or another text editor. In the code at callout A in Listing 2, you need to define at least the RSM_LIBRARY and RSM_REFRESH variables. If you plan to use TapePrep.cmd, you must also define the RSM_POOL variable.

RSM_LIBRARY defines the friendly name for your tape drive. If you're unsure of this name, you can open a command-shell window and run the command

RSMView library

to obtain the list of libraries on your system. Then simply copy the friendly name (but not the GUID) into SetupVars.cmd. You don't need to enclose the library's friendly name in quotes if it contains spaces. To check whether you have specified the library name correctly, type the following command at a command prompt

Library

You should see the library's friendly name followed by its GUID. You must make sure that the library's friendly name doesn't contain any of the following reserved shell characters:

( ) < > ^ & |

If your library's friendly name contains any of these characters, you need to remove them from the library's name. To do so, first open the Removable Storage console by selecting Start, Run, ntmsmgr.msc, OK. In the left pane, expand Libraries (in Windows 2003 and XP) or Physical Locations (in Win2K). Right-click the tape drive in the left pane and choose Properties. Remove any of the offending characters from the Name text box, and click OK.

You need to set RSM_REFRESH to the number of seconds that Refresh.cmd should pause after performing a device refresh. This value depends on your hardware; set it to the number of seconds it takes to insert and remove a tape. A good starting point is 30 seconds.

If you plan to use TapePrep.cmd, set RSM_POOL to the media pool that matches the type of media used by your tape drive. For example, if your tape drive uses Travan tapes, specify the Travan media pool:

Set RSM_POOL=Travan

If the value contains spaces (e.g., 4mm DDS), you don't need to enclose it in quotes.

The code at callout B in Listing 2 defines the post-backup behavior. Setting the EJECT variable to YES prompts Eject.cmd to eject the tape. Setting MAILLOG to YES causes MailLog.cmd to email the NTBackup log file to the specified recipient. Setting PRINTLOG to YES prompts PrintLog.cmd to print the NTBackup log file on the default printer.

If you set MAILLOG to YES, you need to set the variables in the code at callout C in Listing 2. (If you set MAILLOG to NO, you don't need to do anything with this code.) Set the SMTPSERVER variable to the DNS name or IP address of an SMTP server on your network. (In this example, no authentication is used. However, blat.exe supports SMTP authentication. For information about how to incorporate authentication, see the blat.exe documentation.) Set SENDER to the email address you want to appear in the message's From field. Set RECIPIENTS to the email address of the person you want to receive the message. You can specify more than one recipient. Simply separate the addresses with a comma; no spaces are allowed.

You don't need to do anything with the remaining code, which defines the DTSTAMP variable, ERR constants, and NTBACKUP_DATAPATH variable. Backup.cmd uses DTSTAMP to create a date and time stamp. The ERR constants define the exit codes for the scripts. And the NTBACKUP_DATAPATH variable points to NTBackup's data folder, which stores the backup selection (.bks) files and log files.

Customizing Backup.cmd. Open Backup.cmd in Notepad or another text editor. In the code at callout A in Listing 1, set the BACKUP variable to the directory or directories you want to back up. Separate directory names with spaces. If a directory contains spaces, enclose it in quotes. Alternatively, you can specify a .bks file. Enter the full pathname to the file, prefix it with the @ symbol, and enclose it in quotes if it contains spaces. 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"

Set the JOBNAME variable, which is used with NTBackup's /j option, to the backup job's name. This name will appear in NTBackup's Backup Reports window. Set SETDESC, which is used with NTBackup's /d option, to the backup job's description. This description will appear in the log file and in the Description column on the Restore tab in NTBackup's UI. The optional DTSTAMP variable that appears at the end of the description will let you see at a glance when the backup job ran.

You can customize the JOBINFO variable, but it's not required. This variable specifies the text used in error messages and in the email subject line. Note that it references the JOBNAME and COMPUTERNAME variables so you'll know at a glance the job and computer that generated the message.

You use the OPTIONS variable to define NTBackup's command-line options. For example, suppose you want NTBackup to append the backup to whatever tape happens to be inserted. You simply add the /a option to the OPTIONS variable. (You also need to remove /n "%MEDIANAME%" in the Set COMMAND= line because you can't use /n with /a.)

You can specify any of NTBackup's command-line options, except /j, /d, /n, /g, /f, /t, /p, and /um. As I mentioned previously, /j and /d are already defined in JOBNAME and SETDESC, respectively. The script automatically determines the tape's media label (/n) and GUID (/g). The other options (/f, /t, /p, and /um) shouldn't be used because they create conflicts.

The LOGFILE variable exists for troubleshooting purposes. Each script's output is redirected to this file, along with the tape's name and logical-media GUID, the NTBackup command line, and that command's exit code. If you leave the LOGFILE variable set to %~dpn0.log, the file will be created in the same directory as Backup.cmd and will have the filename Backup.log.

Ready, Test, Go
After you've completed these three steps, the backup scripts are ready to test in a nonproduction environment. Even though I tested them with Windows 2003, XP, and Win2K, you should always test any new scripts in a controlled lab environment before deploying them. After you've successfully tested them, you'll have a flexible backup solution to use.

Project Snapshot: How to
PROBLEM: How to use NTBackup to perform an automated backup that overwrites the current tape but doesn't change the tape's media label.
WHAT YOU NEED: The scripts in 44990.zip
DIFFICULTY: 4 out of 5
PROJECT STEPS:
  1. Understand the supporting scripts' functions.
  2. Understand how the main script works.
  3. Prepare the environment and scripts.



End of Article

   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