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
{ 12 comments… read them below or add one }
Great tip steve. I never even knew this was possible. Been backing up the entire server with the system state, and I missed how with Apachie on Linux I could just copy the website files, and the config files. Now I can do the same with IIS. Thanks a ton.
What about srvr 2008? Will this work on that as well?
John,
Glad it helped you out. Been using this for some time on our own websites. Works great if you want to add another server, or even have a staging server with the same exact config.
Hello Mike,
I don’t think it will. That will have to be another article. I would have to check, but I would imagine that MS replaced it with a powershell script of some type.
Steve,
Thank you for answering my question. It was exactly what I was looking for!
No problem…glad I could help
This is a great tip. Thanks Steve
No problem Jen…glad it helped you out.
Hi steve. Like the video. Is there anyway to backup just smtp settings?
Hello David,
I believe you could set your sp and dp to /lm/SmtpSvc1 and it will backup the first SMTP instance…if you have more than one I think you would need to use multiple files, ore just backup the whole IIS tree (lm)
Hi Steve, Is is possible to import onto a server 2008 (i cannot get iiscnfg to work)Server 2008 has iis 7 installed with iis6 but as i only require the smtp config from the server 2003 box
Hoping for an answer to Mohammed’s question as I have the same issue.