
In this post I discuss how to create a fix for the error that occurs when restoring site collection in SharePoint 2013. That is, when no Content Database in the web application is available to store your site collection.
As a SharePoint developer I came across this situation a couple of times. When we try to delete a corrupted Site Collection and restore the back up of a working site collection SharePoint will give the following error:
We assume that the Site Collection gets deleted immediately as soon as we hit Delete Site Collection from Central Server Administration. Although this is true, the Site Collection’s GUID is still referenced in the Content Database.
SharePoint uses a GUID for each of the objects it uses like Web Application, Site Collection, Site, etc. When a Site Collection is deleted, SharePoint stores the site collection ID along with web application ID and the Content Database ID. Every web application will have a timer job called Gradual Site Delete which runs on a daily basis. This timer job reads the Web Application ID, Content DB ID and the site collection ID for a deleted site collection and then it removes the reference from the content database.
We cannot restore the site collection again until the Timer Job is run. In case we need to restore the site collection immediately, we need to follow the following steps:
- Open Central Server Administration -> Monitoring. Under Timer Jobs click Review Job Definitions. Look for the Timer Job named Gradual Site Delete that is specific to the web application which had the deleted site collection. Click on that job and click Run Now. Make Sure the job runs successfully.
- Now open the SharePoint 2013 Management Shell and type the following cmdlet: Get-SPDeletedSite. This cmdlet gets the list of site collections that were deleted in the last 24 hours. Note the SiteId and type the following cmdlet: Remove-SPDeletedSite –Identity <SiteId>.
- Now you are ready to restore the site collection as the deleted site collection reference is successfully removed from the content database. To restore site collection type the following cmdlet: Restore-SPSite –Identity <Site Collection Url> -Path <Backup Path>
This should solve the problem. If it doesn’t, ensure you follow these steps exactly, or leave a comment below.