Solved

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

Posted on 2012-03-29
5
2,551 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 45

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

18 Experts available now in Live!

Get 1:1 Help Now