Web Site Migration with Web Deploy

This scenario will migrate all of the web server's bindings, certificates, and other high level web site information and is used in the following instances:

  • Migrating a web site to a new version of IIS on another server
  • Migrating a web site to a new IIS server
  • Promoting an entire web site between environments, such as a promotion from QA to Production utilizing a code promotion strategy
  • Updating an existing web site on an IIS server

Here is the link to the TechNet content about the appHostConfig provider- https://technet.microsoft.com/en-us/library/dd569080(v=WS.10).aspx

Note: This scenario can only be accomplished with the Web Deploy command line.

Example Syntax:

The -source switch in Web Deploy for migrating a web site is appHostConfig and this switch includes IIS settings such as bindings, certificates, and other top level site settings.

Complete Web Site - appHostConfig

Example:

msdeploy -verb:sync -source:appHostConfig="Contoso.com" -dest:appHostConfig="Hello",computerName=10.0.0.12

Contoso.com= Web Site

Housekeeping:

Source server = Server sending the web files

Target server = Server receiving the files (new server)

For these examples, the Source server IP is 10.0.0.11 and the Target server is 10.0.0.12.

As I am working with customers in either the test or production environments, I always stress the importance of taking backups on all servers BEFORE changes to recreate a restore point in case issues arise during the procedure. In addition, I use the -whatif statement heavily to fix issues before a migration occurs.

The target server must have the Web Deploy service installed and running in order to communicate from the source server. If the service is not installed, run the Web Deploy installer again and select the Service option.

Backup on Target Server:

Make a backup of the IIS configuration settings on the target server using IIS backup and the web deploy tool to back up the web.config files:

%windir%\system32\inetsrv\appcmd add backup “PreContosoV2_Deploy”

AND

msdeploy -verb:sync -source:appHostConfig="Contoso.com" -dest:package=c:\_WebDeploy\PreContosoUpdate.zip

Migration Options:

There are two options presented to migrate the web site. The first option generates a Web Deploy package in the .zip format and this package is copied to the destination server. The second option performs the migration directly from the command prompt and is the fastest method. With both methods, please verify the results from the migration is the expected result by using the –whatif command to ensure a successfully migration.

Verify before Execution:

From the command prompt, enter the following commands to create a differencing file and mechanism to review errors and warnings before generating the package file:

msdeploy.exe -verb:sync -source:appHostConfig="Contoso.com",computername=10.0.0.11 -dest:appHostConfig="Contoso.com",computername=10.0.0.12 –verbose -whatif > c:\_WebDeploy\ServerDiff.txt

Note: The command switch -source:appHostConfig is the equivalent to the IIS web site level. This means, include everything in the web site when creating the package.

Inspect the output in the text file by searching on Error and Warning and resolve the issues before generating the package. Again, the pipe command to the file is optional and output from the WhatIf command can be viewed within the command window.

Note: If the website on the Target does not exist, the output from the -whatif statement will show all adds and no deletes.

Package Transfer Method:

From the command prompt, enter the following commands to create a Web Deploy package:

msdeploy -verb:sync -source:appHostConfig="Contoso.com" -dest:package=c:\_WebDeploy\SourceServerContosoSite.zip

Copy the package to the target server and import using the following command to test before the import:

msdeploy -verb:sync -source:c:\_WebDeploy\SourceServerContosoSite.zip -dest:appHostConfig="Contoso.com" –verbose -whatif > c:\_WebDeploy\SourceImportWhatIf.txt

Inspect the output in the text file by searching on Error and Warning and resolve the issues before generating the package.

Open the command prompt on the target server, run the following command to complete the migration:

msdeploy -verb:sync -source:c:\_WebDeploy\SourceServerContosoSite.zip -dest:appHostConfig="Contoso.com"

Command Line Method without Packages:

This method generates a server to server transfer of entire website settings and files.

From the command prompt, enter the following commands to create a differencing file and mechanism to review errors and warnings before generating the package file:

msdeploy.exe -verb:sync -source:appHostConfig="Contoso.com",computername=10.0.0.11 -dest:appHostConfig="Contoso.com",computername=10.0.0.12 -whatif > c:\_WebDeploy\WebSiteDiff.txt

Inspect the output in the text file by searching on Error and Warning and resolve the issues before generating the package. The output file is the history of the migration and can be archived.

msdeploy.exe -verb:sync -source:appHostConfig="Contoso.com",computername=10.0.0.11 -dest:appHostConfig="Contoso.com",computername=10.0.0.12 > c:\_WebDeploy\SourceToTargerWebSiteMigration.txt