Friday, April 22, 2011

Powershell script to Backup SharePoint 2010 Farm and Site Collections

To start a full farm backup,
Backup-SPFarm -BackupMethod Full -Directory "Destination-Directory"
-BackupThreads 5

When the above command is executed, a full farm backup will be performed with
five threads to perform the backup. You can specify up to 10 threads. However,
the fewer the backup threads, the easier it is to read the backup log file. You can
also specify "Differential" as the backup method to perform differential backup of
SharePoint farm. By default, this does not show the progress of backup
operation.

To see the progress as backup is performed:
Backup-SPFarm -BackupMethod Full -Directory "Destination-Directory"
-BackupThreads 5 –Verbose

To see a list of all items included in backup:
Backup-SPFarm –ShowTree

To perform a site collection backup:
Backup-SPSite -Identity "http://SharePointFix:101/" -Path "Path to Backup
file"

To perform on site collection backup using SQL snapshots:
Backup-SPSite -Identity "http://SharePointFix:101/" -Path "Path to Backup
file" –UseSqlSnapShot

There is no option in the central administration to perform backup using SQL
snapshots. This can be done using PowerShell only. Also, using SQL Snapshots
is the recommended way to perform a site collection backup. This will allow users
to continue to read / write site collection content while the backup is in progress.

References: Knowledge Base article from http://www.powergui.org/

3 comments:

  1. What if you have several site collections. for expample http://mysite & http://intranet. what command would you use to backup both these sites or even more? Thanks

    ReplyDelete
  2. You would ideally store all the site collection URL's in a string array using the Powershell script and then it would run the above Powershell script commands iteratively.

    ReplyDelete
  3. If all the sites are in the same web application you could just iterate through them without having to explicitly provide a list.

    $webapp = Get-SPWebApplication -Identity $guid
    $backupPath = "D:\Backups"

    foreach ($site in $webApp.Sites) {
    Backup-SPSite -Identity $site.Url -Path $backupPath
    }

    ReplyDelete