Backup Files From Azure Storage need a retention review before removal. I list the candidates before approving any cleanup.

A reader shared this alternative to my earlier Azure backup-cleanup script. It selected .bak blobs at least ten days old. The age calculation is useful, but the restore chain must determine what can be removed.
The original Azure cmdlets have been replaced by the Az module equivalents. This updated Windows PowerShell example lists candidate .bak blobs using UTC timestamps and an existing approved account context. It contains no storage-account secret.
# Article example only. Requires an existing approved Az sign-in and RBAC access.
$storageAccount = 'YourStorageAccount'
$containerName = 'YourBackupContainer'
$retentionDays = 10
$cutoffUtc = [DateTimeOffset]::UtcNow.AddDays(-$retentionDays)
$storageContext = New-AzStorageContext -StorageAccountName $storageAccount -UseConnectedAccount
$candidates = @(Get-AzStorageBlob -Container $containerName -Blob '*.bak' -Context $storageContext |
Where-Object { $null -ne $_.LastModified -and $_.LastModified -lt $cutoffUtc })
$candidates | Select-Object Name, LastModified, Length
# Review the full/differential/log restore chain and retention policy first.
# This remains a preview, even if uncommented:
# $candidates | ForEach-Object {
# Remove-AzStorageBlob -Container $containerName -Blob $_.Name -Context $storageContext -WhatIf
# }Age and the .bak extension don’t establish that a backup is disposable. An older full backup can support retained differentials or logs. I check restore tests and the required chain. Storage immutability, snapshots and versioning need separate review.
The commented removal block uses -WhatIf and remains a preview. Actual cleanup needs a separately approved list and an intentional removal step. Azure lifecycle rules can automate age-based removal, but those rules also need the same backup-retention design.
The script can run from an authorized Windows management machine. It doesn’t have to run on the database server. Use an approved Azure account context for the listing.
Reference: Remove-AzStorageBlob preview and deletion behavior.
Related reading
A file age is not a restore-retention decision, it is one attribute used to inspect a cleanup candidate.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.





2 Comments. Leave new
Nice post..I found some typing error. Please note it below,
1. Please change the extension (in the 3rd point under Notes). It has to be *.bak instead of *.back
Thanks a Lot