Thursday, March 27, 2014

SharePoint 2010: Migrating a Sub-Site to a Different (existing) Site Collection

I decided to write this blog post because I screwed up today.  Yes, even good guys have bad days and nobody is perfect, even though to our customers and clients we appear to be.  So, slightly embarrassed for my mistake, I'm putting this out there so others can hopefully learn form this incident and avoid creating more problems and work for yourself.

I was asked by a customer to move some sub-sites from one site collection to another.  The reasoning was because he was running out of space in his storage quota and wanted to move these sites to a different content database.  This is not a big effort usually.  It's actually quite simple using powershell.

First step is you export the original site per this technet article (http://technet.microsoft.com/en-us/library/ff607895(v=office.15).aspx):

Export-SPWeb <URL> -Path c:\site_export.cmp -NoFileCompression

Once the file is created, you simply import the site to the new location (http://technet.microsoft.com/en-us/library/ff607613(v=office.15).aspx):

Import-SPWeb -Identity <URL> -Path c:\location_of_export.cmp -NoFileCompression

When you've confirmed everything looks good in the new location, you can delete the site from the original location and you're done.

BUT... HERE IS WHAT THEY DON'T TELL YOU....

You can also use Import-SPWeb to import a SharePoint list too.  The difference is, when you use this cmdlet to copy a SharePoint list, you simply specify the root site URL and it will create the new list or library in that location.  If you use this cmdlet for a site however, you MUST FIRST create a placeholder site in the destination web application.  If you only specify the root URL, it WILL OVERWRITE that site, instead of creating a new sub-site.

What made this issue even worse for me was, the original root site was created using a 'blank site' template (STS#1) and when I overwrote it, the site was changed to a 'team site' template (STS#0).  Not a big deal, right?  Wrong.  When I tried to restore the site back using an export/import from an unattached backup copy of the content database, it wouldnt overwrite the site back from team site template to blank site template.  Fortunately the site was more or less a placeholder, so I was able to fix it manually, but it could have been much, much worse.

So take it from me, always double check your cmdlets and never assume that Microsoft will be consistent in their processes.  You have been warned.

No comments:

Post a Comment