Old Backup file deletetion issue on SQL Server maintenance backups


Problems :

I recently came across this issue of SQL Server not deleting backups files older then a specific time. In my SQL Server maintenance plan I had specified to delete backups after a week, but on my installation the backups were not getting deleted.

Solution:

In order to sort this out I was given various suggestions on the MS news groups, but the one that worked for me was to change the recovery option of the databases from simple to either bulk or full. If you take the properties of a database in SQL Server, and then click the options tab, there are settings for recovery for the database, you need to make sure that they are not selected to simple for all databases otherwise the maintenance plan fails to delete the older files. Other suggetions are listed as under.

Below KB might help:
http://support.microsoft.com/default.aspx?scid=kb;en-us;303292&Product=sql2k

This is likely to be either a permissions problem or a sharing violation
problem. The maintenance plan is run as a job, and jobs are run by the
SQLServerAgent service.

Permissions:
1. Determine the startup account for the SQLServerAgent service
(Start|Programs|Administrative tools|Services|SQLServerAgent|Startup). This
account is the security context for jobs, and thus the maintenance plan.
2. If SQLServerAgent is started using LocalSystem (as opposed to a domain
account) then skip step 3.
3. On that box, log onto NT as that account. Using Explorer, attempt to
delete an expired backup. If that succeeds then go to Sharing Violation
section.
4. Log onto NT with an account that is an administrator and use Explorer to
look at the Properties|Security of the folder (where the backups reside)
and ensure the SQLServerAgent startup account has Full Control. If the
SQLServerAgent startup account is LocalSystem, then the account to consider
is SYSTEM.
5. In NT, if an account is a member of an NT group, and if that group has
Access is Denied, then that account will have Access is Denied, even if
that account is also a member of the Administrators group. Thus you may
need to check group permissions (if the Startup Account is a member of a
group).
6. Keep in mind that permissions (by default) are inherited from a parent
folder. Thus, if the backups are stored in C:\bak, and if someone had
denied permission to the SQLServerAgent startup account for C:\, then
C:\bak will inherit access is denied.

Sharing violation:
This is likely to be rooted in a timing issue, with the most likely cause
being another scheduled process (such as NT Backup or Anti-Virus software)
having the backup file open at the time when the SQLServerAgent (i.e., the
maintenance plan job) tried to delete it.
1. Download filemon and handle from http://www.sysinternals.com.
2. I am not sure whether filemon can be scheduled, or you might be able to
use NT scheduling services to start filemon just before the maintenance
plan job is started, but the filemon log can become very large, so it would
be best to start it some short time before the maintenance plan starts.
3. Inspect the filemon log for another process that has that backup file
open (if your lucky enough to have started filemon before this other
process grabs the backup folder), and inspect the log for the results when
the SQLServerAgent agent attempts to open that same file.
4. Schedule the job or that other process to do their work at different
times.
5. You can use the handle utility if you are around at the time when the
job is scheduled to run.

If the backup files are going to a \\share or a mapped drive (as opposed to
local drive), then you will need to modify the above (with respect to where
the tests and utilities are run).

Finally, inspection of the maintenance plan’s history report might be
useful.

Advertisements

3 thoughts on “Old Backup file deletetion issue on SQL Server maintenance backups

  1. Hi,
    Regarding this issue of Sql 2005 backup,
    I have developed a service that runs automatically with the system to work on removing any files those are older than 7 days, with customised backup directory location enterd in an .ini file to make it usefull for as many people as it could be!

    If you are interested please contact me on mohamedf@emeco.com

    or mohamedfoad@gawab.com.

    Thanks.

  2. I use FileDestroyer with Windows Task Scheduler
    http://sourceforge.net/projects/filedestroyer/

    Here is a short tutorial:

    http://arturito.net/2010/07/13/file-destroyer-clean-upfree-up-disk-space-and-deleting-files-or-folders-after-a-certain-period-of-time/

    Usage:

    FileDestroyer.exe -scan “D:\SQLBackup” -ext bak -log “D:\Logs\” –days 2

    This command scans folder “D:\SQLBackup” looks for extension .bak and removes backups/files older than 2 days and it logs everything in D:\Logs\

    It also supports UNC Paths (\\server1\shared\backups\)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s