SharePoint 2010 PowerShell Backup and Restore

I was asked to make a copy of a Site Collection on the production server and put it on the development server with the subsites and permissions intact. These steps did the trick using these scripts (thanks to Brad Schacht’s Blog for this):

Backup-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]

  • Force – Include this if you want to override a backup with the same name
  • NoSiteLock – Will prevent the site from going to Read Only mode while the backup is being taken. A small warning, if someone changes content on the site while the backup is being created and according to Microsoft “might lead to possible data corruption”
  • UseSQLSnapshot – A database snapshot will be taken before the backup begins and the backup will be done off the snapshot. The advantage is that changes can be made to the site while the backup process is running without fear of corruption. The snapshot will be deleted automatically when the backup is completed. You don’t need to specify the -NoSiteLock parameter when using this method

Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-DatabaseServer DatabaseServerNameHere] [-DatabaseName ContentDatabaseNameHere] [-HostHeader HostHeaderHere] [-Force] [-GradualDelete] [-Verbose]

  • DatabaseServer – Specify the server for the content database
  • DatabaseName – Specify the name of the content database
  • HostHeader – URL of the Web application that will hold the host-named site collection
  • Force – Overwrite the site collection if it exists
  • GradualDelete – Recommended for site collections over 1 Gig in size, existing data is marked as deleted and gradually removed over time by a job rather than all at once to reduce the performance hit of deleting large amounts of data

—————————————————————————–

  1. To Backup site 
    1. Use Remote Desktop to log into production server
      1. Login with the Service Account (farm admin account that has access to content databases)
    2. Create a folder on the e: drive to put backup file
      1. (Note: it is best practice not to put backup files on the c: drive)
    3. Open ‘SharePoint 2010 Management Shell’
    4. Create backup script in Notepad, then copy and paste it in:

Backup-SPSite -Identity http://yourProductionServer/sites/yourSite
-Path e:\SiteBackups\yourSite.bak
——————————————————————————————

  1. To Restore site
    1. Use Remote Desktop to log into development server
      1. Login with the Service Account (farm admin account that has access to content databases)
    2. Create a folder on the e: drive to put backup file
    3. Copy and paste .bak file from production server Remote Desktop window (e: drive) to development server Remote Desktop window (e: drive)
    4. Open ‘SharePoint 2010 Management Shell’
    5. Create restore script in Notepad, then copy and paste it in:

Restore-SPSite “http://yourDevServer/sites/yourSite”
-Path e:\SiteBackups\yourSite.bak
—————————————————————————–

Note 1: it is best practice to run Backup and Restore scripts after hours because of the site logs, and because the site will be locked (read only) during the backup. Although there are some alternatives available, such as the [-UseSqlSnapshot] and [-NoSiteLock] paramaeters…

Backup-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]

See the Backup-SPSite technet page for details on these parameters.

Note 2: The difference between Backup-SPSite and Export-SPWeb

  1. Workflows are included when you use the Backup_SPSite cmdlet
  2. SPSite targets Site Collection objects
  3. SPWeb targets sites (subsites), list and library objects

Leave a Reply