October 22, 2008

The command line backup / restore routine in SharePoint environment whilst good does not offer any scheduling capability. There are of course products providing granular backup (e.g. DOCAVE) but this is geared to corporate site collections. This document describes the GEMBACKUP application, that can facilitiate the backup of the SharePoint environments and how to backup site collections using a tool I wrote that enumerates the sites and creates a backup batch file that can be scheduled using Windows Scheduler.

This tool can be downloaded from here: GemBackup (ZIP).

Note. This tool has been superceeded by the utility that creates a powershell script and has more features. If you are still keen on using GEMbackup then read on, else visit this link.

Overview on Stadm Backup and Restore

By default, personal sites content is contained in the site database of the portal site. You could use the SharePoint Backup and Restore utility to back up the personal sites content, but then you would not be able to restore individual personal sites. Instead, you would have to restore the entire site database. Stsadm.exe can back up and restore individual users’ personal sites, including all subsites, files in document libraries or lists, security and permission settings, and feature settings.

The Stsadm.exe enumsites parameter lists all personal sites that have been created on the portal site. The enumsubwebs parameter lists all subsites within a site collection. Use the enumsites parameter to parse the list of personal sites, and then back up each personal site to a file. The following example shows how to enumerate personal sites on the portal site:

stsadm -o enumsites -url http://yourmysiteurl.org

The following example shows how to use the Stsadm.exe backup parameter to back up an individual personal site:

stsadm.exe -o backup -url http://yourmysiteurl.org -filename “MySite.bak”

To restore a personal site from an Stsadm.exe backup file, use the Stsadm.exe command with the restore parameter. The following example shows how to use the restore parameter to restore a personal site to its original site or another site:

stsadm.exe -o restore –url http://yourmysiteurl.org -filename “MySite.bak” –overwrite

GEMBACKUP simply enumerates the sites, but as a cool trick identifies sites that have been changed that day, that week or full using a supplied parameter and writes stsadm –o backup commands against each site.

Location of Binaries

To use GEMBackup to cover a full backup suite (daily, weekly and full), you need to create three directories on say the root of a Drive (may even be the same drive holding the backup files). For example:




In each, put the following files.

1: GEMBACKUP.exe – This program is the heart of the backup solution. It enumerates the site collections on each web application and writes out a stsadm -o backup line for each of them.

2: Microsoft.Sharepoint.DLL – This is a dynamic link library holding routines accessible from GEMBACKUP.EXE

3: RunDaily.bat OR RunWeekly.bat or RunMonthly.bat – These are stored in the relevant sub directory Daily, Weekly and Monthly and are used to run GEMBackup on a parameter switch. Each of these folders also include copies of GEMBACKUP and Microsoft.Sharepoint.DLL

Stsadm.exe is stored in the 12 HIVE, so you’ll need a path set to that if you have not done so already.

How does it Work

The rest follows the example of running GEMBackup to create batch files on Drive F. We then use Windows Scheduler create jobs to the Initial Batch files, then create three more to run the Secondary Batch files (they would run 30 minutes say after the Initial Batch file).

So, create an initial batch file for the DAILY, WEEKLY and FULL backups in the each of the directories holding GEMBACKUP.exe as follows:


GEMBACKUP -d -f F:\Backups\GEBackup\daily\BackupDayChangedSites.bat


GEMBACKUP -w -f F:\Backups\GEBackup\Weekly\BackupDayChangedSitesWeek.bat


GEMBACKUP -a -f F:\Backups\GEBackup\Full\Fullbackup.bat


Each GEMBACKUP instruction runs with either a -d or -w or -a parameter, put simply:

-d forces the enumeration of sites which have been changed during the day.

-w forces the enumeration of sites which have been changed during the week.

-f forces the enumeration of all sites.

Note that the relevant batch file created by GEMBackup is stored to the f: Drive, but you can target any drive as long as it has access to stsadm.exe


The secondary batch file created by GEMBACKUP is stored on the F: Drive in a directory called gebackup and then relative to the type of backup being done.

For example, the secondary batch file BackupDayChangedSites.bat is stored in the daily subdirectory of gebackup

The initial batch files stored on drive E within the relevant backup types for daily / weekly / full can be scheduled to run say 8pm each night, on say Friday of each week, or the last Friday of each month.

Additionally, the secondary batch files that actually executed the backup are also scheduled in this way, but giving a thirty minute window between the initial batch file run and the secondary batch file run.

For example, the initial batch file RunDaily.bat is scheduled to run every night at 8pm. The secondary batch file BackupDayChangedSites.bat is scheduled to run everynight at 8.30pm. Meaning that the initial batch file is given 30 minutes to complete its job before the secondary batch file runs. By doing this you can ensure that sites updated daily are captured in the secondary batch file (*).

You could indicate each title starting with the word RUN to indicate that the batch file on drive E is executed forcing site enumeration to the backup batch file stored on F.

Note that I have mentioned that there should be a half hour break between the enumeration (initial) and the actual backup (secondary), giving GEMBACKUP ample time to enumerate all the relevant sites requiring backup. If you find that the sites are not backing up it could be because the time lag between enumeration and backup is too short – use Windows Scheduling to correct this.

How to Restore

To restore individual site collections, use the Stsadm.exe tool with the Restore option. There are three options for restoring sites with the Stsadm.exe backup:

To restore a site from a backup file, either to a new site or a separate server, use the Stsadm.exe restore parameter. Use the overwrite parameter to replace any existing site at the new location.

Notes using the stsadm backup command.

Ensure that a content database exists for the restored site collection. You may receive a message when attempting a restore that a content database is required.

To create a new content database, go to the Manage Content Databases page from the Application Management Page. On this page, select Add A Content Database.

Restore a site collection over an existing site

When you overwrite an existing site, all existing site data—including subsites and content—are completely overwritten.

Restore a site collection to a new site on the same server

This is the recommended option for recovering data without overwriting the entire site collection. When you restore a site collection to a new site on the same server, you can copy the data from the restored site collection or subsite back to its original site.

The following example restores a site collection to the original site or to a new site:

stsadm -o restore -url http://yoursiteurl/myexamplesitecollection -filename myexamplesitecollectionbackup.bak –overwrite

Restore a site to a separate server

The separate server must have a separate installation of SharePoint Products and Technologies. This option is more complex and requires additional hardware to purchase and manage. Also, the following settings and configurations of the backup server must match those of the restore server:

What about the Domain?

The user’s domain should be the same. For example, suppose a server is in domain A and you would try to restore on a server in domain B. If domain B and domain A are not connected, the user might not be able to access the site.

What about Solution Packages?

For example, if the Office value pack is installed on the source server but not on the target server, a restored site might not work.

• Any user-added front-end templates, Web Parts, and changes to layouts.

• Any changes made by the user to the IIS metabase.


Am trying to build a great bunch of tools for Sharepoint automation – if you like this tool please donate something – it all goes to keeping me toiling away on those apps and makes me feel its all worthwhile! Please DONATE – thanks!

You May Also Like…