Friday, July 31, 2009 4:21 PM
When working in a web farm environment, keeping content and configuration in sync is a critical piece of the puzzle. With IIS 5 and IIS 6 you could accomplish this with Microsoft’s Application Center. The product certainly has it’s flaws, but once you are able to get it working it is fairly low maintenance. To this day we still have a couple of production farms running App Center and it’s not something I ever have to worry about.
Unfortunately a few years ago you started hearing that Microsoft was discontinuing any future updates or releases of the App Center product. To make matters worse, they kept silent on what would replace the functionality that it provided and many people relied on. That’s where the Web Deployment Tool comes in . While it still doesn’t offer all of the functionality that App Center did, it’s a good start and they are constantly adding new features to it. Recently an article was posted which compares the features offered in both App Center and the Web Deployment tool.
What I was looking to do was use the Web Deployment Tool, and specifically the command line tool within it called MSDeploy.exe, to be able to synchronize content and all IIS configuration for a website between a source and destination server. To do that, follow these steps:
- Download the latest version of the Web Deployment tool from http://www.iis.net/extensions/WebDeploymentTool . Make sure you get the correct version for your environment – x86/x64
- Run the install on each server that you want to synchronize, choosing Complete to install all components
- Create a folder on your server to store the deployment scripts in. I use E:\WebsiteSyncJobs
- Create a folder within there for each website that you want to synchronize.
- Create a batch file using the info below as a template. Edit the values to match your website and server names. For the apphostconfig value, replace sample.website.com with the URL of the website you’ll be synchronizing. For the computername value, replace SERVERNAME with the name of the destination server that you will be synchronizing with. The below script will create an IIS backup prior to doing anything, and then move over your website and content and write everything to a log.
@ Echo Off
ECHO Starting Deployment on %DATE% at %TIME% >>msdeploySync.log
ECHO Starting Deployment on %DATE% at %TIME%
%windir%\system32\inetsrv\appcmd add backup
"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:apphostconfig="sample.website.com" -dest:apphostconfig="sample.website.com",computername=SERVERNAME -enablelink:AppPoolExtension >>msdeploysync.log
ECHO Deployment Complete on %DATE% at %TIME% >>msdeploysync.log
ECHO Deployment Complete on %DATE% at %TIME%
ECHO --------------------- >>msdeploysync.log
pause
- Save the file with a name that will make it easy to identify. For example, test.website.com_to_SERVER01.bat
- Create your website now on the source server if you haven’t already done so.
- Run the batch file. Once it is done, open up the msdeploySync.log file and check for any errors.
If everything is good and there were no issues then the site should now show up on the destination server. You should run the sync script anytime you make content or configuration changes to the website, that way everything will always match up. You could also easily schedule the synchronizations using Task Scheduler.