Solved

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

Posted on 2012-03-29
5
2,582 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Chris M
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 51

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:Chris M
ID: 37790911
Extension should be "BAK".
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 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