Replicate the IIS6 Metabase Between Nodes

I know that this is a little off-topic, but here goes…. A colleague asked me to have a look at replicating the IIS6 Metabase between two load-balanced web servers that form the front-end of a larger BizTalk environment. After my protests of ‘but I’m a BizTalk guy’ fell on deaf ears and I started to investigate the problem, I was pleasantly surprised with the functionality provided ‘out of the box’ by IIS; of particular interest to the replication problem were following two VBS scripts:

  • IIsCnfg.vbs -Performs Metabase replicated between IIS6 nodes or exported/imported to file.
  • IIsBackup.vbs – Performs Metabase backups/restores and provides the facility to list and delete existing backups.

So how do we go about using these scripts? They exist in the C:WINDOWSSystem32 directory and are all well documented (just execute the script with the help switch (/?) and the list of possible options are presented.

Backing Up the IIS Metabase

To perform a daily (scheduled) backup of the metabase on the local machine, I would suggest running something along the following lines:

C:WINDOWSSystem32iisback.vbs /backup /b DailyBackup

If you wanted to backup the Metabase on a remote machine, simply add the /s (server) switch: this indicates the remote server on which to run the backup (note in the previous example, where no /s switch is supplied, the script defaults to the local server):

C:WINDOWSSystem32iisback.vbs /s winbtiis02 /backup /b DailyBackup

If we wanted to review the backup history, we can list the backups on a local (or remote) server, using the /list switch, as follows:

C:WINDOWSSystem32iisback.vbs /list

which produces the following output (note the last backup in the list – The IIS Setup automatically creates a backup at the end of its run):

Connecting to server ...Done.
Backup Name Version # Date/Time
========================================================================
DailyBackup 0 14/08/2007 17:08:49
DailyBackup 1 14/08/2007 17:08:58
DailyBackup 2 16/08/2007 11:04:38
DailyBackup 3 16/08/2007 11:04:41
DailyBackup 4 16/08/2007 11:04:43
DailyBackup 5 16/08/2007 11:04:44
DailyBackup 6 16/08/2007 11:04:46
DailyBackup 7 16/08/2007 11:04:47
Initial Backup - created automatically by IIS setup 1 15/07/2007 23:28:59

To delete a backup on a local (or remote) server, use the /list switch along with the /b (backup name) and /v (version number) switches:

C:WINDOWSSystem32iisback.vbs /delete /b DailyBackup /v 0

This command would delete version zero of the ‘DailyBackup’ backup. Remember, if you want to run these commands on a remote server, just add the /s switch and the remote server name!

Replicating the IIS Metabase

The IIsCnfg.vbs script performs a number of different functions – including importing and exporting Metabase config files, saving the Metabase to disk etc. – but the one I was particularly in was the replication functionality offered through the /copy switch.

To replicate the IIS Metabase from one server to another, the following command can be used:

C:WINDOWSSystem32iiscnfg.vbs /copy /s winbtiis01 /ts winbtiis02 /tu Username /tp Password

The /copy switch indicates that the Metabase is to be replicated from the source server (specified in the /s switch – not necessarily required) to the target server (the /ts switch) using the target server user (the /tu switch) and target server password (the /tp switch).

The script is essentially a wrapper for a backup and restore operation (using the IIsBack.vbs script mentioned above) – go and have a look at the code if you’re interested (the function in question is called Repl and starts on line 721). In a nutshell, it performs the following operations:

  • Backs-up the source server Metabase (and forces an overwrite of an existing backp if necessary), creating a backup with the name iisreplback;
  • Maps drives on both the source and destination servers using the next available drive letters (which may be different on the two servers);
  • Copies the backup created above to the destination server (the backup is taken from C:WINDOWSSystem32inetsrvmetaback and written to the same directory on the destination server)
  • Unmaps the drive to the source server;
  • Restores the backup (on the remote server) using the IIsBack.vbs script;
  • Unmaps the drive to the destination server;

A Usable Replication Script

Armed with this newfound knowledge, I put together the following batch script to backup the Metabase (on the source and destination servers) and replicate between the two; finally the script lists the backups on both servers for auditing purposes. I’m sure I could have done this in VBS, but any with the words VB in the name gives me the willies…..

# Backup the IIS Metabase on WINBTIIS01 and 02
C:
WINDOWSSystem32iisback.vbs /s winbtiis01 /backup /b DailyBackup
C:
WINDOWSSystem32iisback.vbs /s winbtiis02 /backup /b DailyBackup

# Replicate the IIS Metabase from WINBTIIS01 to 02
C:
WINDOWSSystem32iiscnfg.vbs /copy /s winbtiis01 /ts winbtiis02 /tu Username /tp Password

# List the IIS Metabase backups on both WINBTIIS01 and 02
C:
WINDOWSSystem32iisback.vbs /s winbtiis01 /list
C:
WINDOWSSystem32iisback.vbs /s winbtiis02 /list

One thought on “Replicate the IIS6 Metabase Between Nodes

Leave a reply to David Symons Cancel reply