Export (0) Print
Expand All

Clean up backup files (Office SharePoint Server 2007)

Office 2007

Applies To: Office SharePoint Server 2007

Most data storage and backup retention policies allow for periodic cleanup of old or obsolete backups. It is very important that you retain backups for the time that is required. However, if you do not periodically remove or archive outdated backup files, short-term backup storage devices fill up quickly. Although SharePoint Products and Technologies does not provide an automated backup removal function, you can implement a simple script to perform this task.

Configure periodic backup removal

The following procedures include a sample Microsoft Visual Basic script that you can use and edit as necessary to do the following:

  • By using a single command, locate and delete backup files older than a specified time period.

  • Update the backup manifest file (spbrtoc.xml) to remove records of the deleted files.

  • Create a log file of backup removal activity.

  • Work together with the task scheduler to automate the periodic removal of obsolete backup files.

WarningWarning:

Use the code in this article at your own risk.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not edit these examples to provide additional functionality or construct procedures to meet your specific requirements.

If you have limited programming experience, consider contacting a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, see the Microsoft Partner Program Web site (http://go.microsoft.com/fwlink/?LinkId=128105). For more information about the support options that are available and about how to contact Microsoft, see the Microsoft Help and Support Web site (http://go.microsoft.com/fwlink/?LinkId=128109).

The following are required to perform this task:

  • A script editor and debugger such as Microsoft Visual Studio 2008 (recommended) or a text editor such as Notepad.

  • Experience with scripting languages.

  • Backup files must be stored on devices that can be accessed on the network and that are operational.

  • A clear backup retention policy that specifies how long backup files must be kept.

ImportantImportant:

Membership in the Administrators group on the local computer is the minimum required to complete the following procedure.

Write a backup removal script

  1. Create a folder on the computer that will perform the backup removal task. This folder will contain the backup removal script and the log file.

  2. Start the script editor, and then copy and paste the following code example into the editing window:

    
    '       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 "<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
        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.")
    

    You can edit the script as necessary to meet the requirements of the network, equipment, retention policies, or service agreements.

  3. Save the file as BackUpCleanUp.vbs in the folder that you created earlier.

ImportantImportant:

Membership in the Administrators group on the local computer is the minimum required to complete the following procedure.

Run the backup removal script

  1. At a command prompt, change to the directory that contains the BackUpCleanUp.vbs file.

  2. Type the following command, and then press ENTER:

    Cscript.exe BackUpCleanUp.vbs <Number of days> <\\server name\folder name>

    where <Number of days> is the maximum age of the backup files you want to keep (backup files older than this will be deleted by the BackUpCleanUp script) and <\\server name\folder name> is the path of the spbrtoc.xml backup manifest file.

  3. To troubleshoot the backup file removal process or to review progress, open the BackUpCleanUp.log file located in the same folder.

ImportantImportant:

Membership in the Administrators group on the local computer is the minimum required to complete the following procedure.

Schedule or delay backup removal

  1. Start the Scheduled Tasks Wizard, double-click Add Scheduled Task, and then click Next.

  2. Click Browse, navigate to %ROOT%\WINNT\System32\cscript.exe, and then click Open.

  3. Type a name for the task, for example, BackUpCleanUp.

  4. To automatically perform this backup periodically, select an interval such as Weekly or Monthly, and then click Next. To perform this backup one time, or to delay a single backup, select One time only.

  5. Choose a time and start date for the task, and then click Next.

  6. Type a user name and password in the appropriate boxes, confirm the password, and then click Next. This task will run as if it were started by that user.

  7. Select Open advanced properties for this task when I click Finish, and then click Finish.

  8. In the Advanced Properties dialog box, on the Task tab, in the Run text box, type the following command:

    Cscript.exe BackUpCleanUp.vbs <Number of days> <\\server name\folder name>

    where <Number of days> is the maximum age of the backup files that you want to keep (backup files older than this will be deleted by the BackUpCleanUp script) and <\\server name\folder name> is the path of the spbrtoc.xml backup manifest file.

  9. In the Start In text box, type the path of the folder where the BackUpCleanUp.vbs file is located.

  10. Select Enabled (scheduled task runs at specified time), and then clear the Run only if logged in check box.

  11. Click OK.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft