Skip to content

Commit

Permalink
Fix storage account clean up (#7496)
Browse files Browse the repository at this point in the history
* Revert "Add extra handling for errors during clean-up"

This reverts commit 3eb8cb7.

* Skip container clean-up for file storage accounts as it has none
  • Loading branch information
weshaggard authored Jan 8, 2024
1 parent bd78868 commit 100254c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions eng/scripts/Remove-WormStorageAccounts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ foreach ($group in $groups) {
} else {
Write-Host "Removing $($account.StorageAccountName) in $($account.ResourceGroupName)"
}

$hasContainers = ($account.Kind -ne "FileStorage")

# If it doesn't have containers then we can skip the explicit clean-up of this storage account
if (!$hasContainers) { continue }

$ctx = New-AzStorageContext -StorageAccountName $account.StorageAccountName

$immutableBlobs = $ctx `
| Get-AzStorageContainer `
| Where-Object { $_.BlobContainerProperties.HasImmutableStorageWithVersioning } `
| Get-AzStorageBlob
try {
# Sometimes the retrieval here fails in preview/dogfood regions but we should still try to delete the storage account below
# so just handle the exception and attempt the delete below.
$immutableBlobs = $ctx `
| Get-AzStorageContainer `
| Where-Object { $_.BlobContainerProperties.HasImmutableStorageWithVersioning } `
| Get-AzStorageBlob

foreach ($blob in $immutableBlobs) {
Write-Host "Removing legal hold - blob: $($blob.Name), account: $($account.StorageAccountName), group: $($group.ResourceGroupName)"
$blob | Set-AzStorageBlobLegalHold -DisableLegalHold | Out-Null
Expand Down

0 comments on commit 100254c

Please sign in to comment.