Tuesday, April 10, 2012

Clone IIS 7 Web Site - How to

It used to be very easy to clone an IIS web site in IIS 6, old adsutil.vbs script would do just fine for anyone setting large number of web sites in a web server farm.  Now, all your scripts are broken due to the fact that the "admin scripts" for IIS 6 no longer work with IIS 7, thanks a lot Microsoft. Disappointments never stop with that company.

To make this short and simple, now we have "appcmd" (http://technet.microsoft.com/en-us/library/cc772200(v=ws.10).aspx).

You can do all kinds of things with it.  So, here is how to clone a site, siteA.com to siteB.com, for web apps running in a SAAS environment.

%windir%\system32\inetsrv\appcmd list site "mastersite.com" /config /xml > c:\copy_of_mastersite.com.xml

You can also cd into inetsrv directory: 

cd c:\Windows\system32\inetsrv and run appcmd from there. 

What the appcmd command is doing up there is simply exporting the configuration of master.com into an .xml file.  Now all you need to do is replace SITE.NAME and SITE.ID in the .xml file.  Additionally, any bindings for the domain name of the new site. Once that is done you are ready to import it.

I would rename copy_of_mastersite.com to mastersite2.com.xml or whatever you new domain/subdomain is going to be.

%windir%\system32\inetsrv\appcmd add site /in < c:\copy_of_mastersite.com.xml

By the way, if you are serving SSL on the master site and you want your clone site to serve SSL as well, you'll need to tweak a few things, here is an exemple:

appcmd set site "mastersite2.com" /bindings:http/*:8080:,http/*:80/mastersite2.com,https/*:443:mastersite2.com

Basically SSL with host headers, google this more info on that.  I used port 8080 but you can use any other port. Make sure to go back into the IIS manager for this new site and select a new SSL certificate under bindings

Let me know if that helps you.


Karesz said...

This works fine until you don't need to copy the configuration. Add something e.g in COnfiguration editor add a node, which will appear in applicationHost.config, but will not be copied into the clone config.


Karesz said...
This comment has been removed by the author.