By Dominic Bosco

TechRepublic first published this information as a download. In response to positive reader feedback, we’re making the article available here. The document is still available as a download, as well.


Table of Contents
No native brick-level backup capability
The script’s features and requirements
Configuring the Exmerge Initialization File

No native brick-level backup capability
The script’s features and requirements
Configuring the Exmerge Initialization File

Every Exchange organization has its Very Important Mailboxes (VIMs). If you’re like most Exchange administrators, you have a select group of users who have made it perfectly clear that they just can’t do without their mailbox’s content for any longer than necessary, regardless of whether they deleted the data themselves or whether their server crashed. Wouldn’t you sleep easier at night knowing you have a plan and method ready to restore these critical mailboxes at a moment’s notice?

In this article, we’ll discuss select mailbox, or “brick-level,” backups of Exchange Server Information Stores. Then, we’ll show you how to use an NT Shell Script that uses Exchange Administrator and an updated Microsoft Back Office Resource Kit tool to perform an online backup of a select group of mailboxes and archive the data in .PST files on disk. You can then use NTBackup or any other file-level backup utility to back up these .PST files to tape or other media.

Did you miss the previous articles on NT Command Shell scripting?
If you are not familiar with NT Command Shell scripting, see my series of four articles on the subject.

This article presents advanced scripting techniques and assumes that you are familiar with Exchange Administrator’s command-line export option, use of command-line tools, and a text editor.

No native brick-level backup capability
Unfortunately, neither Exchange Server 5.5 nor the Exchange-aware version of NTBackup allows you to back up (or restore) a single or select number of mailboxes. So how do you perform a brick-level backup or restore of an Exchange Server? Well, unless you use a costly 3rd-party Exchange-Aware Backup application or our free script, you’ll have to do it the old-fashioned way.

If you use NTBackup, you’ll first have to perform an online or offline backup to archive your entire Information Store to tape. As you probably know, NTBackup doesn’t allow you to back up data disk or other media. Then, when it comes time to restore data from even a single mailbox, you’ll need to restore the entire Information Store database from tape, a tedious task.

Imagine this brick-level restore scenario where you use NTBackup to back up and restore your Exchange Servers. Suppose a VIP user asks you to restore messages that he permanently deleted from his VIM four days ago. Your Information Store’s Deleted Items Retention period is three days, but your tape back retention period is seven days. So, off you go to the tape vault to fetch the last good backup (which is more than four days old) of the IS database containing the mailbox. You must restore this database to a recovery server that’s separated from your Exchange organization.

After completing the tape restore and starting the Information Store (which may take a long time if you have several days’ worth of incremental log files to play against the IS), you must run the DS/IS Consistency Adjuster. Then, you must start the Directory Service, create a MAPI profile, and use it to log on to the mailbox and export the data to a .PST file. Finally, you must import the data from the .PST file to the production server that hosts the user’s mailbox.

As you can see, this process will consume a lot of your time and resources and keep your user waiting all the while. In fact, my experience has shown me that restoring 11-16GB Information Stores in this manner from 4mm DAT cartridges can take 24 hours or longer.

Why create your own brick-level solution?
There are 3rd-party backup applications that come with software agents that let you perform online brick-level backups of an Exchange Information Store. However, I’ve tested these applications and found that they are not only costly, they also have some serious shortcomings. For example, some of the tools won’t allow you to restore attachments stored within a message and others do not reliably restore the mailbox data.

Because I could not find a 3rd-party brick-level backup utility that met my department’s needs or budget, I decided to create my own tool in the form of an NT Shell Script that would use Exchange Administrator and the Exmerge utility from the BORK to back up individual mailboxes. Both of these tools should be readily available to any Exchange Administrator, so implementing this script should require little or no investment.

I saw a great advantage in a process that would archive data to disk rather than tape. Once the data was staged to disk, I could use another process (perhaps a nightly backup of shared directories) to back up the staged data to tape, thereby creating a simple but effective Hierarchical Storage Management system.

The “Swiss Army Knife” of Exchange tools
Exmerge’s primary purpose is to move Exchange Mailboxes between sites, servers, and organizations. It provides a programmatic method to perform tasks that would otherwise be very complicated or take a lot of time to do manually. However, the program has many other features and capabilities, and every Exchange administrator would do well to become familiar with them.

The BORK 2 included an early version of Exmerge (EXMERGE.EXE). But you’ll need to obtain Exmerge version 3.65 before implementing the script I present here. Download the file ExMerge3_65Intel_zip_991004.09-42-16 from Microsoft.
Please thoroughly read the documentation that comes with Exmerge. Unintentional misuse of this tool can have disastrous consequences.
Like many command-line tools you can run as batch processes, Exmerge uses an initialization file, EXMERGE.INI. The download version of this article includes a sample of this file that you will need to customize before your run EXBRICKBK.CMD.

The script’s features and requirements
For the purpose of demonstration, I’ve kept the script as simple as possible. It has two main features. First, the script allows you to easily maintain a list of mailboxes that you need to include in the brick-level backup by simply adding them to a Distribution List of your choice. Second, the script runs Exmerge in batch mode and archives the mailboxes to .PST files in a directory you’ve chosen.

Please note that the script doesn’t have reporting or tape archival features, though you can easily add them if you want. The script requires the following support files to be present in the same directory or in the path:

  • BRICKBKUP.TPL—Shown in Listing A and included in the download version of this article. This is a plain text template file that BRICKBKUP.CMD will use to create the Exchange Administrator export file, BRICKBKUP.CSV.
  • BRICKBKUP.OPT—Shown in Listing B and included in the download version of this article. This is the options file that Exchange Administrator uses when exporting the membership of the distribution list.




Stepping through the script’s code
First, we’ll give you the pseudo-code for the script and then explain how to configure the script’s path variables and its support files. The following list steps through the pseudo-code for the BRICKBKUP.CMD script:

  1. Sets script variables that define the proper paths for the script’s runtime environment.
  2. Changes to the script’s directory.
  3. Deletes the old directory export file.
  4. Copies the directory export template to create the new directory export file.
  5. Runs Exchange Administrator against the designated Directory Server and options file BRICKBKUP.CSV and captures the output to the directory export file, BRICKBKUP.CSV.
  6. Parses the BRICKBKUP.CSV and calls a procedure that captures the Distinguished Names of mailboxes that need to be backed up in Exmerge mailbox name file (mailboxes.txt).
  7. Runs EXMERGE.EXE against the mailboxes.txt file (specified in EXMERGE.INI) and creates or merges data into each mailbox’s .PST file in the Exmergedata directory.

Setting the script’s environment variables
Before using EXBRICKBKUP.CMD, you will need to change three statements that set environment variables at the beginning of the batch file.

  • SET EXMERGE_PATH=<drive letter:\path\directory>—Set this variable to the drive letter and complete path to the directory where you’re executing Exmerge.
  • SET ExportSrv=<servername>—Set this variable to the computer name of an Exchange Server in your Organization.
  • SET EXMERGEDATAPATH=<drive letter:\path\directory>—Set this variable to the drive letter and complete path to the directory where you want Exmerge to create the .PST files.

Configuring the Exchange Administrator Export Option file
The BRICKBK.OPT file contains parameters that Exchange Administrator will use to export the membership of the EXBRICKBKMailboxes Distribution List. Set the parameters’ values as follows:

  • DirectoryService—Change the value of this parameter to the computer name of the server you want to run the Directory Export against.
  • Basepoint—Change the value of this parameter to the Distinguished Name for the BRICKBKMailboxes Distribution List. Insert the Organization Name (<orgname>), Site Name (<sitename>), Container Name, (<containername>), and Canonical Name (or alias—in this case, BRICKBKMailboxes) where appropriate.
  • ExportObject—Leave this value as DL, which indicates that you want to export a Distribution List object.
  • BasepointOnly—Leave this value as Yes, which instructs Exchange Administrator to only export the data for the Basepoint that you’ve specified.
  • MVSeparator—Leave this value as 010, which is the ASCII value for the Line Feed character. Doing so will change Exchange Administrator’s multi-value output from comma separated to line feed separated. This allows the script to use the FOR command to parse the file.

Configuring the Exmerge Initialization File
To make Exmerge function within the EXBRICKBKUP.CMD script, you’ll want to change the default values of certain parameters in the EXMERGE.INI initialization files. Open EXMERGE.INI in a standard text editor and change the following parameters:

  • SourceServerName—Change the value for this option to the computer name for an Exchange Server in your Organization.
  • LogFileName—Change the value for this option to the complete path and filename of the file you want to use to log Exmerge’s activity.
  • LoggingLevel—Change the value for this option to choose Exmerge’s Logging Level. 1 is the lowest and 3 is the highest.
  • DataDirectoryName—Change the value for this option to the directory where you want Exmerge to create the .PST files for the selected mailboxes.
  • FileContainingListOfMailboxes—Change the value for this option to the complete path and filename for the file that contains the distinguished names Mailboxes.txt file.

Implementing the script
I recommend that you schedule the EXBRICKBKUP.CMD script to run at least once daily. When you schedule the script using the AT.EXE scheduler, be sure that you’ve configured the Schedule Service to run under an account that has the Admin permissions to the mailboxes that you want to back up. Configuring the Schedule Service to run under the Exchange Service Account is probably your best bet.

If you’re planning on using the script to back up mailboxes in multiple sites that use different Exchange Service Accounts (or that exists in a domain that doesn’t trust your domain), you’ll need to schedule other instances of EXBRICKBKUP.CMD using a schedule service with the required security credentials to access the mailboxes in other sites.

Restoring mailbox data
When it comes time to restore mail from a mailbox’s .PST file, you’ll have several options. You can run Exmerge in normal (as opposed to batch) mode and use its graphical user interface to select the .PST data by a range of dates or other criteria and restore them directly to any production mailbox.

Or you can copy the .PST file to the user’s local disk or make it available on a network share. Then, instruct the user to add Personal Folders to their Outlook Profile and add the .PST file when they do so. The user can then browse through the .PST file’s contents and retrieve the messages they are looking for.

Managing the archived data
Exmerge does not password-protect the .PST files it creates. Therefore, you’ll want to be sure that Exmerge creates the .PST files on a secure file system, such as NTFS, and that you’ve configured the directory’s share (if any) and user level permissions correctly.

Additionally, you’ll need to consider how much space is required to store the .PST files and with what frequency you will have to purge the archived .PST files. If there is no corresponding .PST file for the mailbox in the EXMERGEDATA, Exmerge will create a new .PST file for the mailbox by exporting all the mailbox’s contents to a newly created .PST file. The .PST file naming convention is <alias>.PST.

If a .PST file for the mailbox already exists in the EXMERGEDATA directory, EXMERGE.EXE will export only new message data from the mailbox to the .PST file. Exmerge cannot synchronize the .PST file with the mailbox, it can only add new data to the .PST file—which means that the .PST files in the EXMERGEDATA directory can only grow once they’ve been created. Therefore, you may need to add functionality to EXBKBRICKBKUP.CMD that purges .PST files of a certain age or moves them to another directory so that Exmerge will create new, smaller .PST files when it runs next.

When Exmerge exports mailbox data to a .PST file, you lose the benefit of Microsoft Exchange Server’s Single-Instance message storage capability. So don’t be surprised if a mailbox’s newly created .PST file is 10 to 50 percent larger than the mailbox itself. To check an individual mailbox’s size, open Exchange Administrator, select the Server that hosts the mailbox, and then open Private Information Store|Mailbox Properties and locate the mailbox from the list of the server’s mailboxes.
If you’d like to share your opinion, start a discussion below or send the editor an e-mail.