I have a Maintenance Plan that is suppose to go through the BACKUP folder and remove all .bak older than 5 days. When I run the job, it gives me a success message but older .bak files are still present.

I've tried the step at the following question: SQL Maintenance Cleanup Task 'Success' But not deleting files

Result is column IsDamaged = 0

I've verified with the following question and this is not my issue: Maintenance Cleanup Task(s) running 'successfully' but not deleting back up files

I've also tried deleting the Job and Maintenance Plan and recreating, but to no avail.

Any ideas?


I would recommend capturing the T-SQL call during the cleanup task to see if the input parameters make sense. For example - I captured the following call on version 10.0.2766:

EXECUTE master.dbo.xp_delete_file 0,N'c:\temp',N'.bak',N'2011-03-16T09:23:28',1

First five params in the previous example are type (1 for report, 0 for backup), folder, extension, date.

This will help identify if a particular parameter doesn't make sense (for example - extension fields being used are correct, dates not correct, errors not occurring). Also would be interested in knowing if that command works if executed outside of the context of the plan.

** Update ** I ran process monitor and filtered based on the SQL Server PID. I can't reproduce your error - but here is a screen shot of what a successful archiving should look like. Something for you to compare against - and also will let you know quickly if this is an underlying permissions issue:

enter image description here

| improve this answer | |
  • EXECUTE master.dbo.xp_delete_file 0,N'D:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup',N'bak',N'2011-03-11T12:30:41',1 – Alex Mar 16 '11 at 16:32
  • @Joe Clark Could it be that the master.dbo.xp_delete_file is corrupt? I had an issue with this SQL install which is now fixed, see: serverfault.com/questions/244869/… Thank you for your help – Alex Mar 16 '11 at 18:33
  • Just curious about the 'bak' versus '.bak' - let me test this and see if this was the issue. Regarding corruption - I would expect to see an error message, but may be possible (haven't seen that scenario before). Will ping you after testing your call. – Joe Sack Mar 16 '11 at 21:05
  • Okay - .bak versus bak didn't matter, I just tested it. – Joe Sack Mar 16 '11 at 21:07
  • And just to confirm - executing that command apart from the plan makes no difference, right? Doesn't work in either scenario? – Joe Sack Mar 16 '11 at 21:08

Another Serverfault user had the same issue recently, the below answer fixed the problem, give it a go.

SQL Maintenance Cleanup Task Working but Not Deleting

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.