Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  


SQL Server 2008 Maintenance Cleanup Task to delete database backup files
If you have an automated SQL Server Task to create backups of your database, you may want to automatically delete those that are old.

To delete database backup files regularly using a Maintenance Cleanup Task, follow these steps:

Create a Maintenance Plan (Database/Management/Maintenance Plans)

Create a new Maintenance Cleanup Task as part of a Maintenance Plan (drag a 'Maintenance Cleanup Task' onto the workflow panel below the subplans).

Edit the Maintenance Cleanup Task (right click)

For 'Delete files of the following type', select 'Backup files'

For 'File Location', select 'Search folder and delete files based on an extension' (unless you only have a single backup file, but then there is not a good reason to delete it).

Enter the folder that contains your database backup files (or subfolders) into the 'Folder' text box. This MUST end with a backslash. If it does not, the cleanup task will not delete the database files in the folder.
Example: C:\Sql\Backup\

Enter 'bak' as the 'File Extension'. Do not include a period (.bak) or the files will not delete. The period should not be included.

Check 'Include first-level subfolders' if each database you are backing up is in a subfolder within the main folder.

To only delete old files, check the box 'Delete files based on the age of file at task run time'.
Enter a number and select the time period, for example "2 months".

Click OK to save your changes, and add a subplan to schedule what day or days your task will run.

Save your changes. Test the plan by right-clicking and selecting 'Execute'. (refresh the Maintenance Plans tree if it does not appear).

Created By: amos 3/25/2013 10:46:16 AM
Updated: 12/16/2014 6:08:45 AM