Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

FREE Webcast - Delivering Microsoft SQL Server High Availability on AWS
 

Exporting and Importing SharePoint 2010 Content


By:   |   Read Comments   |   Related Tips: > Sharepoint

Problem

As a SharePoint Administrator, you would often need to deploy content from one site to another. So what are different options available to export the contents of a site, library, or list from SharePoint and to import it back whenever required?

Solution

Granular Backup and Restore functionalities in SharePoint 2010 have grown up tremendously from previous versions. Now you can export sites, libraries, and lists from the Central Administration tool itself.

You can even use new PowerShell cmdlets to script out export and import operations. PowerShell cmdlets are optimized and provide more new features and options than the old STSADM tool.

Exporting a Site, Library or List using Central Administration

The SharePoint 2010 Central Administration UI allows you to export the site, library and list to the file system. Note that to import them back you need to use a PowerShell cmdlet or the STSADM tool. Central Administration does not have provision for importing it back.

Go to START -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Central Administration, on the left side click on Backup and Restore link, then in the detail pane, click on Export a Site or list link under the Granular Backup section as shown below:

central administration

On the next screen you need to select the site collection which contains the site to be exported, and then select the site to export. If you want to export only a specific library or list, select it as well (shown below). For example I am exporting the Shared Documents document library of HR site.

Next you need to specify the location and name of the file to be created and whether you want to overwrite a file with the same name. You can choose to export the associated security with the site which includes users in the site, authors of documents, etc.

You can specify what versions of the documents/list items you want to export, whether to export current versions, last major versions, last major or minor versions or all versions:

central administration

On the Granular Backup Job Status screen, you can see the status of the export operation. This page gets refreshed automatically in every 30 seconds though you can refresh it on-demand by clicking on the Refresh link as shown below (You need to make sure SharePoint 2010 Timer windows service is running before starting the export operation using Central Administration):

central administration

Exporting and Importing a Site, Library, orList using PowerShell cmdlets

The SharePoint 2010 Central Administration UI is not the only way to export a site, library, or list. SharePoint 2010 provides PowerShell cmdlets to export or even to import them back whenever required. You can even script out these operations to run manually or schedule them with the Windows Task Scheduler to make it run on a scheduled basis.

Let's explore these cmdlets in detail.

The Export-SPWeb command is used to export a site, library, or list.

The Import-SPWeb command is used to import them back.

The general syntax of these commands are:

Export-SPWeb [-Identity]

<url of the site to be exported> -Path <location and name of the file to 
	be created after export> [-Force] [-IncludeUserSecurity] [-IncludeVersions <LastMajor 
	| CurrentVersion | LastMajorAndMinor | All>] [-ItemUrl <Any 
	specific item to export, like document library or list>]

Import-SPWeb [-Identity]

<url of the site to be exported> -Path <location and name of the file to 
be imported from> [-Confirm] [-Force] [-IncludeUserSecurity] 
[-UpdateVersions <Append | Overwrite | Ignore>] 

You can use the IncludeUserSecurity parameter to export the associated security with the site, library, or list which includes users in the site, authors of documents and lists, when the document or list was created and modified, etc... and the IncludeVersions parameter to specify which versions of the documents or list items you want to export, whether to export current versions, last major versions, last major or minor versions or all versions, etc.

To launch SharePoint 2010 PowerShell console, go to START -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell and click on it. To export a site, library or list we need to use Export-SPWeb command and specify the location where the exported file will be stored, the URL of the site, library or list. The Force parameter is used to overwrite a file with the same name, if it exists, during export and overwrite a site, library or list with the same name, if it exists, during an import operation.

The first command, given below, will export contents of all the sites of the specified site collection.

The second command will export contents of the specified site only.

The third command will export the content of the Shared Documents library of the specified site (specified with ItemURL parameter).

Export-SPWeb -Identity http://mktaraliw2k8r2:8081 -Path \\MKTARALIW2K8R2\SharePointBackupFolder\PSAllSites.cmp 
-Force 
Export-SPWeb -Identity http://mktaraliw2k8r2:8081/hr -Path \\MKTARALIW2K8R2\SharePointBackupFolder\PSHRSite.cmp -Force
Export-SPWeb -Identity http://mktaraliw2k8r2:8081/hr -Path \\MKTARALIW2K8R2\SharePointBackupFolder\PSSharedDocuments.cmp -ItemURL "Shared Documents" -Force
management shell

The first command, below, will import all the sites available in the exported file to the specified site collection.

The second command will import the contents to the specified site only, in this case the site must exist and the contents will be overwritten.

The third command will import the content of the Shared Documents library of the specified site, in this case the content will be overwritten.

Import-SPWeb -Identity http://mktaraliw2k8r2:8081 -Path \\MKTARALIW2K8R2\SharePointBackupFolder\PSAllSites.cmp 
-Force 
Import-SPWeb -Identity http://mktaraliw2k8r2:8081/hr -Path \\MKTARALIW2K8R2\SharePointBackupFolder\PSHRSite.cmp -Force
IImport-SPWeb -Identity http://mktaraliw2k8r2:8081/hr -Path \\MKTARALIW2K8R2\SharePointBackupFolder\PSSharedDocuments.cmp -Force
management shell

Exporting and Importing site, library or list using STSADM SharePoint Administration tool

STSADM is a SharePoint administrative tool which generally resides in the "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN" folder within the SharePoint 2007 environment and in the "C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN" folder in a SharePoint 2010 environment.

This tool is to be run on the same server of SharePoint by people who are member of Administrators group. In this section we are going to see how this tool can be used to export a site, library or list and import it back when required. These are the general command formats to export a site, library or list and import it back:

stsadm -o Export -URL <url of the site, library or list 
to be exported> -Filename <location and name of the 
file to be created after export> -Quiet -Overwrite
stsadm -o Import -URL <url of the site, library or list imported to> -Filename <location and name of the file to be imported from> -Quiet

The Overwrite switch is required to overwrite a file if it is already existing on the specified location during an export operation whereas the Quiet switch is used to suppress the detail messages generated on the screen during the command execution. Similar to PowerShell cmdlets, you can specify the parameters for including security related detail and all the versions of the documents or lists with the STSADM tool as well. To learn about complete syntax, click here.

The first command, given below, will export the contents of all sites of the specified site collection.

The second command will export the contents of the specified site only.

TThe third command will export the content of the Shared Documents library of the specified site.

stsadm -o Export -URL http://mktaraliw2k8r2:8081 -Filename 
\\MKTARALIW2K8R2\SharePointBackupFolder\STAllSites.cmp -Overwrite 
-Quiet

stsadm -o Export -URL http://mktaraliw2k8r2:8081/hr -Filename \\MKTARALIW2K8R2\SharePointBackupFolder\STHRSite.cmp -Overwrite -Quiet

stsadm -o Export -URL "http://mktaraliw2k8r2:8081/hr/Shared Documents" -Filename \\MKTARALIW2K8R2\SharePointBackupFolder\STSharedDocuments.cmp -Overwrite -Quiet
command prompt

The first command, given below, will import contents of all sites available in the exported file to the specified site collection.

The second command will import the contents to the specified site, and in this case the site must exist and the contents will be overwritten.

The third command will import the content to the specified site and document library, in this case the contents of the specified library will be overwritten.

stsadm -o Import -URL http://mktaraliw2k8r2:8081 -Filename 
\\MKTARALIW2K8R2\SharePointBackupFolder\STAllSites.cmp 
-Quiet

stsadm -o Import -URL http://mktaraliw2k8r2:8081/hr -Filename \\MKTARALIW2K8R2\SharePointBackupFolder\STHRSite.cmp -Quiet

stsadm -o Import -URL "http://mktaraliw2k8r2:8081/hr" -Filename \\MKTARALIW2K8R2\SharePointBackupFolder\STSharedDocuments.cmp -Quiet
command prompt

Notes

  • While you can still use the old STSADM tool to perform content export and import, it is recommended not to use this tool (unless you are forced to use it for backward compatibility) as this tool has been deprecated and provided in SharePoint 2010 only for backward compatibility.
  • The SharePoint 2010 Central Administration UI provides a way to export a site, library or list but not for importing it back. You need to use PowerShell cmdlets or old STSADM tool for importing it back.
  • A log file gets created after an export and import operation (with this name : <specified file name>.export during export and <specified file name>.import during import), which contains all the details about the operation execution.
  • The granular backup/export and restore/import operations are more processing and read-intensive, as it uses Transact-SQL queries as opposed to farm backup.
  • If your SQL Server version supports database snapshot (Enterprise and Developer editions) , it is recommended to use UseSqlSnapshot parameter with Export-SPWeb command for a more consistent backup.
  • Workflows are not included when we export/import contents of sites, libraries, or lists.
Next Steps


Last Update:


next webcast button


next tip button



About the author
MSSQLTips author Arshad Ali Arshad Ali is a SQL and BI Developer focusing on Data Warehousing projects for Microsoft.

View all my tips





Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 


Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



    



Learn more about SQL Server tools