You have seen backup and restore activity of list in SharePoint 2013 of part 1. In this post you will learn how to take backup of the site and site collection and restore it to a different site or site collection using various options.
To take the backup of the site we can below options.
Go to [site settings] [site actions]
Click on Save site as template.
Fill the details shown in the below screen
And click on ok.
It will be stored in [Solutions] solution Gallery under [web designer gallery].
Select the solution that is saved and activate it.
When you try to create a site, you can create by selecting the custom tab and you will see the site template which you have activated.
You can Save site as template using powershell as well.
#Example of using SaveAsTemplate of Get-SPWeb method
$Web=Get-SPWeb https://www.sharepoint-journey.com:19081/ $Web.SaveAsTemplate("Template Name","Template Title","Template Description",1)
Once you run the above command the template will get saved in solutions gallery.
Note: If there are any dependency features on that site then you will get below error.
So you have find the feature details based on the above error and try to activate in site collection where you want to create the site based on a site template.
Use the tool developed by Serge Luca.
To find more details about correlation ID, Please check here.
Once you find the feature, you can activate using below powershell command.
#Example of Activating the Feature on site
Enable-SPFeature –identity V2VPublishedLinks -URL https://www.sharepoint-journey.com/Restore-Tutorials
You can use below powershell commands to perform backup and restore commands.
#Using export-spweb command
export-spweb -identity "< URL > -path < Path >
<URL> URL is site url which you want to take the backup.
<path> physical file path where you need to save the backup file.
#Example of using export-spweb to take the backup of site
export-spweb -identity "https://www.sharepoint-journey.com/Tutorials" -path "E:\SharePointBackups\Tutorials.cmp"
Before importing the site you need to make sure you have the same template for both the sites otherwise you will get below error.
To avoid that you can check the template Id using below powershell script.
#Example of getting web template Name and Id details
$web = Get-SPWeb "https://www.sharepoint-journey.com/Restore-Tutorials" write-host "Web Template:" $web.WebTemplate " | Web Template ID:" $web.WebTemplateId
Once you know the Site Template details you need to create a site based on that template.
#Example of creating site
New-SPWeb "https://www.sharepoint-journey.com/Restore-Tutorials" -Template "SPSTOPIC"
The above command works fine if the Template is available, but few cases it will not available so it does not get created.
It will give below message if a template is not available.
Warning " Template is not found and it's not applied."
If you try to open the site which you created, it will ask for template selection.
The site which you try to create using above powershell command will show under custom template section, so you can choose that one.
This happens where the site is getting migrated from SPS 2003 to MOSS 2007 and then from MOSS 2007 to SP 2010.
Finally after resolving all the issue you can run the below command to perform the restore operation.
#Using import-spweb command
import-spweb -identity "< URL > -path < Path >
<URL> URL is site url where you want to restore the backup.
<path> physical file path where you have saved the backup file.
#Example of using import-spweb to restore site
import-spweb -identity "https://www.sharepoint-journey.com/Restore-Tutorials" -path "E:\SharePointBackups\Tutorials.cmp"
#Example of Back up site collection
backup-spsite -identity https://www.sharepoint-journey.com/sites/Tutorials -path E:\SharePointBackups\Tutorials.bak
#Example of Restore site collection
Restore-spsite -identity https://www.sharepoint-journey.com/sites/Restore-Tutorials -path E:\SharePointBackups\Tutorials.bak
In this article we have seen how to take backup and restore site and site collection using powershell.
It helps to resolve the issues we get while creating a site using save site as template, export and import site.
You can check the List import and export here in Part 1.
Devendra Velegandla is a five-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2019) for Office Apps and Services, Office Servers and Services MVP and SharePoint Server. He received the MCC award for his contributions in Microsoft MSDN/TechNet forums. He loves sharing articles, videos, and tutorial on SharePoint and Office 365.