posted 7/13/2011 by BradSchacht - Views: [9654]
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.
A PowerShell command prompt will appear and you need to format the following to fit the backup for your site.
Backup-SPSite -Identity <Site collection name> -Path <backup file> [-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 [ ]
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:\SharePointBackups\BISite\07-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 <Site collection URL> -Path <Backup file> [-DatabaseServer <Database server name>] [-DatabaseName <Content database name>] [-HostHeader <Host header>] [-Force] [-GradualDelete] [-Verbose]
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.