SharePoint Services 3.0 Command Line Backup Script With 7 Day Full Retention and Email Reporting

This backup script fully backs up your SharePoint Services 3.0 site to a specified location and keeps copies of backups for 7 days. You’ll have to set the variables at the top of the script, then schedule it to run with the windows task scheduler, and then you’re off!

Oh, and you’ll need blat.exe – you can download it directly from me if you like here. OR Google it if you don’t trust me.

location – Location you want your backups to be stored.
blat – Location of blat.exe
relayserver – An email server you have relay access to.
yourserver – Your SharePoint site’s URL.
templog – Temp location logs are stored before being emailed.
file – Name of the SharePoint backup files that will be created.
to – Who the email reports go to.
who – Who the email should come from.
reply – Where email replies should go.

SPBackup.bat

echo blog.integrii.net SharePoint Services 3 7 Day Command Line Backup Script Version 1

set location=d:\sharepoint\backup
set blat=c:\windows\system32\blat.exe
set relayserver=mail.yourrelayserver.com
set yoursite=https://sharepoint.yoursite.com
set emailsub=SharePointBackupReport
set templog=c:\batch\spbackup.txt
set file=Backup.bak
set to=sys-ops@yourdomain.com
set who=sharepointbackup@yourdomain.com
set reply=noreply@yourdomain.com

del %location%\%file%.7day
rename %location%\%file%.6day %file%.7day
rename %location%\%file%.5day %file%.6day
rename %location%\%file%.4day %file%.5day
rename %location%\%file%.3day %file%.4day
rename %location%\%file%.2day %file%.3day
rename %location%\%file%.1day %file%.2day
rename %location%\%file% %file%.1day
“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\Stsadm.exe” -o backup -overwrite -url %yoursite% -backupmethod full -filename %location%\%file% > %templog%
dir %location% >> %templog%
%blat% “%templog%” -t %to% -s “%emailsub%” -i %who% -f “%reply%” -q -server “%relayserver%”

Please comment any problems you have so we can get this baby just right!

3 Responses to “SharePoint Services 3.0 Command Line Backup Script With 7 Day Full Retention and Email Reporting”


  1. 1 Wim

    seems weird that %yoursite% is not defined in the script. I guess this needs to become %yourserver% in the stsadm command line

  2. 2 Eric Greer

    Good catch!

    fixed.

  3. 3 darnitol

    Excellent script – most useful for us sheapskates that can’t see spending hundreds on a lousy backup app that’s harder to use than a horse-drawn plow without the horse.

    I’ve taken the liberty of making some minor improvements, namely locking Sharepoint as readonly so your backup doesn’t get corrupted by someone making changes to the Companyweb while it’s backing up.

    Oh, and I commented it – just in case a new admin has to get involved.

    @echo off

    REM *Set Variables*
    set location=d:\sharepoint\backup
set blat=c:\windows\system32\blat.exe
set relayserver=mail.yourrelayserver.com
set yoursite=https://sharepoint.yoursite.com
set emailsub=SharePointBackupReport
set templog=c:\batch\spbackup.txt
set file=Backup.bak
set to=sys-ops@yourdomain.com
set who=sharepointbackup@yourdomain.com
set reply=noreply@yourdomain.com

    REM *Rename Old Backups and Drop Oldest*
    del %location%\%file%.7day
rename %location%\%file%.6day %file%.7day
rename %location%\%file%.5day %file%.6day
rename %location%\%file%.4day %file%.5day
rename %location%\%file%.3day %file%.4day
rename %location%\%file%.2day %file%.3day
rename %location%\%file%.1day %file%.2day
rename %location%\%file% %file%.1day

    REM *Lock Sharepoint as readonly, create backup, unlock*
    “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\Stsadm.exe” -o setsitelock -url http://server -lock readonly
“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\Stsadm.exe” -o backup -overwrite -url %yoursite% -backupmethod full -filename %location%\%file% > %templog%
    “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\Stsadm.exe” -o setsitelock -url http://server -lock none
dir %location% >> %templog%

    REM *Email backup results*
%blat% “%templog%” -t %to% -s “%emailsub%” -i %who% -f “%reply%” -q -server “%relayserver%”

Leave a Reply