One of the most important things that all SharePoint users, and especially administrators, should do regularly is back up data. Nevertheless, it is often overlooked many people just because the process might seem to take hours, and we don’t have the time or the inclination to run backups on a regular basis. In recognition of this behavior, what if there was a script for backing up SharePoint data which could be scheduled to run automatically? Now that’s a whole different story! In this post, I will demonstrate how to back up a SharePoint 2010 site collection automatically through the use of a PowerShell script.
How can I backup a SharePoint 2010 site collection automatically on a regular basis?
For the sake of this exercise, I’m going to assume that you already have a backup location setup. Let’s say it’s “C:BackupMySite”.
First, verify that you possess the following permissions:
- SharePoint Farm Administrator.
- Local Server Administrator on all Web servers.
- db_owner permission on the content database.
- Full Control permission on the backup folder.
Step 1: Create a PowerShell script for backing up a site collection (BackupSite.ps1):
Basically, the above script will do the following:
- Assign all the needed information to start backup.
- Try to create a new backup and name the file based on current date.
- If successful, it will write a success message to the log file. Otherwise, it will log the error/exception.
Step 2: Create a batch file to run the script (RunBackup.bat):
Step 3: Copy both the script and batch file to a folder on the SharePoint Server.
Step 4: Run the batch file to start backing up the site collection immediately or use Windows Task Scheduler to schedule it.
I have attached both the script and the batch file at the end of this post for your convenience.
- This method works with both SharePoint 2010 Foundation and Server.
- While performing the backup, the SharePoint site collection will be set to Read-Only to prevent data corruption, so it’s recommended that you run this script during off-peak hours.
re: SharePoint 2010 Cookbook: Backup a Site Collection Automatically with a PowerShell Script
in the Backup-SPSite cmdlet, what does the “-ea Stop” do?