backup rotation, any thoughts?

J

Jeroen Wijnands

I've used stsadm to schedule a full backup of my 2007 environment to a
share. Our centralized backup solution archives this to tape. No
problems, routine for most windows environments here.

However..... those dumps are currently 500mb each and I expect this to
grow rapidly when we go live with this environment. I'm considering
writing something to delete older backups but I'm a bit worried that
this will mess up the validity of the spbrtoc.xml file.

Any ideas on this?

TIA!

Jeroen Wijnands
 
N

NZ Projects

I only back up the farm when I change the topology such as add a new
application, top level site, content db etc. Once the backup is complete I
archive the entire backup directory to tape, so a new spbtroc.xml file is
created for each backup.

For daily backups I simply rely on the SQL backup model to backup the DB's
and logs.
 
J

Jochen Ruhland

Hi,

from a white paper by Microsoft:

• Does not provide automatic deletion of old backup files. You may want to
use the backup file deletion script provided in the following Microsoft
Knowledge Base article: How to automate the deletion of backups in SharePoint
Server 2007 and in Windows SharePoint Services 3.0 by using a Visual Basic
script (http://go.microsoft.com/fwlink/?LinkId=102617&clcid=0x409).
 
J

Jeroen Wijnands

Thanks Jochen,

We run into eachother often enough, time to exchange email
addresses? ;-)
 
J

Jeroen Wijnands

Tried the script, looks good but I get

C:\scripts>cscript backupcleanup.vbs 2 e:\sharepoint_backups
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\scripts\backupcleanup.vbs(31, 1) msxml3.dll: Access is denied.

Now I can't find any reasonable cause why this should fail.
 
J

Jochen Ruhland

Hi,

the 2nd argument should be the path to the xml-file, not the path to the
directory only.

Try:

C:\scripts>cscript backupcleanup.vbs 2 e:\sharepoint_backups\spbrtoc.xml
 
J

Jeroen Wijnands

No luck. I think it's a date format issue

I've added some echo'ing to the script and found this:

Backupdate11/06/2007 05:02:04
Checkdate4-11-2007 13:50:56
\\nl-ap043a\sharepoint_backups$\spbr0010\
 
J

Jochen Ruhland

Hi,

Jeroen Wijnands said:
No luck. I think it's a date format issue
Backupdate11/06/2007 05:02:04
Checkdate4-11-2007 13:50:56

looks like a date issue. Maybe put some conversion magic aroung this line of
code:

If CDate(objNode.SelectSingleNode("SPFinishTime").Text) < dtDeleteDate
Then
 
C

Carl

We found that script doesn't work with a UK server, and can end up deleting
all sharepoint backups depending on what the date is at the time.

It was down to sharepoint writing the XML file in US format, and the script
running on our server and comparing the date in UK format.

Adding....

"SetLocale(1033) 'uslocale"

......to the beginning of the script was enough to get the script to compare
using a US formatted date.

Hope this helps some of you out.

Carl
 
J

Jeroen Wijnands

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.
 
C

Carl

Glad it's sorted.

We also changed the "Delete backup nodes section...." to check if the folder
it's trying to delete exists. The script seemed to fall over if the folder
had been manually deleted for whatever reason, but it was still in the script.

Our section now looks like:

' 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

if
objFS.FolderExists(left(objNode.SelectSingleNode("SPBackupDirectory").Text,len(objNode.SelectSingleNode("SPBackupDirectory").Text)-1)) the
objFS.DeleteFolder(left(objNode.SelectSingleNode("SPBackupDirectory").Text,len(objNode.SelectSingleNode("SPBackupDirectory").Text)-1))

else
objLog.WriteLine(Now() &vbTab& "Error: Folder found in xml backup file,
does not exist on drive, cannot delete it " &vbCrLf&_
Now() &vbTab&
left(objNode.SelectSingleNode("SPBackupDirectory").Text,len(objNode.SelectSingleNode("SPBackupDirectory").Text)-1) & " .")
End if

objLog.WriteLine(Now() &vbTab& "Deleted: "
&objNode.SelectSingleNode("SPBackupDirectory").Text& ".")
objXML.DocumentElement.RemoveChild(objNode)
End If
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top