Pages

Friday, June 20, 2014

Beware of Restore-SPSite Requirements

 

Overview

You have SharePoint 2010/2013 Farm deployed. In the same SharePoint Farm, you are trying to back up a site collection and restore on to either a different site URL or managed path or different web application. You are doing this using following PowerShell commands:

  • Backup-SPSite
  • Restore-SPSite

Meanwhile in the process, your Backup-SPSite will work successfully, but while executing the Restore-SPSite you might get following errors:

  1. 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
  2. Restore-SPSite : Access is denied. (Exception from HBESULT: 0x80070005 ( E_ACCESSDENIED))

Cause

Condition for Site Restore

  • When you back up a site collection and restore within the same Web Application, you will need a separate Content Database to restore to. Refer this MSDN Article. Same site collection (will have same SiteID GUID)

If a site collection is backed up and restored to a different URL location within the same Web application, an additional content database must be available to hold the restored copy of the site collection.

Condition for Site Delete

  • Now if you are backing and restoring to be served from different URL, then you are looking at deleting the site collection before you are restoring the site collection. Starting in SharePoint 2010, the Site Collection deletion process has been changed. Refer to Bill Baer's blog here.

Condition for Site Restore

  • When you are set with above conditions and trying to restore site collection now you are greeted with the Access Denied warning.
  • This happens when the user login you are using to login to the SharePoint Server (RDP), this is usually the Farm Admin, is not one of the restoring site collection primary or secondary administrator.

Resolution

  1. You are going to be performing this operation on the SharePoint Server, using the Farm Administrator account.
  2. Your current site collection owner is not the farm admin.
    1. In this case, set your farm admin as Primary/Secondary administrator (This will be temporary until your restore operation is complete)
    2. If you did not do this and went ahead and already deleted the site collection and you have no back up, still no worries, follow further steps.
    3. But at least know who is the Primary or Secondary site collection administrator.
  3. Backup your site collection using the Backup-SPSite.
  4. If you need to delete the site collection because you are trying to move the site collection, then you will need to delete the backed up site collection from SharePoint.
    1. So before you go ahead and delete, ensure you have backed up the Content Database that contains this site collection.
    2. If you delete site collection using Remove-SPSite, the site collection will be deleted permanently.
    3. If you delete site collection from the Central Administration or using Remove-SPSite with -GradualDelete option the site collection will be marked for deletion, and will be deleted based on the timer job "Gradual Site Delete".
      1. You could list the sites marked for deletion by running Get-SPDeletedSite and follow with Remove-SPSite
      2. You could force the timer job Run Now to delete pending the site collection that are marked for deletion.
    4. At this stage you site is removed successfully.
  5. Now you are trying to restore your site collection.
    1. Use Restore-SPSite PowerShell command to restore.
    2. If you are coming across the Access Denied error, that means your Site Collection Primary or Secondary owner is not one of the Farm Admin.
    3. In that case, ( If you did not rest the site collection Primary or secondary admin to the Farm admin before the backup), follow below option:
      1. Find out who was the primary/secondary site collection administrator is
      2. Temporarily, make the above site collection administrator a farm admin, provide rights (I gave full rights until Restore was successful) to the restoring Content Database.
      3. Have the site collection administrator Login to the SharePoint Server farm (This is the only way, because you did not reset the site collection owner to farm admin before the backup)
      4. Then run the Restore-SPSite.
      5. Now remove the user from farm admin and remove the SQL Full rights on the content database.
      6. If you had the Site collection administrator reset to Farm admin prior to back up, then set the appropriate business users to the site collection administrators.

No comments: