1
votes

I am trying to remove the long term retention policy on a test db and delete the vault attached to it. I was able to disable the policy but when I try to delete the vault, I get the error:

Vault cannot be deleted as there are existing resources within the vault. Please ensure there are no backup items, protected servers or backup management servers associated with this vault. Unregister the following containers associated with this vault before proceeding for deletion : Sql;mydatabase123;mysqlserver123-svr Unregister all containers from the vault and then retry to delete vault

I'd like to completely undo their bond so I can setup another long term policy with another vault and also to test the limits of what I can do with azure sql and vaults.

Any idea how I can undo what I did? Thanks!

P.S. I found this question also posed here but without a resolution.

2

2 Answers

1
votes

Please try using PowerShell to remove the recovery vault as a workaround.

$vault = Get-AzureRmRecoveryServicesVault -Name "TestRecoveryServiceVault"
Remove-AzureRmRecoveryServicesVault -Vault $vault

Remove-AzureRmRecoveryServicesVault -Vault $vault -Force

Above cmdlets will remove the recovery vault irrespective of the contents of the vault.

1
votes

There are SQL backups in the vault. You need find SQL backups and delete them. Try following script.

$vault = Get-AzureRmRecoveryServicesVault -Name "VaultName"

Set-AzureRmRecoveryServicesVaultContext -Vault $vault

#VIEW THE BACKUP ITEMS
$container = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureSQL -FriendlyName $vault.Name

$item = Get-AzureRmRecoveryServicesBackupItem -Container $container -WorkloadType AzureSQLDatabase

$availableBackups = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $item

$availableBackups      
#REMOVE THE BACKUP ITEMS AND VAULT
$containers = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureSQL -FriendlyName $vault.Name

ForEach ($container in $containers)
{
    $items = Get-AzureRmRecoveryServicesBackupItem -container $container -WorkloadType AzureSQLDatabase

    ForEach ($item in $items)
    {
        Disable-AzureRmRecoveryServicesBackupProtection -item $item -RemoveRecoveryPoints -ea SilentlyContinue
    }

    Unregister-AzureRmRecoveryServicesBackupContainer -Container $container
}

Remove-AzureRmRecoveryServicesVault -Vault $vault

You also could check this question.