Cleanup of Differential and Log Backups

  • I am using Ola Hallegren's scripts to do backups. He uses @Cleanup Time to delete backups older than a certain number of hours. My situation is I do a full backup of a database on Sunday and then I have a few Differentials and then log backups for the rest of the week. When Sunday rolls around again and my full backup is finished, I would like to delete all the differential backups and log backups. Does anyone know of a way that I could accomplish this using Ola's scripts?

    Thanks

    Kathy

  • I use powershell. Like this:

    $Path = "D:\MyPath"

    $CurrentDate = Get-Date

    $DatetoDeleteFULL = $CurrentDate.AddDays(-14)

    $DatetoDeleteDIFF = $CurrentDate.AddDays(-7)

    Get-ChildItem $Path -Recurse -include *_FULL_*.sqb| Where-Object { $_.LastWriteTime -lt $DatetoDeleteFULL } | Remove-Item

    Get-ChildItem $Path -Recurse -include *_DIFF_*.sqb| Where-Object { $_.LastWriteTime -lt $DatetoDeleteDIFF } | Remove-Item

    This runs on my backup server where I keep my backup files, generated by Ola's solution.

    As you can see above, FULL and DIFFs are deleted based on 2 and 1 week respectively. Of course, you can adjust that to your own particular case.

    That code runs as a Task in Windows, every weekend. The code is a local file with "ps1" extension. That file is the one being called by Windows Task Scheduler.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply