Scheduled metabase backups
IIS can be one of the most configuration intensive server applications in your environment, so it makes especially good sense to ensure you always have a current backup of the metabase which stores all of the configuration directives in IIS. IIS metabase backups are split into two files with the naming convention of MDx and SCx, where MD is the metabase backup, SC is the schema backup and x is the revision number of the backup using values from 0~999. Previously we have covered the topic of backing up and restoring your IIS 6 metbase via the GUI and the command line, and in this guide we'll be using a script to automate this task which is then scheduled to ensure your backups are always up to date.
The script we'll be using in this article is based on the script I used previously in my guide to backing up MySQL automatically using a batch file. What this script basically does is create a backup of your IIS metabase, moves and compresses it to a user defined location, and then emails a user defined email address the results. To do this the script uses two executables to compress and email backup reports, and one VB script which comes with IIS 6 to perform the actual backup. These utilities are;
- gzip - a command line based compression tool
- blat - a command line based email client
- iisback.vbs - script for managing your IIS metabase backups which comes with Windows 2003/ IIS 6.
Download these files along with the iis_backup.bat batch file script from below and using your favorite text editor configure all the options at the top of the batch file where the "ENTER_VALUE_HERE" string is with the values from your own environment. Once complete, save the batch file and it is time to give it a test. Run the iis_backup.bat script by either double clicking on it or running it from a command prompt. Once completed you should find two compressed files in your specified backup directory, and have an email containing a summary of the results.
Once this is complete the only step left is to schedule the backups so that they run automatically at a set time. How often you backup your metabase is entirely up to you, but it should be at least as often as the number of times you modify your IIS environment on average. If you make changes once a month, then there is little worth in backing it up every day, and if you modify it daily there is risk in only backing it up once a month. In this example we'll set the IIS_backup.bat file to run one a week on a Sunday night at 11pm. To do this open a command window and type in;
at 23:00 /every:Su x:\path\to\iis_backup.bat
That is it, your IIS metabase should now have regular backups. If possible try and ensure the backups are not stored on the same hardware as IIS is running on, as backing up the metabase to the same physical machine only really protects you from human error, not catastrophic error. As always feel free to leave any comments, questions or suggestions you might have here or in the forums.