Automating Site Collection Backups

Here is a useful batch file for automating site collection level backups.  It creates a unique timestamp string and uses it in the name of the backup.

You can easily create a scheduled task to run this every week or every night.  You will still need to go in and clean up old backups.

The STSADM -o backup command can be tweaked to run full farm backups as well.

Copy and paste this into a text file and rename with *.bat extension (remove "pause" command when scheduling as a task)

SET STSADM="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe"@echo off

for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%cfor /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%afor /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%bSET TODAY=%year%%month%%day%

for /f "tokens=1-4 delims=.: " %%i in ("%time%") do set timestr=%%i%%j%%k%%l

SET FULLSTR=%TODAY%%TIMESTR%

SET LOC="D:\moss_backup\sitename_%FULLSTR%.bak"

@echo.@echo Backup file will be named: %LOC%@echo.@echo on

%STSADM% -o backup -url https://siteurl -filename %LOC%

pause