backup removal on WSS 3.0 (Windows Server 2008)
Hello:
If this is not the appropriate forum for this, then please give me a link to one that is. Anyway, here's my concern.
The Windows Server 2008 scheduled task for removing Windows Sharepoint Services 3.0 backups every 7 days is not working. I can tell, because the backup folder that I created as a domain administrator at
\\ora-fs01\SharePointBackup still has backups dating back to October 25.
Upon noticing this, I ran the task manually and Task Scheduler says that it ran successfully. Once again, though, the same number of backup files are there.
I tried to run the program from a command prompt and DOS tells me that it cannot find the path to the .vbs script that I created for removing these backups.
What’s interesting is that, before trying to run this in DOS, I told DOS to change directory to the D drive. It refused access to me to any drive except for C. Could that be the issue?
Here is the “full path” of what needs to run: C:\Windows\System32\Cscript.exe D:\SharePointBackUpRemoval\BackupCleanUp.vbs 7
\\ora-fs01\SharePointBackup.
Below is the code. I am an administrator with all privileges therewith.
Thanks!
John
' Title: BackupCleanUp
' Description: Deletes SharePoint 2007 backups older than a specified
' number of days and removes them from the backup history.
Dim nNumberOfDays
Dim strTOCFile
Dim dtDeleteDate
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 "7 must be an integer value."
End If
strTOCFile = WScript.Arguments(1)
Else
WScript.Echo "Usage: BackupCleanUp 7 \\ora-fs01\sharepointbackup"
WScript.Quit
End If
objLog.WriteLine(Now() &vbTab& "Start: Clean up backups older than " &nNumberOfDays& " days from " &strTOCFile& ".")
' Load SharePoint Backup and Restore 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 Older Than Deletion Date
For Each objNode in objXML.DocumentElement.ChildNodes
If CDate(objNode.SelectSingleNode("SPFinishTime").Text) < dtDeleteDate Then
If objNode.SelectSingleNode("SPIsBackup").Text = "True" Then
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 XML File With Old Nodes Removed
objXML.Save(strTOCFile)
objLog.WriteLine(Now() &vbTab& "Finish: Completed backup clean up.")
November 5th, 2010 10:31am
Do you have the correct permissions on the share to delete?
Is UAC enabled on the server:
Are you able to navigate to D:\ and get the script to run successfully in an elevated command prompt? (right-click runas admin)
Free Windows Admin Tool Kit Click here and download it now
November 7th, 2010 10:45am
Do you have the correct permissions on the share to delete?
Is UAC enabled on the server:
Are you able to navigate to D:\ and get the script to run successfully in an elevated command prompt? (right-click runas admin)
November 7th, 2010 10:45am
Do you have the correct permissions on the share to delete?
Is UAC enabled on the server:
Are you able to navigate to D:\ and get the script to run successfully in an elevated command prompt? (right-click runas admin)
Free Windows Admin Tool Kit Click here and download it now
November 7th, 2010 10:45am
Yes, on your first question.
No, on your second question.
No, on your third question. When I run it, I get "msxml3.dll access is denied".
November 7th, 2010 1:47pm
Here's the answer. The xml code file that is created automatically was wrong. Once updated, the backup removal task ran successfully. Here is the good code:
Scroll all the way to the bottom, way way down, to see the solution (code below)
With boolDelete=False, it only logs what it WOULD delete. Once it looks OK, change boolDelete=True, it will actually delete old backup files and modify
the xml file that lists the backups.
' Title: BackupCleanUp
' Description: Deletes SharePoint 2007 backups older than a specified
' number of days and removes them from the
backup history.
Dim nNumberOfDays
Dim strTOCFile
Dim dtDeleteDate
Dim boolDelete
boolDelete = False
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 SharePoint Backup and Restore 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 Older Than Deletion Date
For Each objNode in objXML.DocumentElement.ChildNodes
Set objSPFinishTimeNode = Nothing
Set objSPFinishTimeNode = objNode.SelectSingleNode("SPFinishTime")
If Not objSPFinishTimeNode Is Nothing Then
If CDate(objSPFinishTimeNode.Text) < dtDeleteDate Then
Set objSPIsBackupNode = Nothing
Set objSPIsBackupNode = objNode.SelectSingleNode("SPIsBackup")
If Not objSPIsBackupNode Is Nothing Then
If objSPIsBackupNode.Text = "True" Then
Set objSPBackupDirectoryNode = Nothing
Set objSPBackupDirectoryNode = objNode.SelectSingleNode("SPBackupDirectory")
If Not objSPBackupDirectoryNode Is Nothing Then
If boolDelete = True Then
If objFS.FolderExists(objSPBackupDirectoryNode.Text) Then
If Right(objSPBackupDirectoryNode.Text, 1) = "." Then
strDirectory = Left(objSPBackupDirectoryNode.Text, Len(objSPBackupDirectoryNode.Text) - 1)
Else
strDirectory = objSPBackupDirectoryNode.Text
End If
If Right(objSPBackupDirectoryNode.Text, 1) = "\" Then
strDirectory = Left(objSPBackupDirectoryNode.Text, Len(objSPBackupDirectoryNode.Text) - 1)
End If
On Error Resume Next
objFS.DeleteFolder(strDirectory)
If Err.Number = 0 Then
On Error GoTo 0
objLog.WriteLine(Now() & vbTab & "Deleted: " & strDirectory & ".")
objXML.DocumentElement.RemoveChild(objNode)
Else
objLog.WriteLine(Now() & vbTab & "Error deleting " & strDirectory & ". " & Err.Description)
Err.Clear
On Error GoTo 0
End If
Else
objLog.WriteLine(Now() & vbTab & "Path in SPBackupDirectoryNode could not be found: " & strDirectory & ".")
End If
Else
objLog.WriteLine(Now() & vbTab & "Would Delete: " & objSPBackupDirectoryNode.Text & ".")
End If
Else
objLog.WriteLine(Now() & vbTab & "SPBackupDirectory node not found.")
End If
End If
Else
objLog.WriteLine(Now() & vbTab & "SPIsBackup node not found.")
End If
End If
Else
objLog.WriteLine(Now() & vbTab &
"SPFinishTime node not found.")
End If
Next
' Save XML File With Old Nodes Removed
objXML.Save(strTOCFile)
objLog.WriteLine(Now() &vbTab& "Finish: Completed backup clean up.")
Free Windows Admin Tool Kit Click here and download it now
November 9th, 2010 4:20pm