Thursday, July 29, 2010

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 Files\Common Files\Microsoft Shared\web server extensions\12\BIN
@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 \\ServerName\ShareName\Backup_ %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.

No comments:

Post a Comment