After setting up STSADM.exe to backup my WSS v.3 sites the backup directory did grow daily.
I could not find any way to set some sort of retention on these backups, and got tired of deleting the backups and adjusting the spbrtoc.xml manually. So I wrote my own script.
As a real PowerShell addict this problem had to be solved with PowerShell. Here’s the script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 = "E:\Backup\Sharepoint\spbrtoc.xml" # Days of backup that will be remaining after backup cleanup. $days = 5 # Import the Sharepoint backup report xml file [xml]$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 $sp.Save($spbrtoc) Write-host "Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisk." |
This script does:
- queries the spbrtoc.xml and finds all backups
- deletes old backup entries from spbrtoc.xml
- deletes the old backup files from disc
- saves the updated spbrtoc.xml.
The result:
Just schedule this script to run after the backup has been made and no more manual deletion of the backup files is needed.
As a real IT Pro, you can now put your feet on the table and drink a relaxing cup of coffee. (Well at least until your boss finds you in this way…)