Trying something new this week – got a video version of this weeks tip:
Got a question from Linda this week,
“Steve. We have quite a few IIS based web servers and each of them has their own custom configuration. I know how to backup all the files, but is there any way to backup and restore IIS settings from the command line? ”
Great question. When using IIS, you eventually get lots of custom settings hiding in there:
IIS Stores all of these settings in what as known as the metabase. It keeps track of the home directory, ISAPI filters, what type of files it will process, etc. How to we back this up?
You can back it up manually from the IIS manager:
But this has a major flaw. It just backs it up to a hidden file on your hard drive. Sure you can find this, and pull it off – but that takes some digging. That won’t help you much when the server is smoking and you want to get another one in its place right away.
How can we automate this process, and be able to grab the file and do what we want with it?
By using a little known VBS file that is included with Windows
It is called IISCnfg.vbs
Before we can use it, get to a command line and type IISCnfg and then enter.
It will give you an error, and then ask if you want to default to use CScript.exe instead of VBScript.exe for your VB Scripts.
Once you say yes, you can start calling it from your batch files or the command line.
There are many options to iiscnfg, but there are a few things that we will require:
-We want to export the settings
-We want all the settings, so we will start at the root and include the children
-We need to set a password on the exported file, or it won’t work on another server (Feature or bug – you decide)
-We want to export the file to a specific location, not the metabase storage area
So here are those requirements translated into arguments:
iiscnfg /export /sp /lm /children /inherited /d [password] /f c:\backup\IISMetabase.bak
The [password] is the password the file will be encrypted with. You will need this to restore it, so don’t forget it!
/sp (Source Path) indicates where in the IIS structure you want to start the backup /lm is at the top of this (I believe lm stands for local machine…someone please write a comment below if I am wrong)
So the above code will take our entire structure and back it up to c:\backup\IISMetabase.bak and then encrypt that file with the password [password]
Put that in your batch file used for backups and you can pull that config any time you want. Keep in mind this only backs up your configuration. Not the files that make up your website or ftp sites.
Later, a new VP of IT walks in and starts plunking around on your web servers
After he “improved” the system, how do you restore the settings?
You get that metabase file from your backups, and import it using a very similar command line:
iiscnfg /import /dp /lm /sp /lm /children /inherited /d [password] /f c:\backup\IISMetabase.bak
Note the /dp (Destination Path) and /sp (Source path). In my example they point to the same place – the top of the IIS settings tree.
Notice the password – it must be the same as the one used to back it up. If you forgot it your hosed. If you forgot to even set a password you might be OK…as long as it is the same system. Otherwise again, your hosed.
That is all there is to it. One line to backup, and one line to restore.
One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools