Delete Old Files

I’ve been working with Brightstor 11.5 SP2 Disk Staging Option lately.  We’ve configured it to purge old staging data according to a policy.  Unforunately, we’ve found that it only automatically purges data if the associated backup ran perfectly.  Of course, being a CA product, this is a rare event.  Hence our disk fills up with unwanted data and prevents future backups when the disk fills.
 
My solution is to purge old data using a script.  I found something very similar to what I wanted on Tek-Tips by a poster called "monsterjta".  After a little tweaking, I had what I wanted:
 
Option Explicit
on error resume next
    Dim oFSO
    Dim sDirectoryPath
    Dim oFolder
    Dim oFileCollection
    Dim oFile
    Dim iDaysOld
    Dim CurDir
 
‘Definitions
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    sDirectoryPath = CreateObject("WScript.Shell").CurrentDirectory
 
‘Set the age (in days) for files to be deleted in E:D2DFulls
    iDaysOld = 6
    sDirectoryPath = "E:D2DFulls"
    set oFolder = oFSO.GetFolder(sDirectoryPath)
    set oFileCollection = oFolder.Files
    DelOldFiles oFileCollection, iDaysOld
 
‘Set the age (in days) for files to be deleted in E:D2DDiffs
    iDaysOld = 5
    sDirectoryPath = "E:D2DDiffs"
    set oFolder = oFSO.GetFolder(sDirectoryPath)
    set oFileCollection = oFolder.Files
    DelOldFiles oFileCollection, iDaysOld
Function DelOldFiles (oFileCollection, iDaysOld)
‘Walk through each file in this folder collection.
    For each oFile in oFileCollection
        If oFile.DateLastModified < (Date() – iDaysOld) and NOT oFile.name = "HEADER.CTF" Then
            oFile.Delete(True)
‘ The following line is commented out.  It can be run for testing.
‘     wscript.echo "This file should be deleted: " & oFile.name
        End If
    Next
End Function
 
This script runs as a scheduled task on the backup server.  The highlighted sections are set up to match the data retention/purge policy in Disk Staging Option.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.