How to create a batch file to do automatic backup of SharePoint site?

Suppose you have a SharePoint site with some heavy and important data and you want to take the backup regularly. So instead of manual process you can create a batch file which will automatically take the backup of the mentioned site.

Below is the given script:
Write below code in a notepad and save it as .bat file.

@echo off
@echo This script will backup your site: [Enterprise Management Site]
cd C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN
@echo locking site collection before the backup process starts
@echo off

stsadm -o getsitelock -url http://moss-server:333/
stsadm -o setsitelock -url http://moss-server:333/  -lock readonly
@echo site collection is now locked
@echo off
stsadm -o backup -url http://moss-server:333/  -filename C:RRSbackupautobackup.bak -overwrite @echo backup completed
@echo off
stsadm -o setsitelock -url http://moss-server:333/  -lock none
@echo Site lock removed

Once you ready with your batch file then you can put this batch file in a scheduler and define a time to run this batch file.

Leave a Comment