A backup plan is an insurance policy for your data, providing a means to manage the risk of a system failure or human error that results in data loss. In law firms such as mine, Fenwick & West, where Microsoft SharePoint houses valuable content such as documents, wikis and calendars, it’s of paramount importance that we adequately insure against the loss of those information assets.

A SharePoint backup plan needs several elements to provide for complete and flexible recovery. Because firms running SharePoint already own most of the required tools, implementing such a plan need not be costly. However, one element is missing from the out-of-the-box toolkit: automated, site-level backup. In this article, I’ll explain the key components you’ll need for your SharePoint backup plan, and show you (or your SharePoint administrator) how to build and deploy this missing element.

A solid backup plan doesn’t need to be complicated. Backup software vendors would have you believe that only their product can field a robust and reliable backup strategy; that you must shell out a lot of cash, and commit significant system administration resources, in order to protect your SharePoint environment.

In many cases spending your firm’s scarce resources on additional backup technology is unnecessary, as you already own the required software. For a comprehensive backup plan you’ll need file-system and SQL database backups, as well as a means to recover any customizations to your SharePoint environment. You’ll also want site-level backup so you can quickly restore a single site collection if accidentally deleted, or if you want to roll back to a previous version of a site (you’ll find this particularly handy with “My Site“).

Note: Those new to SharePoint may find Microsoft’s nomenclature a bit confusing. In SharePoint, the terms “site” and “site collection” are sometimes used synonymously, other times not. What is true is that the most granular unit that can be backed up using the methods I describe below is a site collection.


Any SharePoint backup plan should include:

1. File system backup of all SharePoint servers, including registry and SharePoint files that may be subject to customization — to rebuild a new Web front-end server in case of hardware or operating system failure;

2. SQL Server backup of content and configuration databases — to restore a working copy of the SharePoint configuration and content databases, or rebuild new SQL Server(s) in case of hardware failure.

If you customize SharePoint by adding features, custom Web parts, graphic or other elements, you’ll also need source control (such as Visual SourceSafe from Microsoft) to allow rollback of errors introduced into your production environment via custom components such as Web parts, Web applications or CAML (XML) configuration files.

To round out your toolkit, I’ll show you how to create a site-level backup to allow you to recover individual site collections in case some unwanted edit needs to be rolled back or a site administrator accidentally deletes the entire site.

How you implement the above components will be determined in large part by the answers to the following two questions:

1. What is the maximum amount of data that you can afford to lose — your “Recovery Point Objective” in disaster recovery terminology?

2. What is the maximum time you can allow for recovery –- your “Recovery Time Objective”?

As the values of RPO and RTO decrease, the cost of your data insurance policy (your backup plan) in terms of software, hardware and human resources tends to increase. Can your firm afford to lose a day’s worth of edits (RPO) to your SharePoint sites and wait for up to four hours to be back online (RTO)? If so, a plan that includes nightly SQL and file system backups and a spare Windows server may suffice. On the other hand, if minutes count, real-time mirroring of data to SQL and SharePoint servers at a remote location may be the right choice.

The point is that there’s no “correct” answer to the question: “What’s the right backup plan for my firm?” The answer will depend on your firm’s needs and budget with respect to the data housed in SharePoint.

What about third-party backup and source control products?

Windows Server and SQL Server both come with functional backup applications at no additional cost, and if you have Visual Studio you already own a source control solution. This raises the question: “When should my firm consider a third-party backup or source control product?”

Dedicated backup products generally go well beyond the basics, and will add the most value in firms with a large number of servers and/or many locations. These products can ease the burden of managing many backup schedules and devices, as well as restoring from those devices.

High-end source control solutions are most appropriate for large and/or dispersed development teams. Smaller teams may do best with the basic source control found in Visual SourceSafe (part of Visual Studio) or with an open source alternative such as CVS.

Only you can decide whether a third-party backup or source control product is right for your firm. Armed with the knowledge that you may already own the necessary tools will put you in the best position to make that determination.


In this section I’ll describe two options for creating an automated site-level backup utility for SharePoint. Both options create one backup file for each site collection on your server which can subsequently be restored using SharePoint’s STSADM command-line utility. There are important differences between these two approaches, however. The first option uses a Windows script that calls the SharePoint STSADM command. This approach has the advantage that it does not require .NET programming, and thus may be more accessible to systems administrators who are comfortable creating script files, but not with developing applications using Visual Studio and C#. The downside of this approach is that it provides limited control over memory use, and thus may not be appropriate for large SharePoint installations.

The second option involves creating a C# application that calls the SharePoint API. While this approach requires a bit more work, it should be quite easy for anyone with access to Visual Studio 2005 or later, and a bit of programming experience. This option also gives you more control over memory use, and so can scale to very large installations.

Note: Both the script created in option No. 1 and the program created in option No. 2 must run from a front-end Web server that is part of your SharePoint farm. To implement either of the following solutions, you will need administrator rights on your SharePoint server.


If you are a SharePoint administrator, you’re probably familiar with the STSADM utility. This is a command-line utility that is installed with SharePoint (either MOSS or WSS), and is typically found in the “c:\program files\common files\microsoft shared\web server extensions\12\bin” folder on any SharePoint server. The STSADM utility supports numerous operations, two of which are BACKUP and RESTORE. The following script can be saved to a file on disk, and run using the Windows command prompt or task scheduler.

‘ ————————————————————–
‘ Purpose: Backup all SharePoint site collections on server
‘ ————————————————————–
Option Explicit

‘ Set the path to the STSADM utility
“C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm”

‘ Set the path to where you want the backups made
Const BACKUP_PATH = “C:\SharePoint_Backups\”

‘ Define needed variables
Dim objFso, objFolder, objFiles, objFile, objShell
Dim objExec, strResult, objXml, objSc, objUrl
Dim strUrl, strFileName, strCmd

‘ Step 1: OPTIONAL: Delete any pre-existing backups
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set objFolder = objFso.GetFolder(BACKUP_PATH)
Set objFiles = objFolder.Files
For Each objFile in objFiles

‘ Step 2: Retrieve all site collections in XML format.
Set objShell = CreateObject(“WScript.Shell”)
Set objExec = objShell.Exec(STSADM_PATH & ” -O ENUMSITES -URL http://localhost/”)
strResult = objExec.StdOut.ReadAll

‘ Load XML in DOM document so it can be processed.
Set objXml = CreateObject(“MSXML2.DOMDocument”)

‘ Step 3: Loop through each site collection and call stsadm.exe to make a backup.
For Each objSc in objXml.DocumentElement.ChildNodes
strUrl = objSc.Attributes.GetNamedItem(“Url”).Text
strFileName = BACKUP_PATH & _
Replace(Replace(strUrl,”/”,”_”),”:”,”") & “.bak”
strCmd = STSADM_PATH & ” -O BACKUP -URL “ ”" & _
strUrl + “”" -FILENAME “”" + strFileName + “”"”

‘ For testing, display pop-up for each collection backed up
WScript.Echo “Backing up site collection ” & _
strUrl & ” to file ” & _
strFileName & ” using the following command ” & _


‘ Optional, if there will be many site collections, may want
‘ to insert a delay to avoid overloading server memory


‘ This function can be used to insert a delay in the processing
‘ to avoid overloading server memory if there are many
‘ site collections to be backed up.
Function GoSleep(seconds)
Dim startTime, endTime, nowTime, dummy
startTime = DateAdd(“s”,0,Now)
endTime = DateAdd(“s”,seconds,Now)
nowTime = DateAdd(“s”,0,Now)
While endTime > nowTime
‘ Need some commands lin while loop to
‘ ensure it actually executes
nowTime = DateAdd(“s”,0,Now)
dummy = Time
End Function

If you save the above script to a file named “Backup.vbs”, you would execute it using the command CSCRIPT BACKUP.VBS.

Running the above command from a command prompt will look something like the following screen shot:

Click image to enlarge
Figure 1: Output from command “cscript backup.vbs” Click image to enlarge.

And, assuming the script is set to write backup files to “C:\SharePoint_Backups,” you should find one or more BAK files in that folder after the script runs.

Click image to enlarge
Figure 2: Directory view of .bak files. Click image to enlarge.


To create the following program you’ll need Microsoft Visual Studio 2005 or later. First create a new C# console application, then paste the code below into the “program.cs” file, add a reference to the Windows SharePoint Services assembly and, finally, click the compile button.

This will result in an executable that you can run from the Windows command prompt or the task scheduler. Note that if the SharePoint Web application you want to back up is on a non-standard port, or uses a host header, you will want to change the reference to http://localhost in the line site = new SPSite(“http://localhost”);.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Data;
using System.Configuration;

namespace SharePointBackup
class SharePointBackup
const int DAYS_BACK = 365;