Thursday, February 17, 2011

Delete old SQL backups using a maintenance plan

I had an onsite with a client I rarely get to visit today. They are located about an hours drive south of Cairns. Their SBS 2008 server's data drive is an 860GB disk partition that had run out of disk space. A quick investigation with Tree Size (a free tool that I recommend for anyone wanting to know where all their disk space has gone) showed that the folder D:\SQLBackups was approx. 560GB in size. The SQLBackups folder contained thousands of backup files of the clients HR3 and GP databases going back 5 months.

I checked the Windows Task Scheduler, there was no SQL backup jobs scheduled here. I ran up the Microsoft SQL Server Management Studio and checked the Maintenance Plans. The consultant that installed and customized Great Plains for them had created a Maintenance Plan that checked the integrity of the databases and rebuilt indexes on a weekly basis. It also ran a full backup of the user databases daily and a transaction log backup every 2 hours. The backups were written to the D:\SQLBackups folder. The consultant neglected to create a subplan to delete old backup files, perhaps he knew he wouldn't be around when disk space would become an issue.

What's needed is to add a subplan to the existing Maintenance Plan. Click "Add Subplan" and edit the schedule to a suitable time, in this case I chose daily at 6:00am. Drag the Maintenance Cleanup Task from the Toolbox window on the left to the task window on the right.


I edited the task settings to delete the bak  database backup files older than 4 weeks from the D:\SLQBackups folder and the first level of sub folders. I dragged a second Maintenance Cleanup Task from to the task window and linked it to the first task, then edited it to this time delete the trn Transaction Log backup files older than 4 weeks.



Running the new subplan freed up approx 450GB of disk space. This saves the client buying more hard drives and also reduces the amount of data to be backup up to an external drive on a nightly basis and also the time taken for this backup.

No comments:

Post a Comment