SharePoint 2013 backup and restore using PowerShell

In this SharePoint tutorial, we will discuss sharepoint backup and restore, how we can do backup and restore in SharePoint 2016 or SharePoint 2013 backup and restore. How to backup and restore in SharePoint 2013 using PowerShell and also how to backup and restore in SharePoint 2016 using SharePoint Central Administration. We can take a backup of the site collection using PowerShell and also from SharePoint 2016/2013 Central Administration.

We will also see, how to fix an error, Backup-SPSite : The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program.

[toc]

Backup Site Collection using PowerShell in SharePoint 2016/2013

First, we will see how we can take a backup of the SharePoint 2016 site collection using PowerShell. Either you can use Windows PowerShell ISE or you can use SharePoint 2016 Management Shell.

To take backup using PowerShell, run the below command in the SharePoint 2016 / 2013 Management Shell.

Backup-SPSite -Identity http://mypc/sites/MySP2016SiteCollection/ -Path E:\MySiteCollection.bak
sharepoint backup and restore
sharepoint backup and restore

Here http://mypc/sites/MySP2016SiteCollection/ is the Site collection URL. And E:\MySiteCollection.bak is the path of the backup file.

Once the backup done successfully, you can see the .Bak file in the path specified above.

backup restore site collection sharepoint 2013 using central adminstration
backup and restore in sharepoint 2013 using powershell

Backup Site Collection by using SharePoint 2016/2013 Central Administration

We can also take backup of a site collection from central administration. To take the backup through SharePoint 2016/2013 Central Administration. Open SharePoint 2016/2013 central administration, then from Backup and Restore section click on “Perform a site collection backup”.

sharepoint 2013 backup and restore
sharepoint 2013 backup and restore

In the next page, select the Site Collection URL and then give the file name with path in the File Location box. Then click on Start Backup.

backup and restore in sharepoint 2013 using powershell
backup and restore in sharepoint 2013 using central admin

Restore site collection using PowerShell:

We can only restore site collection by using PowerShell only in SharePoint. We do not have the option available to restore a site collection through central administration.

Open SharePoint 2016/2013 Management Shell and execute the below command:

Restore-SPSite -Identity <SiteCollectionURL> -Path <Backup file> [-DatabaseServer <DatabaseServerName>] [-DatabaseName <ContentDatabaseName>]

If you want to restore the site collection to a specific content database, use the DatabaseServer and DatabaseName parameters to specify the content database. If you do not specify a content database, the site collection will be restored to a content database chosen by SharePoint 2013.

Example:

Restore-SPSite -Identity http://win-pfcp2dgt8di/sites/MyNewSiteColURL/ -Path E:\MySiteCollection.bak

Example-1:

Restore-SPSite -Identity http://win-pfcp2dgt8di/sites/MyNewSiteColURL/ -Path E:\MySiteCollection.bak -DatabaseServer WIN-PFCP2DGT8DI -DatabaseName WSS_Content_New

Export Import Sub Site using PowerShell in SharePoint 2016/2013

We can export and import a subsite in SharePoint 2016/2013 using PowerShell. By using Backup and Restore you can backup and restore site collection not a subsite. We can use the Export and Import command to export and import a particular subsite or a list or document library.

Below is PowerShell command to take backup of a sub site:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Export-SPWeb http://win-pfcp2dgt8di/sites/EnjoySharePoint/MyTestSubSite/ -Path "E:\Bijaya\MyTestSubSite.cmp" -IncludeVersions All

Below is the PowerShell command to import a sub site.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Import-SPWeb http://win-pfcp2dgt8di/sites/EnjoySharePoint/SPSubSite/ -Path "E:\Bijaya\MyTestSubSite.cmp" -UpdateVersions overwrite

Backup-SPSite : The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program

Recently I was working on a SharePoint backup and restore functionalities. When I was trying to take sharepoint site collection backup using PowerShell I got the below error which says:

Backup-SPSite : The term ‘Backup-SPSite’ is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ Backup-SPSite -Identity http://mypc/sites/MySP2016SiteCollection/ -Path E:\MySit …
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Backup-SPSite:String) [], CommandNotFound
Exception
+ FullyQualifiedErrorId : CommandNotFoundException

You can take the backup using PowerShell or also you can take backup of site collection from SharePoint 2016 central administration. Here I was trying with PowerShell and I was writing the PowerShell script in a Windows PowerShell ISE. You can also write, debug and execute the powershell script using visual studio code.

The error looks like below:

The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program
The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program

Backup-SPSite : The term ‘Backup-SPSite’ is not recognized as the name of a cmdlet, function, script file, or operable program

The best way is you can use “SharePoint 2016 management shell” and run the Backup script. The error will not come.

But if you are using Windows PowerShell ISE, then you can add the below line at the beginning to load Microsoft.SharePoint.dll.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

Or also you can use the below line which will run even if the PSSnapin already loaded.

Add-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue

So the full script will be like below:

Add-PSSnapin “Microsoft.SharePoint.Powershell”
Backup-SPSite -Identity http://mypc/sites/MySP2016SiteCollection/ -Path E:\MySiteCollection.bak

Backup-SPSite : The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program
Backup-SPSite : The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program

After you execute this, the error will not come.

This is how to fix error, the term ‘backup-spsite’ is not recognized as the name of a cmdlet.

Read some PowerShell tutorials:

In this SharePoint tutorial, we learned SharePoint backup and restore.

  • Backup Site Collection using PowerShell in SharePoint 2016/2013
  • Backup Site Collection by using SharePoint 2016/2013 Central Administration
  • Restore site collection using PowerShell
  • Export Import Sub Site using PowerShell in SharePoint 2016/2013
  • Backup-SPSite : The term Backup-SPSite is not recognized as the name of a cmdlet function script file or operable program
>