SharePoint PowerShell - BackUps and Restore

SharePoint: PowerShell - BackUps and Restore

Open Windows PowerShell using Run as admin
PC> add-pssnapin Microsoft.sharepoint.powershell

BackUp & Restore in SharePoint 2013

In SharePoint 2013, you can use Windows PowerShell functionality to perform a backup or restore process for the following items:
  • Farm
  • Site collection
  • Configuration database
  • Services
  • List or document


Farm BackUp
Syntax:
Backup-SPFarm -BackupMethod -Directory [-AssignmentCollection ] [-BackupThreads ] [-ConfigurationOnly ] [-Confirm []] [-Force ] [-Item ] [-Percentage ] [-WhatIf []]

Another Syntax(This doesn’t backups actually, it shows the items to be backed up in this command):

Backup-SPFarm -ShowTree [-AssignmentCollection ] [-ConfigurationOnly ] [-Confirm []] [-Item ] [-WhatIf []]

Example:
PS C:\Windows\system32> backup-spfarm -directory \\KSSHRPT01\FarmBackUp -backupmethod full
PS C:\Windows\system32> backup-spfarm -directory \\KSSHRPT01\FarmBackUp -backupmethod full -ConfigurationOnly

*The shared path shall be accessible from all the server. You can use local PC path in case if you have single server farm and have both SP and DB are installed on the same machine.




BackUp a Site collection
Syntax:
Backup-SPSite [-Identity] -Path [-AssignmentCollection ] [-Confirm []] [-Force ] [-NoSiteLock ] [-UseSqlSnapshot ] [-WhatIf []]

PS C:\Users\spadmin> $s = "http://ksshrpt01"
PS C:\Users\spadmin> $pth = "C:\KS\SiteBackUps\Primarysite.bak"
PS C:\Users\spadmin> backup-spsite $s $pth
PS C:\Users\spadmin> backup-spsite $s -path  $pth

Another way to do the same:

PS C:\Users\spadmin> get-spsiteadministration $s | Backup-spsite -path $pth

PS C:\Users\spadmin> backup-spsite $s -path  $pth -usesqlsnapshot -force
This example backs up a site collection using database snapshots to ensure backup integrity.Specifies a SQL Database Snapshot will be created when the backup begins, and all site collection data will be retrieved directly from the database snapshot. This snapshot will be deleted automatically when the backup completes
The UseSqlSnapshot parameter is recommended if the database server hosting your content database supports database snapshots such as SQL Server Enterprise Edition and SQL Server Developer Edition. This is because it will ensure a valid backup while allowing users to continue reading and writing to the site collection during the backup. It is not necessary to specify the NoSiteLock parameter when specifying the UseSqlSnapshot parameter.

PS C:\Windows\system32> backup-spfarm -showtree -item "Microsoft sharepoint foundation web application" -verbose
*Gives the tree path of back procedure, but doesn’t actually backs up the Farm.

PS C:\Windows\system32>Backup-SPFarm -Directory C:\Backup -BackupMethod full -BackupThreads 10 -Force
This example performs a backup of a farm using 10 threads and forces the backup to be saved to the C:\Backup directory even though SharePoint estimates that it does not have sufficient space available.







Backup-SPConfigurationDatabase
Performs a farm-level configuration-only backup.

Syntax:

Backup-SPConfigurationDatabase -Directory [-AssignmentCollection ] [-DatabaseCredentials ] [-DatabaseName ] [-DatabaseServer ] [-Item ]

Backup-SPConfigurationDatabase -ShowTree [-AssignmentCollection ] [-DatabaseCredentials ] [-DatabaseName ] [-DatabaseServer ] [-Item ]


The Backup-SPConfigurationDatabase cmdlet performs a configuration-only backup of the current farm or a configuration-only backup of a separate configuration database which is not attached to the current farm. If you wish to perform a configuration-only backup of the current farm, there is no need to specify the DatabaseServer and DatabaseName parameters. However, using the Backup-SPFarm cmdlet with the ConfigurationOnly parameter is recommended for such a scenario.
An example of a configuration backup is an administrator creates a farm configuration template which then can be applied to other SharePoint farms by performing a restore using the Restore-SPFarm cmdlet.

PS>Backup-SPConfigurationDatabase -DatabaseName SharePoint_Config -DatabaseServer SqlServer1 -Directory \\server\share\Backup -ShowTree

This example displays components that are available for inclusion in a configuration-only backup.

PS>Backup-SPConfigurationDatabase -DatabaseName SharePoint_Config -DatabaseServer SqlServer1 -Directory \\server\share\Backup -Verbose
This example performs a configuration-only backup with verbose output.





Get-SPBackupHistory

Returns a history of backup and restore operations.
The Get-SPBackupHistory cmdlet reads a history of backup and restore operations that have been run. Specifies whether you want to display only the backup history, only the restore history, or all of the history.

Syntax:
Get-SPBackupHistory -Directory [-AssignmentCollection ] [-ShowBackup ] [-ShowRestore ]




PS C:\Windows\system32> Get-SPBackupHistory -Directory \\KSSHRPT01\FarmBackUp

T S Operation ID                         Method    Start Time
- - ------------                         ------    ----------
B Y 3682c4c6-7eb8-4f61-9714-9870e67d9948 Full


PS C:\Windows\system32>


PS C:\Windows\system32>Get-SPBackupHistory -Directory C:\Backup -ShowBackup
This example returns all of the farm backup operations that have been run for the C:\Backup directory.

PS C:\Windows\system32>(Get-SPBackupHistory -Directory C:\Backup -ShowBackup)[0].SelfId | Restore-SPFarm -Directory C:\Backup -RestoreMethod overwrite

This example gets all of the farm backup operations that have been run for the "C:\Backup" directory, finds the most recent backup, and then passes its backup GUID to the Restore-SPFarm cmdlet. The Restore-SPFarm cmdlet will then perform an overwrite restore from that backup package.

Restore-SPFarm
Restores one or more items from a backup.

This cmdlet contains more than one parameter set. You may only use parameters from one parameter set, and you may not combine parameters from different parameter sets. For more information about how to use parameter sets, see Cmdlet Parameter Sets.
The Restore-SPFarm cmdlet restores one or more items from a backup such as an individual database, Web application, or the entire farm. This cmdlet can also be used to apply a farm template to the entire farm.


Syntax:
Restore-SPFarm -Directory -RestoreMethod [-AssignmentCollection ] [-BackupId ] [-ConfigurationOnly ] [-Confirm []] [-FarmCredentials ] [-Force ] [-Item ] [-NewDatabaseServer ] [-Percentage ] [-RestoreThreads ] [-WhatIf []]

Restore-SPFarm -Directory -ShowTree [-AssignmentCollection ] [-BackupId ] [-ConfigurationOnly ] [-Confirm []] [-Item ] [-WhatIf []]

Example:

PS>Restore-SPFarm -Directory \\file_server\share\Backup -BackupId 12345678-90ab-cdef-1234-567890abcdef -RestoreMethod new -ConfigurationOnly

This example restores the configuration settings from the backup package in the \\file_server\share\Backup directory to the farm.

PS>Restore-SPFarm -ShowTree -Directory \\file_server\share\Backup -BackupId 12345678-90ab-cdef-1234-567890abcdef -Item "Microsoft SharePoint Foundation Web Application" -Verbose

This example show which components of the farm would be restored under the Microsoft SharePoint Foundation Web Application node, but does not actually restore them.

PS>Restore-SPFarm -Directory C:\Backup -BackupId 12345678-90ab-cdef-1234-567890abcdef  -RestoreMethod overwrite -RestoreThreads 10 -Force

This example restores a farm by using 10 threads and suppresses the overwrite warning.

Restore-SPSite
Restores a site collection.
The Restore-SPSite cmdlet performs a restoration of the site collection to a location specified by the Identity parameter. A content database may only contain one copy of a site collection. 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.

Example:

PS>Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak

This example restores a site collection from the backup file C:\Backup\site_name.bak to the site collection URL http://server_name/sites/site_name.

PS>Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak -Force -DatabaseServer SQLBE1 -DatabaseName SQLDB1

This example restores a site collection backup from the backup file
C:\Backup\site_name.bak, but overwrites the existing site collection at http://server_name/sites/site_name while specifying that the site collection must be stored in a specific content database.

PS>Restore-SPSite http://www.example.com -Path \\file_server\share\site_name.bak -HostHeaderWebApplication http://server_name

This example restores a site collection backup from the backup file \\file_server\share\site_name.bak to the host-named site collection http://www.example.com on the Web application http://server_name.


Reference: MSDN

Comments

Popular posts from this blog

Visual Studio Build Issue : Build: 0 succeeded or up-to-date, 0 failed, 1 skipped

SharePoint log error "Cannot find site lookup info for request Uri http://"

SharePoint PowerShell to Manage Term Store / Add Terms using PowerShell