Deleting SQL backups that are a specific age

Posted: Tuesday 6 December 2011 by Khalid Ameerodien in Labels:
0

I was having a bit of an issue on one of our dev environments where SQL would complete a backup but even though I specified that backups should be removed if older than 3 days in my maintenance plan it would not remove them. No errors nothing.

 

I then reverted to old faithful powershell and created the following script which I ran via a scheduled task.

 

Dir "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -recurse | where {$_.LastWriteTime –lt (get-date).AddDays(-3) } | % {del $_.FullName}

 

0 comments: