Full backup of Moss with Cleanup of older backups

I was facing an issue recently with one of my moss servers that was filling up my backup location disk space with the full backups of MOSS. Apparently you can use stsadm to create a full backup to a UNC path, but there isn’t an option to cleanup those backups. Shame on you Microsoft [:D]. The only corrext way to cleanup the backup is to manually edit the spbrtoc.xml file on your backup location and remove the backup files manually after that.

Being an Administrator for all sorts of systems, I really love to automate such tasks and my make life a lot easier.

 So here is what you need to do to have full MOSS backups and have a cleanup of older backups.

On the server where you want to run the backup (any one of your moss servers) do the following:

1. Download and install Powershell (if not installed already [H])

2. start powershell in a command prompt: type powershell.exe

3. Execute the command: Set-ExecutionPolicy Unrestricted. This will enable you to run unsigned ps1 scripts. unless you are a guru in powershell and know how to sign your scripts with a certificate and all.

4. Create a new text file with notepad, paste the following adn save the file to a location like C:\backup\cleanbackups.ps1:

# Clean-up (old) backup files created by WSS v3 (STSADM.EXE)
# Created by Marco
# Tested with PowerShell RTM v1.0

# Location of spbrtoc.xml
$spbrtoc = “\\server1\backup\Sharepoint\spbrtoc.xml”

# Days of backup that will be remaining after backup cleanup.
$days = 14

# Import the Sharepoint backup report xml file
$sp = gc $spbrtoc

# Find the old backups in spbrtoc.xml
$old = $sp.SPBackupRestoreHistory.SPHistoryObject | ? { $_.SPStartTime -lt ((get-date).adddays(-$days)) }
if ($old -eq $Null) { write-host “No reports of backups older than $days days found in spbrtoc.xml.`nspbrtoc.xml isn’t changed and no files are removed.`n” ; break}

# Delete the old backups from the Sharepoint backup report xml file
$old | % { $sp.SPBackupRestoreHistory.RemoveChild($_) }

# Delete the physical folders in which the old backups were located
$old | % { Remove-Item $_.SPBackupDirectory -Recurse }

# Save the new Sharepoint backup report xml file
Write-host “Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisc.”

 I found this script on the follwing link: http://blog.wauwwie.nl/Lists/Categories/Category.aspx?Name=MOSS%202007%20%2F%20WSS%20v.3

5. Now create a batch file on your moss system with the following commands:

stadm -o backup -directory \\server1\backup -backupmethod full -quiet
powershell.exe C:\backup\cleanbackups.ps1

Save the file and schedule it.

And there you have it.

3 thoughts on “Full backup of Moss with Cleanup of older backups

  1. Thanks for this, not using it on the machine itself but was great to tidy our backup folder down (200 + days worth of backups!!)


  2. Thank You, you can improved a bit to write an event to event log and send a mail to the admin

    well done to you and the original writer

Leave a Reply

Your email address will not be published. Required fields are marked *