-1

**Az104 lab 10 Have created 2 backup items in Recovery Services Vault but unable to remove/delete it

  • Azure VM & Azure Backup Agent**

  • On trying to remove or delete these items; since soft-delete is enabled (Say for 14 days). Facing error on Manual as well as PowerShell Delete procedures.

  • PowerShell seems to be not updated with Current menu options in Azure Portal. I used the below; get the status as success but VM and Agent still appear in my subscription.

Below is the PS I used

Undo-AzRecoveryServicesBackupItemDeletion -Item $myBKpItem -VaultId $myVaultID -Force


Disable-AzRecoveryServicesBackupProtection -Item $myBkpItem -RemoveRecoveryPoints -VaultId $myVaultID -Force

And ms-learn docs the below PowerShell seems to not work

Set-AzRecoveryServicesVaultProperty -VaultId $myVaultID -SoftDeleteFeatureState Disable

It gives a result of Bad Request saying -SoftDeleteFeatureState does not exists for Set-AzRecoveryServicesVaultProperty

What may be possible ways to delete soft-delete enabled backup VM on the recovery services vault.

Aditya
  • 67
  • 1
  • 12

1 Answers1

1

So I replicated your problem as best as I could, this is what I did:

Create RSV, add VM into RSV with soft delete enabled, then deleted and had the VM in soft delete state. I went into the RSV and manually clicked undelete, which put the VM back into the RSV and then ran the below turn off soft delete:

Set-AzRecoveryServicesVaultProperty -VaultId "myvault" -SoftDeleteFeatureState Disable

I then ran the below to remove the VM from the vault and remove any associated backup data:

# VARIABLES
[String]$rgBackup = ""
[String]$vaultName = ""
# $vaultId = "[RECOVERY SERVICE VAULT ID]"

$vault = Get-AzRecoveryServicesVault -ResourceGroupName $rgBackup -Name $vaultName

$containerBackup = Get-AzRecoveryServicesBackupItem -BackupManagementType    AzureVM -WorkloadType AzureVM -VaultId $vault.ID | Where-Object {$_.DeleteState -eq "NotDeleted"}

$containerbackup| ForEach-Object -ThrottleLimit 10 -Parallel {write-host -fore green $_.name; Disable-AzRecoveryServicesBackupProtection -Item $_ -VaultId "" -RemoveRecoveryPoints -Force -Verbose} 

Write-Host "********************************* FIN *********************************************************"

And then I ran the below to force delete the RSV:

az backup vault delete --name --resource-group --force

You should just need to update RG and RSV names and IDs and hopefully it should work for you.

aph1997
  • 11
  • 2
  • Cloud Shell says "Set-AzRecoveryServicesVaultProperty -VaultId "myvault" -SoftDeleteFeatureState Disable" is BadRequest. And I seem be stuck with Undelete state even after executing the above 4 cmdlets – Aditya May 03 '23 at 18:41
  • Used this for the last cmdlet "$containerbackup| ForEach-Object -ThrottleLimit 10 -Parallel {write-host -fore green $_.name; Disable-AzRecoveryServicesBackupProtection -Item $_ -VaultId $vault.ID -RemoveRecoveryPoints -Force -Verbose} " - Still stuck with the VM. – Aditya May 03 '23 at 18:46
  • Tried again a few times.Still did not work – Aditya May 04 '23 at 11:30