SQL 2005 - Maintenance Cleanup Task

  • Do you have to create a separate Maintenance Cleanup Task in order to delete each type of file e.g .txt, .bak, .trn etc?

  • Yes. The alternative would be to create an SSIS package for maintenance operations in BIDS and use a script task to delete files, i.e.

    Imports System.Data

    Imports System.Math

    Imports System.IO

    Imports Microsoft.SqlServer.Dts.Runtime

    Public Class ScriptMain

    Public Sub Main()

    Dim strFile As String, strFilePath As String

    strFilePath = Dts.Variables("varBackupLocation").Value

    Dim strFileNames = Directory.GetFiles(strFilePath)

    Try

    For Each strFile In strFileNames

    Dim FileInfo As New System.IO.FileInfo(CStr(strFile))

    'For Debug

    'System.Windows.Forms.MessageBox.Show(FileInfo.CreationTime)

    'System.Windows.Forms.MessageBox.Show(FileInfo.CreationTime < DateTime.Now.AddDays(-3))

    If (FileInfo.CreationTime <= DateTime.Now.AddDays(-3)) = True Then

    File.Delete(strFile)

    End If

    Next

    Catch ex As Exception

    End Try

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

  • Thanks for the response. Have implemented it and it works well.

  • NP 😀

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply