Tuesday, October 4, 2016

Copy-SPSite and 404 error

[Background]

"Copy-SPSite" is a new command available from SharePoint 2013. In theory, we can generate a identical site collection with different Site ID and URL.

However, when trying to open the new site from web browser, I got "404" Page Not Found error. I am not the only one who got this problem.

[Error Message]

Error message in web page:

This error (HTTP 404 Not Found) means that Internet Explorer was able to connect to the website, but the page you wanted was not found. It’s possible that the webpage is temporarily unavailable. Alternatively, the website might have changed or removed the webpage.

Error message in ULS:

Exception trying get context compatibility level: System.NullReferenceException: Object reference not set to an instance of an object.  
 at Microsoft.SharePoint.SPSite.PreinitializeServer(SPRequest request)  
 at Microsoft.SharePoint.SPSite.GetSPRequest()  
 at Microsoft.SharePoint.SPSite.InitSite()  
 at Microsoft.SharePoint.ApplicationRuntime.SPRequestModule.GetContextCompatibilityLevel(Uri requestUri)

[Trouble Shooting]

Initially, I thought I just need to specify a new content database for the new site, but, that didn't help.

Not sure what went wrong. I guess there is a bug in the command implementation.

Cumulative Updates (until CU201609) haven't mentioned this issue.

Do we have to switch back to "Backup-SPSite and Restore-SPSite"? The real problem is, SharePoint doesn't allow duplicated SiteID in a farm.

[Fix]

Luckily, I found a way to make it work. Below is the script. Hopefully it can save you some time.


Mount-SPContentDatabase -AssignNewDatabaseId -Name $databaseNameTmp -DatabaseServer $databaseServer -WebApplication http://$webAppSource$envSuffix/

Copy-SPSite http://$webAppSource$envSuffix/sites/$siteNameSource -DestinationDatabase $databaseNameTmp -TargetUrl http://$webAppSource$envSuffix/sites/$siteNameDest

Move-SPSite http://$webAppSource$envSuffix/sites/$siteNameDest -DestinationDatabase $databaseNameSource -Confirm:$false

Dismount-SPContentDatabase -Identity $databaseNameTmp -Confirm:$false


The script above generate a new site in the same web application.  To copy site to different web application is similar.

Mount-SPContentDatabase -AssignNewDatabaseId -Name $databaseNameTmp -DatabaseServer $databaseServer -WebApplication http://$webAppSource$envSuffix/

Copy-SPSite http://$webAppSource$envSuffix/sites/$siteNameSource -DestinationDatabase $databaseNameTmp -TargetUrl http://$webAppSource$envSuffix/sites/$siteNameDest

Move-SPSite http://$webAppSource$envSuffix/sites/$siteNameDest -DestinationDatabase $databaseNameSource -Confirm:$false

Dismount-SPContentDatabase -Identity $databaseNameTmp -Confirm:$false

Mount-SPContentDatabase -AssignNewDatabaseId -Name $databaseNameTmp -DatabaseServer $databaseServer -WebApplication http://$webAppDest$envSuffix/

Move-SPSite http://$webAppDest$envSuffix/sites/$siteNameDest -DestinationDatabase $databaseNameDest -Confirm:$false

Dismount-SPContentDatabase -Identity $databaseNameTmp -Confirm:$false

No comments:

Post a Comment