Solved

SQL Server 2008 - maint plan cleanup task not deleting old backup files

Posted on 2012-03-29
5
2,557 Views
Last Modified: 2012-03-31
I have created a maintenance plan with only 1 task -- a cleanup task to delete all .bak files in the backup folder older than 1 week.  The job completes successfully and the log file entry says it ran successfully but it's not deleting the old files.  I have verified I have the file extension (.bak) and the backup folder correct.  There are .bak files in that folder much older than 1 week but they do not get deleted.  I checked the box that indicates to go 1 sub-folder below the one specified.  At my last job I setup the maint plan this way and it worked fine.

Ideas?
0
Comment
Question by:Eric3141
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:pastorchris
ID: 37786640
A maintenance plan always logs backup details in MSDB database so a plan will not delete old backup files which it did not backup initially.

For instance you have  maintenance plans:
"Plan A" and "plan B"
If both plans backup the same database and are also set to delete old backup files, "Plan A" will delete only old backup files which were logged as initially backed up by "Plan A".
Likewise, as much as both plans backup the same databases, "Plan B" will only clean-up old backup files which it originally backed up!

If you have a plan to delete old backup files but the backups were or are taken by another plan, then your plan will not work on them.
Similarly, if you have a maintenance plan which is meant to delete backup files for other plans, then it wont work too!
This is how SQL 2005, 2008 plans are made to work.

The solution is: You will have to manually delete the old backup files in the backup folder and then the current plan will delete its own backup files.

The logic used to work in SQL server 7 and SQL 2K .....but in 2K5, 2K, 2K8 R2 and 2012, this wont work.
0
 
LVL 46

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 37787113
Try '*bak' or only '*' if you know that only backup files will be there.

Good luck
0
 
LVL 2

Author Comment

by:Eric3141
ID: 37787115
Thx.  That explains why maint plan B (that only has the task to delete old files) won't delete the old files.  But maint plan A (that backed up the databases) also has a task (in the same sub-plan where the backup happens) to delete old files -- and it's not doing that.  Plan A writes to a log file that one of the parameters is wrong or the connection string is wrong.  Yet the connection string (local system -- the default one) can't be wrong because the maint plan does actually backup the databases.  I don't see how the parameters can be wrong because I specified them thru the maint plan wizard.

Ideas?
0
 
LVL 2

Author Comment

by:Eric3141
ID: 37787899
Oh my gosh... for file extension I included the '.' so was using '.bak' instead of 'bak'.  So the maint plan job was looking for files with extension = '..bak' older than one week to delete.  Not finding any, the job completed normally without error and did not delete the old files.
0
 
LVL 12

Expert Comment

by:pastorchris
ID: 37790911
Extension should be "BAK".
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Haw to apply join on 2 tables with this scenario 4 22
SQL Query 2 43
Can Unique column have more than one Null? 8 43
all records from previous month 6 45
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now