One of the most annoying processes with SharePoint is backing up a site collection. There is a build in tool that you can use but it is kinda clunky and can take a while to perform the backup. I used it once and was not impressed. PowerShell provides a quick and easy way to do site collection backups. My favorite part is that you can do the entire backup with one, uno, un, 1 (that’s all I know for the number one so… yeah) line of code. Just a little something to be careful of, you need to use the Windows SharePoint 2010 Management Shell, not the regular Windows PowerShell. I spent about 15 minutes trying to figure out why it (Windows PowerShell) didn’t think that Backup-SPSite was a valid command. Here are the steps you should take. Note that doing the backup will put your site into a read only mode.
- Click Start
- Go to All Programs
- Go to Microsoft SharePoint 2010 Products
- Open SharePoint 2010 Management Shell
A PowerShell command prompt will appear and you need to format the following to fit the backup for your site.
Backup-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]
I recommend creating a folder where you can place these backups before starting the backup process so they aren’t just chillin on the C: drive of your SharePoint server; just a thought. Here is a little explanation of those additional parameters that are inside the braces [ ]
- Force – Include this if you want to override a backup with the same name
- NoSiteLock – Will prevent the site from going to Read Only mode while the backup is being taken. A small warning, if someone changes content on the site while the backup is being created and according to Microsoft “might lead to possible data corruption”
- UseSQLSnapshot – A database snapshot will be taken before the backup begins and the backup will be done off the snapshot. The advantage is that changes can be made to the site while the backup process is running without fear of corruption. The snapshot will be deleted automatically when the backup is completed. You don’t need to specify the -NoSiteLock parameter when using this method
Here is a simple example of what the script may look like if you want to just do a backup:
Backup-SPSite -Identity http://servername/sites/BISite -Path D:SharePointBackupsBISite 7-13-2011.bak
To do site restores the syntax is almost just as easy. You will need to use the same SharePoint 2010 Management Shell as doing the backup.
Restore-SPSite -Identity SiteCollectionURLHere -Path BackupFilePathHere [-DatabaseServer DatabaseServerNameHere] [-DatabaseName ContentDatabaseNameHere] [-HostHeader HostHeaderHere] [-Force] [-GradualDelete] [-Verbose]
- DatabaseServer – Specify the server for the content database
- DatabaseName – Specify the name of the content database
- HostHeader – URL of the Web application that will hold the host-named site collection
- Force – Overwrite the site collection if it exists
- GradualDelete – Recommended for site collections over 1 Gig in size, existing data is marked as deleted and gradually removed over time by a job rather than all at once to reduce the performance hit of deleting large amounts of data
Hopefully this will save you some time and a headaches as it did me! As much as I don’t like coding and I stay away from PowerShell, I will admit, it is a huge time saver and super easy in the SharePoint site collection backup/restore world.
[…] a little out of the ordinary… I am posting about PowerShell. I have done one previously about Backing up and restoring site collection in SharePoint, so believe me I will admit that it has its place. Well I was onsite with a client today and […]
Thank you for the example. I presume that Windows SharePoint 2010 Management Shell is installed as part of the SP2010 installation?
Also, how simple is it to use that Restore-SPSite to restore to a different farm, so that you can get in to recover just an item/list/document . I generally don’t want to restore an entire site to its original location.
You are correct, it is part of the SharePoint 2010 installation.
The Restore-SPSite command is very simple to use. You are probably better off restoring to a secondary location if all you need is an item or document as you stated. Just restore to a DEV location and pull whatever you need from the site and delete it. Another option may be to just pull the document from the database backup if you have a backup of the content database. But removing contents from there can be a daunting task. Sounds like restore, copy files, delete site is probably the easiest route you will find.
I have some code that will export the contents of the SharePoint content database, I will try to post it this week.It is in the form of an SSIS package.
Hi Bradley – I am trying to retsore site collection ,I tried both Powershell and Stsadm but none worked for me.
The command would throw an error – “The operation that you are attempting to perform cannot be completed successfully. No content databases in the web application were available to store your site collection. The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection. Create another content database for the Web application and then try the operation again”.
Please let me know how to proceed with this.
thanks
Do you have a full install of SharePoint 2010 on that same server? You may need to specify the database using the appropriate parameter on the PowerShell script if the content for the web application is someplace other than the default databases. Are there other SharePoint site collections out there currently or will this be the first? If you are trying to overwrite the same site collection with a backup you will likely need to use the Force command along with the restore script. Hope this helps. Let me know if you continue to run into issues and maybe I could get you to send me a couple screen shots. Thanks for reading!
I actually just ran across this error myself this morning and after fumbling around for a little while I discovered that the content database was full, or in my case only had 20MB of space available and I was restoring a 200MB site collection. So in that case you can either make sure the database can grow beyond the size that it was, or in my case the drive was full and it was a DEV box that I needed the site collection on very quickly for something I was demoing so I created a second content database for the web application in Central Administration. Hope that helps.
[…] site collection can be a pretty easy task. If your interested in how to do that check this blog (Backup and Restore SharePoint 2010 Site Collection With PowerShell) where I explain the process. Unfortunately this is not always a foolproof process as I have […]
bak up worked fr me
check this for your backup and restore using powershell
http://profadmins.com/2012/12/31/backup-and-restore-a-site-collection-in-sharepoint-using-powershell/
where does that actual snapshot get temporarily saved? On the db or on the server performing the script?
hay , it does not backup 14 hive content
thanks. it helped!
Could you please tell what exactly will be deleted in “GradualDelete”
Its work fine in SharePoint 2013 also. Great article. Thanks
[…] Article from: http://bradleyschacht.com/backup-and-restore-sharepoint-2010-site-collection-with-powershell/ […]
HI
I tried and it worked for me.
Thnks..
In SP2013 Site also..
Hi Bradley,
Nice write-up,
you can get regular powershell to access the SharePoint cmdlets that the management shell has access by adding this line to your powershell profile or to your powershell session
add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
Cheers,
this really helped me thanks
Hello Mr. Bradley,
I’m new to sharepoint and i have started learning and working with sharepoint since one week, My problem is i have deleted my top-level site unknowingly form the only site collection of my web application, So can the lost site be restored, I don’t know much about sharepoint, can u please help me to restore my site with simple steps.
Thanks…
In some cases, this method d’ont work
For example, if you try to restore a .bak file from a version n of sharepoit to version n+1 ….
Sharepoint is the very bad software I never seen
[…] Backup and Restore SharePoint 2010 Site Collection with … – One of the most annoying processes with SharePoint is backing up a site collection. There is a build in tool that you can use but it is kinda clunky and can take a …… […]
Madhulika, just restore the SQL database
kjgjgjghkjhghghj
[…] is a little out of the ordinary… I am posting about PowerShell. I have done one previously about Backing up and restoring site collection in SharePoint, so believe me I will admit that it has its place. Well I was onsite with a client today and […]
[…] site collection can be a pretty easy task. If your interested in how to do that check this blog (Backup and Restore SharePoint 2010 Site Collection With PowerShell) where I explain the process. Unfortunately this is not always a foolproof process as I have […]
Hi Bradley, may I know how to cancel the backup job after I have performed the Backup-SPSite command? I need to stop it because I have found the previous site collection backup file. Otherwise it will take > 8hrs for backup process.
great, you give the purpose of all the parameters. Useful, specially when we are working in live environment.
[…] 4. Backup and Restore SharePoint 2010 Site Collection with … […]
[…] 9. Backup and Restore SharePoint 2010 Site Collection with … […]
[…] 9. Backup and Restore SharePoint 2010 Site Collection with … […]