SharePoint 2010 Restore-SPSite Error: The site collection could not be restored

We have an internal web content authoring environment (http://author.local) which has a number of site collections, each of which is used to create and author content for a different external-facing website i.e. http://author.local/sites/web1, http://author.local/sites/web2. This was causing some issues with relative site paths when publishing i.e. /sites/web1 internal, but / external so links were breaking that had been hard-coded. A notable example was we had set a different search results page via site settings, and this broke when using the site on the published environment.

There are a number of solutions to this, but we felt the easiest way was to create replacement host-header site collections instead i.e. http://author-web1.local/ instead. This lets us create as many site collections as we want while still using the same physical web application http://author.local.

I backed up the site collection http://author.local/sites/web1 using Backup-SPSite, and then tried to restore the site collection using Restore-SPSite via the following:

Restore-SPSite -identity http://author-web1.local -path <physical path> -contentdatabase <contentdb> -hostheaderwebapplication http://author.local/

However I got the following error from powershell:

Restore-SPSite : The site collection could not be restored. If this problem persists, please make sure the content databases are available and have sufficient free space.
At line:1 char:15
+ Restore-SPSite <<<<  -identity http://author-web1.local -path 'C:\site.bak' -contentdatabase MyDb -hostheaderwebapplication http://author.local
+ CategoryInfo          : InvalidData: (Microsoft.Share...dletRestoreSite:
SPCmdletRestoreSite) [Restore-SPSite], SPException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletRestoreS

ULS reported the following error in the log files:

System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'Docs_IdLevelUnique'. Cannot insert duplicate key in object 'dbo.AllDocs'.  The statement has been terminated.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

at System.Data.SqlClient.SqlDataReader.get_MetaData()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)

at Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command, CommandBehavior behavior, SqlQueryData monitoringData, Boo

It turned out that I had a previous site collection from a failed restore attempt before. No problem, I deleted the site collection so there were none in there at all, then tried again. Same result. I checked in the content database, and there were indeed files in the AllDocs tables even though the site collection had been deleted. I went the Big Bang approach and deleted the content database. After creating a new content database, the restore worked perfectly.

My guess at this stage is that I may have been a victim of the site collection recycle bin! SP1 includes the ability to restore deleted sites and site collections via PowerShell, so there may still have been deleted references in the content database. Regardless, it works now. I don’t know how to fix this issue if you only have the one content database, but I always try and split out site collections in host-header web applications to different databases so this didn’t affect me in this case.


5 Responses to “SharePoint 2010 Restore-SPSite Error: The site collection could not be restored”

  1. kurt Says:

    I came accross this too. Creating a new content db was the trick to restore.

  2. Koen Zomers Says:

    Thanks for sharing guys! Ran into the same issue. A bit more details for people running into the same and not knowing how to accomplish this: create a new content database via Central Administation – Application Management – Manage content databases. Select the proper WebApplication at the top right, click into the current content database, check Remove content database, click OK, click Add a content database, click OK and try your Restore-SPSite PowerShell command again.

  3. Theodor Says:

    Hi Guys.
    Relating to the content database creation, this will leave old databases with alot of junk!
    Imagine a site collection of somewhat 10.000.000 records – then this approach won’t be practical.
    You mentioned the scheduler, who looksinto siteDeletion table, where a deleted site has the values 0 and 1 in the values “InDeletion” and “Restorable”. The 1 in Restorable, indicates that the site data is present in collection, but not available in terms of a sitecollection or list, while the actual data in dbo.alldocs are…

    Is there a tool out there, where databases get cleansed from such data with no parent sites or sitecollection?

  4. Lon Feuerhelm Says:

    Perfect. I’ve been pulling my hair out trying to do what you were doing and getting nowhere, read all of the Tech Forum stuff, but this worked perfectly.

  5. Gabriel Serrao Says:

    I solved this just creating a new contentdb. That´s magic! After that, i suggest you move all sites from broked content DB to a new content, using “Get-SPSite -ContentDatabase BrokenContentDb | Move-SPSite -DestinationDatabase NewContentDb2”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: