Recently here at Imulus we had a production server go down, meaning all of our clients' websites on that box were unreachable.  Thankfully, we had the proper precautions taken and backups were restored in hours.  Yet it was a very stressful time for all of us and it led me to wonder what else was out there and how much better we could have responded in an emergency.

After a bit of research I found Microsoft's Web Deployment Tool, also sometimes referred to as MSDeploy.  Of course it only applies to Windows Servers with IIS, so if you are looking for another OS/web server solution this article is not for you.

I was somewhat skeptical at first because, well, I'm skeptical of everything.  They even call me the skeptic here at work.  It also seemed a lot of people that were writing about it were fanboys and it was a very new product (I started testing when this product was still a release candidate).  After reading about it thought I should give it a shot since it sounded very powerful.  Here is a short version of what we were looking for:

  • Able to take all manual steps out of recovery
  • Backup all files and code that made up the website
  • Include all settings, SSL Certificates, Bindings etc.

After playing with it and doing some tests I was very impressed.  The tool does deployment/backups per site, so if you host multiple sites on a server and want to customize depending on site you are able to do that.  You can view code dependencies, backup databases – do almost anything you want.  You can choose to use the GUI from IIS Manager or go command line.  You can choose to export the package to another server immediately or create a folder with an archive of all necessary files for restoration later.

If you are interested in using it for deploying, go get it,  check out this overview page or visit their forums.

If you are interested in seeing how we created a fully automated solution, read on.

Since we wanted something that had little or no human interaction, and therefore not error prone with a high degree of reliability, I came up with a solution that took all human involvement out of the backup and recovery process.  The solution we came up with is broken into 3 parts.

1) Backups of all sites in IIS needs to occur in case of a server failure.

2) Replicate backups to other available live servers as well as offsite automatically.

3) The ability to recover our site(s) needs to be easily and quickly available with fewest manual steps as possible.

To address all these I wrote a small, simple program to help the Web Deployment Tool with this process.  The program has two purposes and can easily be scheduled through the task manager in order to create a repetitive and up-to-date solution.  The program writes two files.  The first .bat file should be run nightly, or however often you want, and contains commands for msdeploy that create an archive backup for each site in IIS.  The second bat file contains all commands for msdeploy to install/restore each website that has been archived.  This second file should only be run if a server goes down and you need to restore sites on your standby server.

To take care of our first step we must schedule an execution of our custom application to generate our archival and restore bat files.  We must also schedule an execution of the archival .bat file our program generates to be run afterwards.  The bat file execution results in the creation of an archive for each site.

Now that all sites are backed up with step #1, we need to take care of step #2.  To do this, just use your favorite sync tool to copy all necessary files to other server(s) and offsite.  If you don't know what I am talking about, check out Super Flexible File Synchronizer or Microsoft's Sync Toy.  Using a program to move files on an automatic basis allows us to be ready to execute step three if we ever need to.

Step #3 is the only manual step in this whole process and is quite easy.  First, bind the new server you are recovering to with all necessary IPs, or do whatever network voodoo you need to.  Secondly, run the recovery .bat file.  The file will install your site(s), application pool, certs and restore all settings.  One click recovery?  Yes please!

If you think this code could be used in your environment you may grab a generic version here – I hope it helps.  Obviously, I make no warranty about any of this process or code.  If you do use the code, please read the readme as well as the code comments.  The code is a Visual Studio 2008 C# solution licensed under GPL.  Use your heads and do your testing people!

If you come up with anything different feel free to comment and let us know how you have improved upon the process.  If you modify the code please send me what you have done.  Enjoy!

  • Chris

    Great article! It is good info for someone starting the IIS7 process. I was looking for your code but the link is no good. Any chance of taking a peek w/ a good link?

  • http://imulus.com Mario

    Link updated.

  • Sascha

    Link is broken again. Please update. Thanks