Click here to Skip to main content
Click here to Skip to main content

Scheduling STSADM Backup using Windows Task Scheduler

, 13 Feb 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
STSADM can be used effectively with Windows Task Scheduler to schedule periodic/delayed backups.

Introduction

STSADM can be used effectively with Windows Task Scheduler to schedule periodic/delayed backups.

STSADM

STSADM is the powerful built-in command line tool to backup/restore a SharePoint server farm or web application or site collection or a database. This tool has very simple, faster and easy to use commands for backup/restore SharePoint data.

STSADM Backup Syntax

For site collection backup

stsadm -o backup
   -url<URL name>
   -filename<file name>
   [-overwrite]

For catastrophic backup

stsadm -o backup
   -directory<UNC path or local drive>
   -backupmethod<full or differential>
   [-item]<created path from tree>
   [-percentage]<integer between 1 and 100>
   [-backupthreads]<integer between 1 and 10>
   [-showtree]
   [-quiet]

Please refer the following to get more details about the backup syntax

Backup: Stsadm operation (Office SharePoint Server)

Locking Site

The backup process will take a longer time for large site collections. If any changes made to the site collection during the backup process, the backup can become corrupted. The preferred approach would be locking the site collection using the Setsitelock command of STSADM till the backup process is complete. Once the backup process completes, reset the site collection to its default state.

Please refer the following for more information on Setsitelock

Setsitelock: Stsadm operation (Office SharePoint Server)

To get the current access level of the site

stsadm -o getsitelock -url <URL of Site Collection>

To lock the site/changing the site to read-only.

stsadm -o setsitelock -url < URL of Site Collection> -lock readonly

The following steps needs to be done for scheduling a periodic/delayed backup.

Batch File

Create a batch file, use Notepad to enter the below script and save as “Backup_Script.bat”.

This script creates daily backup of a site collection. A new backup file will be created each day and the file name is auto generated concatenating the current system date.

The script does the following

  1. Determine the lock status
  2. Locks the site collection
  3. Creates a file name using current date
  4. Creates backup
  5. Unlock the site collection
@echo off
@echo--------------------------------------------------------
@echo backing up site collection <URL of SiteCollection>
@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 <URL of Site Collection>
stsadm -o setsitelock -url <URL of Site Collection> -lock readonly
@echo Site locked

@Echo Generating File Name using current date
@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 <URL of Site Collection> -filename "C:\Backup\Backup_ All%.bak"
@echo backup completed
@echo off
stsadm -o setsitelock -url <URL of Site Collection> -lock none
@echo Site lock removed

Note: Replace “<URL of Site Collection>” with your site collection URL. Also I’ve used a folder named “C:\Backup” change it to your respective folder.

Windows Scheduled Tasks

Create a new Windows Scheduled Task by navigating Start > Control Panel > Scheduled Tasks > Add Scheduled Task. The following screen shows the Windows Scheduled Task Wizard.

image001.jpg

Click the Browse button and select the backup batch file (Backup_Script.bat). Click on Next to schedule the backup. The screen below shows the available options for scheduling a task.

image002.jpg

Select the convenient time to take the backup. It is better to choose low traffic hours for backing up a site.

image003.jpg

Once the time schedule has been selected, click on Next and supply the credentials to run the task. The account which is used for executing the task should have the Administrative permission. Click Finish to complete the wizard. Now a daily backup has been scheduled, the Task Scheduler will execute the batch file daily at specified time.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zabiullah Sheik Ismail
Architect
India India
Zabiullah SI is working for an MNC in Chennai.
 
Blog : http://zabistop.blogspot.com

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 13 Feb 2009
Article Copyright 2009 by Zabiullah Sheik Ismail
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid