Clone a SharePoint 2010 Site using PowerShell
Creating SharePoint 2010 site collections in a test environment becomes tedious and definitely no fun especially when you need a 5 or 6 levels deep “Lorem Ipsum” dummy site with tons of pages under them. But, what if you have already created a previous dummy site that fits all your requirements for your next project and you just don’t have the time and patience to recreate it manually? I was in this situation the other day and I refused to do it manually again, so I started to do some research. It took me awhile to find something useful and finally I managed to put together two different PowerShell scripts that does the trick. I don’t say this is the best way to do it but it worked perfectly for me.
So, first find the site you would like to clone. Head over to SharePoint 2010 Management Shell, open it, copy the following script and paste it. (Right-click >> Paste) and hit Enter. Make sure you plug your site URL for Identity attribute and pick a path where to backup your site and a name for your backup.
Backup-SPSite -Identity "http://myspsite" -Path "C:\backups\myspsite.bak" -Force -Confirm:$False |
Next, you need to create your new web application manually. Go to “Central Administration” >> “Manage web applications” >> New. For testing purposes let’s call it myspsite and if you don’t use any host headers you need to pick a port number, so we picked :81 since our main site uses port 80 by default. Our new site URL would be http://myspsite:81
Now, we need to restore our newly backed up main site (http://myspsite) to the newly created site (http://myspsite:81) so it can inherit all the site/page structure. Go back to the SharePoint 2010 Management Shell, copy the following script and paste it. (Right-click >> Paste) and hit Enter.
Restore-SPSite "http://myspsite:81" -Path C:\backups\myspsite-81.bak -Force -Confirm:$False |
If you didn’t get any errors, your new site looks pretty much like the main site just under different URL. Notice that your new site inherited tons of stuff from the main site: security settings, themes, master pages, page layouts, title… That means you still have some minor clean-up to do but this is nothing compare to what you had to go thru by creating all the those sites and pages manually.
Hi Sid,
I was reading your post and I wanted to recommend cloudshare to you. It’s an excellent solution for dev/test with SharePoint. You can import your existing site or start from scratch with preset templates in your environment. I think you’d have a much easier time using CloudShare than what you had to do with Powershell. The website is here – http://www.cloudshare.com. Let me know what you think. I’d love to hear your thoughts.
This worked well for me, bar a few hiccups, but it only clones single site collections. Is there a similar way to clone an entire web application including all site collections therein?
This worked nicely when the ‘Export-SPWeb/Import-SPWeb’ commands did not work. (I believe the ‘Export-SPWeb/Import-SPWeb’ commands had issues with size or number of subsites or something likel that).
Thank you for your post.
This worked well on SharePoint 2013 too. Thank you!