December 12, 2011 at 11:56 am
Hi,
I'm using the below VB script to delete the old backup files via SQLAgent and it's working fine in SQL Server 2005.
But it's NOT working in SQL Server 2008 R2. The SQLAgent job finishes successfully without deleting the old backup files.
Option Explicit
on error resume next
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim Message
Dim iDaysOld
Dim oFSFile
Dim objTextFile
Dim objFSO
Const ForAppending = 8
'Customize values here to fit your needs
iDaysOld = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "Z:\Backups\Full\"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFileCollection = oFolder.Files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("D:\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\Delete_FullBakFiles.txt", ForAppending, True)
'Walk through each file in this folder collection.
'If it is older than 1 days, then delete it.
For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
objTextFile.WriteLine Date & " " & Time & " Deleting File " & oFile.name
oFile.Delete(True)
End If
Next
'Clean up
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
objTextFile=Nothing
Please advice
December 13, 2011 at 4:05 am
Please verify the path\file 'D:\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\Delete_FullBakFiles.txt'. It is not valid for SQL Server 2008.
For More:
December 13, 2011 at 8:32 am
Verify the path, if it's not working, include some MSGBOX lines in there, and see what values are being sent for the files and folders. It's basic debugging here for your system.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply