Software Engineer

My photo
Colombo, Sri Lanka
B.Sc.Special(Hons)in IT, MCTS, MCPD, MCP

Thursday, May 23, 2013

Schedule a Site Collection Backup with a PowerShell Script - SharePoint 2010

I will demonstrate how to back up a SharePoint 2010 site collection automatically through the use of a Power-Shell script. My challenge is How can I backup a SharePoint 2010 site collection automatically on a regular basis?

Here is the solution.

Step 1.

  First setup a backup location. It can be "C:\Backup\MySite" or a shared location like
  "\\MYPC\Backup"

Step 2.

  Then, 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 3.

Download this Power-Shell script for backing up a site collection and change the values according to your environment. Replace "$mySite" with your site collection URL and "$backupLocation" with your backup location. My script name is "BackupSite.ps1".

Download "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 4.

Download the batch file to run the script from following link. (To create a batch file, open a notepad, add these lines and then save it with ".bat" extension)
Download "RunBackup.bat"

Step 5.
 
Copy both the script and batch file to a folder on the SharePoint Server.

Step 6.

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 for your convenience.

Notes:
  • 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.

No comments:

Post a Comment