0

Estoy tratando de eliminar todos los backup items de un recovery service vault usando powershell. He encontrado un script pero este script elimina item por item esperando a que el primero se termine de eliminar para pasar al siguiente. Me gustaría modificar el script para, por ejemplo, ordenarle a Azure que elimine el item y pase al siguiente mientras el anterior se está eliminando. Intenté usar el flag -AsJob pero powershell no lo reconoce (lo tengo comentado en el código). Estoy usando la versión 5 de powershell. Tengo que eliminar cientos o miles de backup items por lo que ir uno a uno no es una opción.

¿Podrían ayudarme?

## Variables
$rgBackup = Read-Host -Prompt "Introduce el nombre del resource group"

$vaultName = Read-Host -Prompt "Introduce el nombre del recovery service vault" 

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

$count = 0
 
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ## Disable soft delete for the Azure Backup Recovery Services vault

Set-AzRecoveryServicesVaultProperty -Vault $vault.ID -SoftDeleteFeatureState Disable

Write-Host ($writeEmptyLine + " # Soft delete disabled for Recovery Service vault " + $vault.Name)`

## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Check if there are backup items in a soft-deleted state and reverse the delete operation

$containerSoftDelete = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureWorkload -WorkloadType MSSQL  -VaultId $vault.ID | Where-Object {$_.DeleteState -eq "ToBeDeleted"}

foreach ($item in $containerSoftDelete) {

    Undo-AzRecoveryServicesBackupItemDeletion -Item $item -VaultId $vault.ID -Force -Verbose

}

Write-Host ($writeEmptyLine + "# Undeleted all backup items in a soft deleted state in Recovery Services vault " + $vault.Name)

## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Stop protection and delete data for all backup-protected items

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

foreach ($item in $containerBackup) {

    Disable-AzRecoveryServicesBackupProtection -Item $item -VaultId $vault.ID -RemoveRecoveryPoints -Force -Verbose #-AsJob

    $count++

    Write-Host "$count - Item has been deleted"

}

Write-Host ($writeEmptyLine + "# Deleted backup date for all cloud protected items in Recovery Services vault " + $vault.Name)`

1 respuesta 1

0

Pude solventar el problema con este script, aunque puede ser mejorado:

# Powershell version >= 7.0
# Si al eliminar da error de formato de fecha, probar a lanzarlo desde una VM ubicada en North Europe en inglés ya que en algunas máquinas no da este error.

# Autenticarse en Azure
Connect-AzAccount -Tenant "[TENANT ID]"

Set-AzContext -SubscriptionId "[SUBSCRIPTION ID]"

# VARIABLES
[String]$rgBackup = "[RG]"
[String]$vaultName = "[RECOVERY SERVICE VAULT NAME]"
# $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 "[RECOVERY SERVICE VAULT ID WITHOUT VARIABLES]" -RemoveRecoveryPoints -Force -Verbose} 

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

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.