I have a job that deletes transaction log backups older than 3 days.
if for some reason there are no files to delete, it comes out with the following error message:
Msg 22049, Sev 16, State 1: xp_delete_file() returned error 2, 'The system cannot find the file specified.' [SQLSTATE 42000]
Job 'Log Shipping - Delete tran backups older than 3 days' : Step 1, 'delete the trn files older than 3 days' : Began Executing 2019-01-18 23:00:02
Msg 22049, Sev 16, State 1: xp_delete_file() returned error 2, 'The system cannot find the file specified.' [SQLSTATE 42000]
this is the code of the job:
-This will set the date time stamp to pass onto the Stored Proc for 72 hours from the current date when it runs
--The stored proc will recursively delete all TRN files from the parent level specified all the way down
declare @DeleteDate nvarchar(50)
declare @DeleteDateTime datetime
set @DeleteDateTime = DateAdd(hh, -72, GetDate())
set @DeleteDate = (Select Replace(Convert(nvarchar, @DeleteDateTime, 111), '/', '-') + 'T' + Convert(nvarchar, @DeleteDateTime, 108))
--5th argument below "0 - don't delete recursively (default)" and "1 - delete files in sub directories"
EXECUTE master.dbo.xp_delete_file 0,N'\\homer\S_SYSTEMS\FullBackups\MY_SERVER\_log1\',N'trn', @DeleteDate,1
--5th argument below "0 - don't delete recursively (default)" and "1 - delete files in sub directories"
EXECUTE master.dbo.xp_delete_file 0,N'\\homer\S_SYSTEMS\FullBackups\MY_SERVER\_log12',N'trn', @DeleteDate,1
how can we change this? if there are no files, that's fine, no need to fail the job.




