Link to home
Start Free TrialLog in
Avatar of Eric3141
Eric3141Flag for Afghanistan

asked on

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

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?
Avatar of Chris M
Chris M
Flag of Uganda image

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.
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric3141

ASKER

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?
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.
Extension should be "BAK".