Customer Question: Renaming Site Collections in SharePoint 2013

As part of my day to day role as a Premier Field Engineer, I often receive questions from my customers as well as from colleagues or from their customers.  Last week I received a question that was interesting enough to warrant a blog post and broader discussion.

Note:  The instructions provided are for SharePoint 2013 but these steps are valid and will also work for SharePoint 2010.

Question from Customer

Good Morning.  I wanted to touch base with you on an issue that we are experiencing in our environment.  What we have discovered is that we are having difficulty “renaming” SharePoint 2013 sites. 

Consider the scenario where we need to take an existing SharePoint 2013 Site and rename it.  There are various blogs posts out there that suggest using Copy-SPSite to perform this operation.  What we have found is that the operation appears to work.  However, due to some customizations that we have deployed, we receive the following error:

“Error loading navigation.  The Managed Navigation term set is improperly attached to the site: (Correlation ID: removed)”

Also, what about moving sites between Web Applications within the same environment or between environments (such as from Test into Prod).  In general, what is are the best practices around renaming site collections and moving them from farm to farm?

Response to Customer

First of all, the Copy-SPSite commandlet is a upgrade and migration command that is intended to be used to make a copy of a site collection with its content being written into a user specified content database.  Typically this command is used to make copies of site collections that can be used to validate the upgrade process.   It wasn’t really intended to be used as part of day to day operations and has limitations that prevent it from being used for this purpose

Instead, the best way to accomplish your objective of renaming a SharePoint site collection is to use a combination of the following three commandlets:  Backup-SPSite, Restore-SPSite, and Remove SPSite.  Also, the same set of command can be used to accomplish your second goal of moving site collections between farms (such as from Test into Prod).

Backup-SPSite

Use Backup-SPSite to make a backup copy of a given site collection.  When using this command, you should always specify the –UseSQLsnapshot if your database server supports it.   Including the –UseSQlSnapshot option ensures a valid backup for larger site collections and ensure that users activity does not affect the validity of the backup.

For more information about Backup-SPSite see http://technet.microsoft.com/en-us/library/ff607901.aspx

Restore-SPSite

Once the backup is complete, use Restore-SPSite to create a new site collection from the backup.  The Restore-SPSite command will automatically assign a new id to the created site collection to avoid the potential of duplicate site ids.  You may specify the ContentDatabase name if you want to restore the site to a specific database and should use the HostHeadeerWebApplication parameter if you want to restore the site as a Host Named Site Collection (HNSC).

For more information about Restore-SPSite, see http://technet.microsoft.com/en-us/library/ff607788.aspx

Remove-SPSite

Once you have verified that they restored site is functioning as expected you can delete the old site using the Remove-SPSite command.  If the site collection is very large it is highly recommended that you specify the –GradualDelete option so as not to overburden the system while the site collection is deleted.

For more information about Remove-SPSite, see http://technet.microsoft.com/en-us/library/ff607948.aspx

Scenarios

Each of the usage examples below are based upon the following:

  • Contoso has three SharePoint farms:  SP-dev.contoso.net, sp-test.contoso.net and sp.contoso.net
  • There is an existing site sp.contoso.net/sites/HR that needs to renamed to sp.contso.net/HumanResources
  • A site called sp-test.contoso.net/sites/research needs to be moved from test into prod.

Rename Existing Site

The following command can be used to rename http://sp.contoso.net/sites/Hr to http://sp.contoso.net/sites/HumanResources

 Backup-SPSite http://sp.contoso.net/sites/HR `
   –Path E:\Backup\HRBackup.bak -UseSqlSnapshot
 Restore-SPSite http://sp.contoso.net/sites/HumanResources `
   –Path E:\Backup\HRBackup.bak
 Remove-SPSite http://sp.contoso.net/sites/HR –GradualDelete

Move Site Collection from Test to Prod

The following command can be used to move http://sp-test.contoso.net/sites/research to http://sp.contoso.net/sites/research

From Test

 Backup-SPSite http://sp-test.contoso.net/sites/research `
   –Path \\BackupServer\BackupShare\ResearchBackup.bak `
   -UseSqlSnapshot

From Prod

 Restore-SPSite http://sp.contoso.net/sites/research `
   –Path \\BackupServer\BackupShare\ResearchBackup.bak

Move Site Collection from path based URL in Test to Host Name Site Collection in Prod

The following command can be used to move http://sp-test.contoso.net/sites/research to http://research.contoso.net

From Test

 Backup-SPSite http://sp-test.contoso.net/sites/research `
   –Path \\BackupServer\BackupShare\ResearchBackup.bak `
   -UseSqlSnapshot

From Prod

 Restore-SPSite http://research.contoso.net `
   –Path \\BackupServer\BackupShare\ResearchBackup.bak `
   -HostHeaderWebApplication http://sp.contoso.net 

One of the great about utilizing the commands described here is that, as you can see, they can be used for essentially all of your site move and rename needs and won’t be subject to the limitations of the Copy-SPSite commands.

Hope you found this post helpful and I look forward to reading your comments.

# # # # #