Published on

November 14, 2014

Understanding SQL Server Maintenance Cleanup Task

As a SQL Server user, it is important to ensure that your database backups are properly managed to avoid filling up your drive with unnecessary files. One way to achieve this is by using the Maintenance Cleanup Task in SQL Server.

Recently, one of my blog readers encountered an issue with the Maintenance Cleanup Task. He had set up the task to delete backup files with the extension “.bak” that were older than 7 days. However, despite the task running successfully, the older backup files were not being deleted.

Upon further investigation, it was discovered that the issue was caused by a simple mistake in the configuration of the task. The reader had mistakenly included a dot before the file extension in the UI, resulting in the task not recognizing the files to be deleted.

To resolve the issue, the correct command to delete the backup files was provided:

EXECUTE MASTER.dbo.xp_delete_file 0, N'E:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Backup', N'bak', N'2014-09-30T10:14:59' GO

By running this command, all backup files with the extension “.bak” older than the specified date were successfully deleted.

The moral of the story is to ensure that you do not include a dot before the extension of the file in the UI when configuring the Maintenance Cleanup Task. This simple mistake can prevent the task from functioning as expected.

Properly managing your database backups is crucial for maintaining a healthy SQL Server environment. By understanding the nuances of tasks like the Maintenance Cleanup Task, you can ensure that your backups are efficiently managed and your drive space is not unnecessarily consumed.

Remember, attention to detail is key when working with SQL Server maintenance tasks. Double-check your configurations to avoid any unexpected issues.

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.