Thursday 20 February 2014

Powershell Backup/Restore site colections

Backup-SPSite

Backup-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]
·         Identity - Specifies the URL or GUID of the site collection to be backed up.
For example, a valid URL, such as http://server_name/sites/site_name or a GUID such as, "01234567-89ab-cdef-0123-456789abcdef".
·         Path - Specifies the full path to the backup file (that is, C:\Backup\site_name.bak.
·         Force - Specify to overwrite an existing backup file if it already exists.
·         NoSiteLock - Specifies the site collection to remain read and write during the backup.
If the NoSiteLock parameter is not specified, then a site collection that has a site collection lock setting of "none" or "no additions" will be temporarily set to "read only" while the site collection backup is performed. Once the backup has completed, the site collection lock will return to its original state. The backup package will record the original site collection lock state so that it is restored to that state.
If users are writing to the site collection while the site collection is being backed up, then the NoSiteLockparameter is not recommended for potential impact to backup integrity, it means if someone changes content on the site while the backup is being created and according to Microsoft “might lead to possible data corruption”
·         UseSqlSnapshot - 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.

Example

Backup-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
Get-SPSiteAdministration http://server_name/sites/site_name | Backup-SPSite -Path C:\Backup\site_name.bak
Backup-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak -UseSqlSnapshot
 

Restore-SPSite

Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-ContentDatabase ContentDatabaseNameHere] [-Force] [-GradualDelete] [-HostHeaderWebApplication HostHeaderHere]
·         ContentDatabase - Specifies the SQL Server content database where the site collection data will be stored. If no content database is specified, the content database with the greatest unused site collection capacity and whose database status is ready will be used.
·         Force - Specifies that the existing site collection at the URL location is to be overwritten by this restoration.
·         GradualDelete - Specifies that the site collection being overwritten with the Force parameter should be gradually deleted over time by a timer job instead of all at once, which reduces its impact on SharePoint 2010 Products and SQL Server performance. This option is recommended for large site collections.
·         HostHeaderWebApplication - A valid URL assigned to the Web application by using alternate access mapping, such as http://server_name.
Restores a site collection as a host-named site collection instead of a path-based site collection. When the HostHeaderWebApplicationparameter is present, the value of the Identityparameter is the URL of the host-named site collection and the value of theHostHeaderWebApplication parameter is the URL of the Web application that will hold the host-named site collection.
Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-DatabaseServer DatabaseServerNameHere] [-DatabaseName ContentDatabaseNameHere] [-HostHeaderWebApplication  HostHeaderHere] [-Force] [-GradualDelete] [-Verbose]
 
·         DatabaseServer - Specifies the name of the SQL Server containing the content database specified by the DatabaseNameparameter.
The type must be a valid database server name, in the form SQLBE1 and needs to be used in conjunction with the DatabaseName parameter.
·         DatabaseName - Specifies the SQL Server content database where the site collection data will be stored.
 If no content database is specified, the content database with the greatest unused site collection capacity and whose database status is ready will be used.
The type must be a valid database name, in the form SQLDB1.
·         Force - Specifies that the existing site collection at the URL location is to be overwritten by this restoration.
·         GradualDelete - Specifies that the site collection being overwritten with the Force parameter should be gradually deleted over time by a timer job instead of all at once, which reduces its impact on SharePoint 2010 Products and SQL Server performance. This option is recommended for large site collections.
·         HostHeaderWebApplication - A valid URL assigned to the Web application by using alternate access mapping, such as http://server_name.
Restores a site collection as a host-named site collection instead of a path-based site collection. When the HostHeaderWebApplicationparameter is present, the value of the Identityparameter is the URL of the host-named site collection and the value of theHostHeaderWebApplication parameter is the URL of the Web application that will hold the host-named site collection.

Example

Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
Restore-SPSite http://www.example.com -Path \\file_server\share\site_name.bak -HostHeaderWebApplication http://server_name

 

No comments:

Post a Comment