Creating a SharePoint 2007 Backup Strategy using STSADM commands complimented by Windows Scheduled Task (AT) commands 7


Synopsis:

I am on a project where we will have to rely on the out of box (OOB) Backup Strategies from Office SharePoint Server. I am wearing my IT Pro hat, but the developer in me… says when you do something once… Automate it for future use, Blog it so you can remember it….  SO here goes.. There are two flavors of OOB Backup Strategies in Office SharePoint Server 2007:

1. Using Central Administration –> Operations –> Backup and Restore

2. Using STSADM –> – o backup –url [site path] –filename [where to save the file]

The Central Administration route is, in my opinion an ineffective way to do backups if your goal is to be a long term strategy; it is a one-time deal through a wizard with limited options. Certainly if you are in need to do a backup because of a pressing circumstance, this is in-fact a viable option, but outside of that, STSADM provides more flexibility and it may be scripted and scheduled for future recurring operations.

HOW TO: Implementing a Backup Strategy with OOB STSADM commands

STSADM Backup Syntax:
For site collection backup

stsadm -o backup

-url<URL name>

-filename<file name>

[-overwrite]

Things to look out for when using STSADM to perform backups

As your site grows, logically does your content databases, and if you are employing STSADM as the tool for backup, a bi-product of that will be “longer backup times”. If your environment will be taking longer to backup, your risk of someone updating a file/document/asset as you are performing your backup increases; as a result if a backup is in running and a file is open, that backup is at risk of failure. How do we combat that problem? We use yet another STSADM command to lock the Site in effect the database to read-only; we do this with the SiteLock command, there are two in particular, getsitelock and setsitelock see below for the full command syntax.

stsadm -o getsitelock

-url <URL of Site Collection>

 

stsadm -o setsitelock

-url < URL of Site Collection> -lock readonly

 

Automate your Backup Solution

Certainly you can navigate to the SharePoint 12-Hive and execute these commands as a single action; however, a more consistent action is to script the job with error handling and user feedback.

Script your Backup

@echo off
@echo——————————————————–
@echo This script will backup your site: [Your Site Name Here]
@echo——————————————————–
cd Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN
@echo locking site collection before the backup process starts
@echo off

stsadm -o getsitelock -url http://YourSiteCollectionNameHere
stsadm -o setsitelock -url http://YourSiteCollectionNameHere  -lock readonly
@echo site collection is now locked

@Echo Logic to create a new file name daily 
@For /F "tokens=1,2,3 delims=/ " %%A in (‘Date /t’) do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C%%B%%A
)

@echo off

stsadm -o backup -url http://YourSiteCollectionNameHere  -filename ServerNameShareNameBackup_ %All%.bak -overwrite
@echo backup completed
@echo off
stsadm -o setsitelock -url http://YourSiteCollectionNameHere  -lock none
@echo Site lock removed

Save the above to a .bat file in a preferred location.

Automate your Backup

Create a new Windows Scheduled Task by going to Start–> Control Panel –> Scheduled Tasks –> Add Scheduled Task

Follow the wizard and schedule the .bat file created above to run at a frequency of your own choosing.


[1] A complete reference of STSADM commands are located on Jose Barreto’s blog http://blogs.technet.com/josebda/archive/2007/03/22/complete-reference-of-all-stsadm-commands-with-options-in-moss-2007.aspx

[2] Example of creating the filename so it changes daily and thus does not have to overwrite itself. http://www.zorbathegeek.com/153/batch-file-to-append-date-to-file-name.html


Leave a comment

Your email address will not be published. Required fields are marked *

7 thoughts on “Creating a SharePoint 2007 Backup Strategy using STSADM commands complimented by Windows Scheduled Task (AT) commands

    • fabiangwilliams

      Thanks Deanna… I did some research before putting it together, most of which came from Jose Barreto and some bat file helper site… like Hillary says.. “…it takes a village…”

  • WMC

    Is it possible to use the sitelock switches w/ stsadm.exe and [free] WSS3? We’re backing up a large farm w/ stsadm.exe and running into file locking probs when copying the backup to another server via scheduled task. Here’s our .bat file:

    e:
    rmdir /s/q e:backupsspbr0000
    cd e:backups
    del /s/q/f *.*
    c:
    cd C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN
    stsadm.exe -o backup -directory “e:Backups” -backupmethod full

    Thanks for any insight.