Thanks to the feedback here and a collegue with more vb knowledge than
I have (some potted plants probably know more vb than I do) I ended up
with this:
' Title: BackupCleanUp
' Description: Deletes SharePoint 2007 backups that are older than a
specified
' number of days and then removes the backups from the
backup history.
Dim nNumberOfDays
Dim strTOCFile
Dim dtDeleteDate
SetLocale(1033)
Set objXML = CreateObject("Microsoft.XMLDOM")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objLog = objFS.OpenTextFile("BackupCleanUp.log",8,true)
' Validate command line arguments and initialize data.
If WScript.Arguments.Count = 2 Then
If IsNumeric(WScript.Arguments(0)) Then
nNumberOfDays = CInt(WScript.Arguments(0))
dtDeleteDate = DateAdd("d",nNumberOfDays*-1,Now)
Else
WScript.Echo "<NumberOfDays> must be an integer value."
End If
strTOCFile = WScript.Arguments(1)
Else
WScript.Echo "Usage: BackupCleanUp <NumberOfDays> <PathToTOC>"
WScript.Quit
End If
objLog.WriteLine(Now() &vbTab& "Start: Clean up backups older than "
&nNumberOfDays& " days from " &strTOCFile& ".")
' Load the SharePoint backup and restore the TOC file.
objXML.Async = false
objXML.Load(strTOCFile)
If objXML.ParseError.ErrorCode <> 0 Then
objLog.WriteLine(Now() &vbTab& "Error: Could not load the
SharePoint Backup / Restore History." &vbCrLf&_
Now() &vbTab& "Reason: "
&objXML.ParseError.Reason& ".")
WScript.Quit
End If
' Delete backup nodes that are older than the deletion date.
For Each objNode in objXML.DocumentElement.ChildNodes
If CDate(objNode.SelectSingleNode("SPFinishTime").Text) <
dtDeleteDate Then
If objNode.SelectSingleNode("SPIsBackup").Text = "True" Then
'wscript.echo "Backupdate" &
(objNode.SelectSingleNode("SPFinishTime").Text)
'wscript.echo "Checkdate" & dtDeleteDate
'wscript.echo mid(objNode.SelectSingleNode("SPBackupDirectory").Text,
1,len(objNode.SelectSingleNode("SPBackupDirectory").Text)-1)
objFS.DeleteFolder(mid(objNode.SelectSingleNode("SPBackupDirectory").Text,
1,len(objNode.SelectSingleNode("SPBackupDirectory").Text)-1))
'
objFS.DeleteFolder(objNode.SelectSingleNode("SPBackupDirectory").Text)
objLog.WriteLine(Now() &vbTab& "Deleted: "
&objNode.SelectSingleNode("SPBackupDirectory").Text& ".")
objXML.DocumentElement.RemoveChild(objNode)
End If
End If
Next
' Save the XML file with the old nodes removed.
objXML.Save(strTOCFile)
objLog.WriteLine(Now() &vbTab& "Finish: Completed backup clean up.")
It's crude but it seems to work.