Last week a colleague of mine was attempting to perform a site collection backup and restore using PowerShell so he could move a site collection to a different web application.  We’ve been able to do this successfully with other site collections before without issues, so we were a bit stumped when all of a sudden he encountered this error message:

Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully. No content databases in the web application were available to store your site collection. The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection. Create another content database for the Web application and then try the operation again.

Most of the time SharePoint error messages tend to be either very cryptic or so generic as to not offer any help.  In this case, however, the message does prove to be useful.  “The existing content databases … may already contain a copy of this site collection.”  It turns out that my colleague had indeed tried to perform the backup/restore to the same web application at an earlier time; however, there was not enough disk space so it failed and he deleted the site collection.  Evidently there were still some traces left in the content database even though he deleted it.  This is what is known as an orphaned site.

I found two excellent posts that helped me in troubleshooting and resolving this issue.  The first one is: How to Remove Corrupted SharePoint Sites – Preparing for SharePoint 2010 Upgrade.  A very useful article on exactly how to identify orphaned or corrupted sites by enumerating all the site collections, and then how to actually delete all traces of the site in question using STSADM (yes I realize that STSADM is deprecated but I wasn’t able to quickly find a PowerShell-equivalent during my hasty search, and to be honest this still works so I used it).

The other article that was very useful:  Running stsadm -o preupgradecheck.  I was having an issue locating the site id of the ophaned site in question because we have so many site collections in our web app that my command prompt window was cutting many of them out of the display area.  This post explains how to run the command but save the output to a file so you can view all the site collections.

Solution

Following are exactly the steps I took to solve this issue:

  1.  Open a command prompt and navigate to c:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14Bin”
  2. Type “stsadm -o enumallwebs -databasename [content db] > output.xml 2>&1”   (replace [content db] with the name of your content database)
  3. Open the file that was generated in step 2 called “output.xml” (located in Bin directory); analyze the file until you find the URL of the site collection that was deleted.  Note the “site id” GUID – you will need this in next step
  4. Type “stsadm -o deleteweb -url [URL name] -siteid [site id from step 3] -databaseserver [database server name] -databasename [database content db]
  5. Run the restore again – SUCCESS!!
(Visited 275 time, 1 visit today)