JeffreyO
JeffreyO

Reputation: 23

Is there a method using Powershell to remove a "Backup Item" from within a vault in Azure?

I'm currently running into a bit of a problem with Azure. My organization has several Recovery Service Vaults, one of which contians 6 backup items, within these items there are varying numbers of backups. One that I need to remove contains backups for SQL databases (not VM's, SQL DB backups). The only method through the GUI to remove these is doing them one at a time but we have hundreds that need to go.

I have done some research but couldn't find a method in removing a specific backup item, just click methods for removing backups from within the Backup Item one at a time through the point and click method. I have found powershell solutions for removing the entire vault but as there are backup items in there we want to preserve, this won't work.

Does anyone know of a powershell method to remove an entire backup item or at least remove all the backups from within a backup item so that I may then manually remove the backup item instead of going through hundreds of these through ye' ol' point-and-click?

Upvotes: 0

Views: 2441

Answers (2)

Charles Groleau
Charles Groleau

Reputation: 21

For SQL in Azure VM you can use the following.

$vault = Get-AzureRmRecoveryServicesVault -ResourceGroupName "ressource group name" -Name "vault name"
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
$containers = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVMAppContainer -Status Registered

foreach ($container in $containers)
{
    $items = Get-AzureRmRecoveryServicesBackupItem -Container $container -WorkloadType MSSQL
    foreach ($item in $items)
    {
        Disable-AzureRmRecoveryServicesBackupProtection -item $item -RemoveRecoveryPoints -Force
    }
}

Upvotes: 2

4c74356b41
4c74356b41

Reputation: 72171

this is the snippet I was using to delete Azure SQL long term backups:

# We need to set recovery services context to work with recovery vault
$vault = Get-AzureRmRecoveryServicesVault -Name %VaultName%
Set-AzureRmRecoveryServicesVaultContext -Vault $vault
# Get protection containers to work with those
$containers = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureSQL -Status Registered
$item = Get-AzureRmRecoveryServicesBackupItem -Container $containers -WorkloadType AzureSQLDatabase
$availableBackups = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $item
$availableBackups # check existing items
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
}

I'm not sure what would be the type for SQL backup for Azure Backup, though. AzureVm, probably.

Upvotes: 0

Related Questions