How to Create Copy of Web Site on Same Server or Remote Server using Web Deploy

 

Continuing with the different uses of Web Deploy to help with the management of the web site environment is the method to create an exact copy of the web site on the same server, or a remote server, with a Web Deployment script. This method differs from the typical manual method by automatically creating the web site structure, web site, application pool, NTFS permissions, and IIS settings, with the exact same settings as the source web site. In addition, this process allows for automation and this is crucial in reducing the time spent as an IIS administrator.

The manual steps of this process are creating the destination directory for the new site and editing the web site bindings and both of these actions can be scripted.

In this situation, I am using the site URLTest and it is located at c:\inetpub\wwwroot\urltest. A new directory can be created in File Explorer –> c:\inetpub\wwwroot\urltest2.

The Web Deployment tool can be used to create a copy of the site on the same server, or a remote server. Both examples will be shown below.

Deployment Scripts:

The omission of the attribute computername in the script tells Web Deploy to perform all actions on the local server, or localhost. As always, use the -whatif command to test the script *before* committing to the server and resolve any issues encountered.

Local Server - Create Exact Copy of Site Pointing to Same Web Directory:

msdeploy -verb:sync -source:appHostConfig="URLTest" -dest:appHostConfig="URLTest2" -enableLink:AppPoolExtension -whatif

Local Server - Create Exact Copy of Site and Copy Files to New Directory:

The -replace rule is used to change the location of the web site in URLTest to a new directory created earlier. Review this link for more information on using the replace rule.

msdeploy -verb:sync -source:appHostConfig="URLTest" -dest:appHostConfig="URLTest2" -replace:objectname=virtualDirectory,match="c:\\inetpub\\wwwroot\\urltest",replace="c:\\inetpub\wwwroot\urltest2" -enableLink:AppPoolExtension -whatif

or

msdeploy -verb:sync -source:appHostConfig="URLTest" -dest:appHostConfig="URLTest2" -replace:objectname=virtualDirectory,targetAttributeName=physicalPath,replace="c:\inetpub\wwwroot\urltest2" -enableLink:AppPoolExtension -whatif

Remote Server - Push from Source Server to Remote Server:

msdeploy -verb:sync -source:appHostConfig="URLTest" -dest:appHostConfig="URLTest2",computername=10.1.1.15 -enableLink:AppPoolExtension -whatif

Note: Use the syntax listed above to change the physical path on the remove server.

Expected Error:

There will be an error stating the site ID cannot be duplicated and the ID will be incremented. clip_image001

To commit the command onto the server, remove the -whatif statement and run

To verify the site was successfully created, run the appcmd statement to list the sites:

Appcmd list sites

In this situation, there is an issue with the newly created site as it is listening on the same port, host header, and IP address as the original site. One of the three variables must be updated to remove the conflict and allow the site to come online: clip_image002 clip_image003

Change the listening port: clip_image004

The fastest method is to open the Internet Manager utility or cmd –> inetmgr, right click on the new site and select Edit Bindings. Of course, this can be scripted by using the appcmd utility.

Start the Site:

Appcmd start site "URLTest2"