Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Wednesday, December 14, 2011

Scheduling SharePoint site backup using stsadm command and batch file

Following stsadm command can be used to take the backup of sharepoint website as a .dat file:
STSADM -o backup -url “http://SiteURL” -filename “C:\SiteBackup.dat"
The above stsadm command takes a backup of only one site collection represented by "http://siteurl".
Recently I worked in a small SharePoint portal which had only one site collection. But there was no database team to take the backup of database. So I needed to take the backup of SharePoint portal some how and schedule it to excute thrice a day automatically.
To achieve the above requirement, I had created a batch file which performs following tasks:
  1. It takes the backup of specified SharePoint site using STSADM command and stores the backup file (.dat file) into the specified directory on the SharePoint server. It follows the naming convention for backup file as "SiteBackup_Date_Time.dat" where Date and Time will be current date & time.
  2. After that it copies the same site backup file into a remote file server "\\RemoteFileServer\SharePoint\Site Backup".
Following is the complete code of the batch file "SharePointBackup.bat":
@ECHO OFF
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm.exe"
for /F "tokens=1-4 delims=/- " %%A in ('date/T') do set DATE=%%B%%C%%D
for /F "tokens=1-4 delims=:., " %%a in ('time/T') do set TIME=%%a%%b%%c
echo Backup Operation Started....
%STSADM% -o backup -url http://siteurl -filename "F:\SharePoint\Site Backup\SiteBackup_%DATE%_%TIME%.dat"
echo Copying Backup File to Remote File Server....
xcopy "F:\SharePoint\Site Backup\SiteBackup_%DATE%_%TIME%.dat" "\\RemoteFileServer\SharePoint\Site Backup"
echo Copying Backup File Completed.
:End
Another requirement was to schedule the SharePoint site's backup to execute thrice a day automatically. To achieve this, I had scheduled this batch file to execute thrice a day using Windows Task Scheduler. To open the Windows Task Scheduler click on "Start -> Settings -> Control Panel -> Scheduled Tasks".

No comments:

Post a Comment