Synchronize IIS 7.0

Author: Faith Allington

Published on April 07, 2008 by faith_a

Updated on September 01, 2009 by faith_a

Average Rating  Rate It (3)

RSS

This quick guide will guide you through the process of using the Web Deployment Tool to sync a web site from a source to a destination on IIS 7.0. You can do this by "pushing" data to a remote destination, or by "pulling" data from a remote source. This guide will show both methods, as well as an option to just use an archive folder and not install the remote service.

What are the ways you can sync using the Web Deployment Tool?

  • Push (sync from a local source to a remote destination)
  • Pull (sync from a remote source to a local destination)
  • Independent Sync (initiate a sync from a machine where both destination and source are remote)
  • Manual Local Sync (create an archive of the source and copy it to the destination, then run it locally)

Prerequisites

This guide requires the following prerequisites:

  • .NET Framework 2.0 SP1 or greater
  • Web Deployment Tool 1.0

Note: If you have not already installed the Web Deployment Tool, see Installing the Web Deployment Tool.

Part 1 - View your site's dependencies

1. Get the dependencies of the web site by running the following command:

msdeploy -verb:getDependencies -source:apphostconfig="Default Web Site"

2. Review the output of the dependencies and look for any script maps or installed components in use by the site. For example, if Windows Authentication is in use by the web site, you will see <dependency name="WindowsAuthentication" />.

3. If your site is inheriting any script maps, these will not be listed in the dependencies and you should also review the script maps for your site manually.

4. Compile a list of the components needed on the destination.

For detailed steps on analyzing the output of getDependencies, see Viewing Dependencies of a Web site.

 

Part 2 - Configure the target (destination)

1. Review the list of dependencies and install them on the destination server.

For example, let’s assume you had the following in use for your web site:

• ASP.NET

• Windows Authentication

• Anonymous Authentication

Based on analyzing your dependencies, you would install those components.

 

Part 3 – Sync your site to the target

1. Always make a backup of the destination and source servers. Even if you are just testing, it allows you to easily restore the state of your server. Run the following command to backup an IIS 7.0 server:

%windir%\system32\inetsrv\appcmd add backup "PreMsDeploy"

2. Install the remote service on the source or the destination depending on if you want to "pull" the data from a remote source or "push" the data to a remote destination.

3. Start the service on the machine.

net start msdepsvc 

4. Run the following command to validate what would happen if the sync was run. The whatif will not show every change, it will just show an optimistic view of what might be changed if everything succeeds (doesn't catch errors where you can't write to the destination, etc.)

Pushing to remote destination, running on source machine
msdeploy -verb:sync -source:apphostconfig="Default Web Site" -dest:apphostconfig="Default Web Site",computername=Server1 -whatif > msdeploysync.log

Pulling from a remote source, running on destination machine
msdeploy -verb:sync -source:apphostconfig="Default Web Site",computername=Server1 -dest:apphostconfig="Default Web Site" -whatif > msdeploysync.log

5. After verifying the output, run the same command again without the whatif flag:

Pushing to remote destination, running on source machine
msdeploy -verb:sync -source:apphostconfig="Default Web Site" -dest:apphostconfig="Default Web Site",computername=Server1 > msdeploysync.log

Pulling from a remote source, running on destination machine
msdeploy -verb:sync -source:apphostconfig="Default Web Site",computername=Server1 -dest:apphostconfig="Default Web Site" > msdeploysync.log

{Optional - Sync your site to the target using an archive}

If you don't wish to use the remote service, you can use an archive instead. 

1. Run the following command on the destination server to take an archive of the server for synchronization:

msdeploy -verb:sync  -source:apphostconfig="Default Web Site" -dest:archivedir=c:\site1archive

2. Copy the archive folder to the destination server. 

3. Run the following command on the destination server to validate what would happen if a sync was run:

msdeploy -verb:sync -source:archivedir=c:\site1archive -dest:apphostconfig="Default Web Site" -whatif > msdeploysync.log

4. After verifying the output, run the same command again without the whatif flag:

msdeploy -verb:sync -source:archivedir=c:\site1archive -dest:apphostconfig="Default Web Site" > msdeploysync.log

 

You are now done synchronizing your site. To verify, test browsing to the web site on the destination server. For troubleshooting help, see Troubleshooting the Web Deployment Tool.

Summary

You have now synchronized a web site from a source IIS 7.0 server to a destination IIS 7.0 server, including viewing the dependencies, configuring the destination IIS 7.0 server and performing the synchronization.

Comments

  1. Submitted on Oct 06 2008 by
    pazure
    On step 2 of Part 3, it reads

    2. Run the following command on the destination server to take an archive of the server for synchronization:

    Shouldn't it read...?

    2. Run the following command on the SOURCE server to take an archive of the server for synchronization:
  2. Submitted on Nov 06 2008 by
    faith_a
    Thanks for the note pazure, this is fixed.
  3. Submitted on Mar 10 2009 by
    DaveWebb
    Hello. This is a really nice tool. I've just written a VB Script that synchronises every web site on the source server with the target server (anyone can have a copy if they ask).

    However, is there a way to sync files based on timestamps? I have an NLB cluster setup for 2 IIS7 servers using a shared configuration (when browsing to a site it access a random server). The problem I face is if a file gets updated or removed from Server2 then the sync that runs on Server1 overrides that change. Can I get it to sync by working out which server has the newest files?

    Dave
  4. Submitted on Jun 04 2009 by
    member57123811
    Hi Dave,
    i have a server farm like yours, could you post me script, please?
    Many thanks and have a good day!
  5. Submitted on Jul 09 2009 by
    Paul_1234
    Hi Dave,

    could i please get a copy of your script too..
  6. Submitted on Jul 17 2009 by
    rdowell
    Dave, could I get a copy of your script also.
  7. Submitted on Jul 20 2009 by
    robol
    hi all ,
    here is a script which can replication iis configuration across multiple servers
    http://www.orcsweb.com/articles/ClusterUtils.zip

    here is tutorial how to do it

    http://www.orcsweb.com/articles/IISConf.aspx

    Hope that satisfy your needs
    cheers
    Robol
    email me if you need any help
    robol@pz10.com

You must Log In to comment.