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 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!