February 13, 2012 at 8:35 am
So I have some stored procedures that clean up a specific backup folder every night to keep a certain number of day's backups on hand. How do I create a script to delete old .bak files older than 90 days, across the entire drive?
February 13, 2012 at 8:48 am
Is this a local drive or a networked backup location? Seems risky to want to wipe out filetypes across and entire drive...
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
February 13, 2012 at 8:49 am
Local drive. Just want to specify (for example) D:\ and have it search the entire drive for old .bak flies.
February 13, 2012 at 8:51 am
I actually create a job using the maintenance plan feature of SQL Server to do this. I create the plan that deletes all differential backups. I then go and add a step before this step to do a full backup. So after my fill backup, it deletes all of my diff's. Acceptable for our company's risk tolerance and space usage, but may not be for your company. However, the maintenance plan created will allow you to choose how long you want to keep these files.
Jared
CE - Microsoft
February 13, 2012 at 8:53 am
That's not really what I am looking for but thanks. We enforce disk quotas for the developers so we don't want a ton of old crap laying around in various folders. Simply doing a recursive delete on the D: drive for .bak files older than 90 days is all I need.
February 13, 2012 at 8:56 am
Again, using a maintenance plan and using the cleanup task will allow you to specify the extension for files to delete (bak), an age (>90 days), a file path and an option to include all sub-folders, and finally a schedule. I think this is exactly what you are looking for.
Jared
CE - Microsoft
February 13, 2012 at 9:01 am
I agree with Jared, sounds like the way to go
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
February 13, 2012 at 9:11 am
I will give that a shot and post back if I get stuck.
February 13, 2012 at 9:00 pm
ahthomas (2/13/2012)
That's not really what I am looking for but thanks. We enforce disk quotas for the developers so we don't want a ton of old crap laying around in various folders. Simply doing a recursive delete on the D: drive for .bak files older than 90 days is all I need.
Are you deleting from the backup history in the log files in MSDB? If you're not, you're only doing a part of the job that a well laid out maintenance plan would take care of automatically.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 14, 2012 at 6:52 am
Forgot to follow up on this yesterday. Looks like the maintenance plan goes only one subdirectory level down from D:\, so this doesn't work for what I need it to do. I need a FULL scan of the HDD for .bak files older than 90 days.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply