Simple PowerShell script to compress SQL Bacup files

# Handle BAK and TRN files
get-childitem -recurse |
where { $_.extension -match ".(bak|trn)" -and -not (test-path ($_.fullname -replace "(bak|trn)", "7z")) } |
foreach { &7za a -t7z -mx=9 ($_.fullname -replace "bak", "7z") $_.fullname }

# Delete any BAK or TRN that has a matching 7z file
get-childitem -recurse |
where { $_.extension -match ".(bak|trn)" -and
(test-path ($_.fullname -replace "(bak|trn)", "7z")) } |
foreach { del $_.fullname }

Leave a Reply

Close Menu