Hack 55 Restore the Metabase

figs/moderate.gif figs/hack55.gif

While it's simple to restore the metabase from a backup, what if you have no backup or can't open the GUI? Use this hack.

In [Hack #54], we explored several ways of backing up the metabase, including backing up the machine's System State information using the Backup utility, saving the configuration in Internet Services Manager with MetaEdit (a downloadable tool for IIS 5), and using the history feature of IIS 6.

Restoring the metabase from backup is equally straightforward. If you are recovering your machine from a disaster, the metabase is restored as part of the System State information you previously backed up, assuming you didn't change the default option of including System Protected Files in your backup. Alternately, if you're restoring the metabase on a working machine to recover a previous good IIS configuration, simply select the backup in the Configuration Backup/Restore dialog box and click Restore. Then, follow the prompts and wait as IIS stops, rebuilds, and restarts. Restoring the IIS 6 metabase from a history file is done in the same way: just select a history file in the Configuration Backup/Restore dialog box and click Restore.

Notice that the dialog box (refer back to Figure 6-2) displays both metabase backups stored in %SystemRoot%\System32\inetsrv\MetaBack and history files stored in %SystemRoot%\System32\inetsrv\History in one combined list. You can tell the difference between a history file and a backup file in this list by looking at the filenames: all history files are named Automatic Backup and are distinguished in the GUI only by their timestamp, while backup files you create are named whatever you decide to call them.

It all seems so simple, but what if your metabase becomes corrupt and you need to restore it from backup? If you can start Internet Services Manager, you can use the Configuration Backup/Restore dialog box as described earlier. But if the metabase is corrupted beyond the ability of IIS to repair it, Internet Services Manager might not even start, and then you're stuck. What do you do?

You could restore the entire System State of your machine from backup media. Unfortunately, that might have unpleasant side effects, especially if you're running IIS on a domain controller. For example, all those users and groups you created since the last backup will suddenly be gone (unless you have another domain controller to replicate the information). There might also be changes to the Registry that will be rolled back, and these changes might be harder to troubleshoot.

But there's a better way.

Manually Restoring a Backup in IIS 5

If you can't open Internet Services Manager, try replacing the metabase with its most recent backup.

First, stop all IIS services by typing net stop iisadmin /y at the command prompt (or use iisreset /stop if you prefer). Then, find the metabase.bin file in %Systemroot%\System32\inetsrv and rename it metabase.bad (keep it in case you need it later). Copy your backup file (it probably has the extension .MD0) from %Systemroot%\System32\inetsrv\MetaBack to %Systemroot%\System32\inetsrv and rename it metabase.bin. Now, restart the computer. You should once again have a working IIS configuration and be able to start Internet Services Manager.

By the by, instead of rebooting your machine, you can try to restart IIS services by typing iisreset /start from the command line. But in my experience, it's better to reboot your machine, because IIS is sometimes a little flakey after a restore like this.

Restoring without metabase backups

What if you don't have any metabase backups in the inetsrv\MetaBack folder? Perhaps you deleted them all or you never created any in the first place. Hopefully, you do have a recent backup of your system drive?on tape, perhaps? Use the Backup utility to restore the inetsrv folder from backup to a new location (C:\inetsrv2, for example) and repeat the previous process by copying C:\inetsrv2\metabase.bin over %Systemroot%\System32\inetsrv\metabase.bin. Be sure to stop the IIS services as before, and reboot the machine when you've finished.

Restoring without a backup on tape

But what if there are no metabase backups in your MetaBack folder and you don't even have a working backup on tape?

Here's a hack you can try that just might work: look in the inetsrv folder on your machine for files named metabase.bak or metabase.bin.bak. If you find one, you're in luck; this is a temporary metabase backup created by IIS when it has problems updating the metabase due to corruption. Normally, this temporary file is deleted once a successful metabase update is performed, but if your metabase corruption was caused by some interruption in the update process (a server glitch or hiccup), IIS might not yet have gotten around to deleting the temp file and you can use it to restore your configuration. Simply stop the services, rename metabase.bin to metabase.bad, rename metabase.bak to metabase.bin, and reboot the machine.

Reinstalling IIS

In the worst case scenario, you have no tape backup, nothing in the MetaBack directory, and no temporary .bak file in inetsrv. What do you do? Use Add/Remove Programs in the Control Panel to first uninstall IIS and then reinstall it. After you uninstall it, you should also check the %Systemroot%\System32\inetsrv folder (which is not deleted by the uninstall process) for a file named metabase.bin. If you find one, delete it before reinstalling IIS.

Moral of the story? Sometimes a reinstall is the only way to recover.

Manually Restoring a Backup in IIS 6

Remember that the metabase in IIS 6 is structured differently [Hack #54]; it consists of two files, MetaBase.xml and MBSchema.xml, instead of the single metabase.bin file used by IIS 5. Fortunately, you normally have to restore only the MetaBase.xml file, because it's highly unlikely that you would have made changes to the schema. The procedures to follow are identical to those described in the previous section, except you replace metabase.bin with MetaBase.xml in each step where metabase.bin occurs. I've also found that restarting IIS by using iisreset /start seems to work fine and you don't have to reboot. IIS in Windows Server 2003 does seem more robust than IIS in Windows 2000.

See Also

[Hack #59]