Azure Backup failure Retry using Automation

Kalaimani Thirupathi 411 Reputation points
2021-07-09T13:56:48.503+00:00

Dear All,

I'm looking for some way to re-run the failed azure backup using Powershell or azure run book. Kindly someone help with this, please

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,258 questions
{count} votes

2 answers

Sort by: Most helpful
  1. SadiqhAhmed-MSFT 45,181 Reputation points Microsoft Employee
    2021-07-12T08:48:10.893+00:00

    @Kalaimani Thirupathi Below is the PowerShell script used in the runbook that was described in the video. The script runs an ARG query to look for all VMs with failed jobs and then triggers an ad-hoc backup for each of the VMs.

    $connection = Get-AutomationConnection -Name AzureRunAsConnection  
    $connectionResult = Connect-AzAccount `  
    -ServicePrincipal `  
    -Tenant $connection.TenantID `  
    -ApplicationId $connection.ApplicationID `  
    -CertificateThumbprint $connection.CertificateThumbprint  
    "Login successful.."  
      
    get-azcontext  
      
    $query = "RecoveryServicesResources   
    | where type in~ ('microsoft.recoveryservices/vaults/backupjobs')  
    | extend vaultName = case(type =~ 'microsoft.dataprotection/backupVaults/backupJobs',properties.vaultName,type =~ 'Microsoft.RecoveryServices/vaults/backupJobs',split(split(id, '/Microsoft.RecoveryServices/vaults/')[1],'/')[0],'--')  
    | extend friendlyName = case(type =~ 'microsoft.dataprotection/backupVaults/backupJobs',strcat(properties.dataSourceSetName , '/', properties.dataSourceName),type =~ 'Microsoft.RecoveryServices/vaults/backupJobs', properties.entityFriendlyName, '--')  
    | extend dataSourceType = case(type =~ 'Microsoft.RecoveryServices/vaults/backupJobs',properties.backupManagementType,type =~ 'microsoft.dataprotection/backupVaults/backupJobs',properties.dataSourceType,'--')  
    | extend protectedItemName = split(split(properties.backupInstanceId, 'protectedItems')[1],'/')[1]  
    | extend vaultId = tostring(split(id, '/backupJobs')[0])  
    | extend vaultSub = tostring( split(id, '/')[2])  
    | extend jobStatus = case (properties.status == 'Completed' or properties.status == 'CompletedWithWarnings','Succeeded',properties.status == 'Failed','Failed',properties.status == 'InProgress', 'Started', properties.status), operation = case(type =~ 'microsoft.dataprotection/backupVaults/backupJobs' and tolower(properties.operationCategory) =~ 'backup' and properties.isUserTriggered == 'true',strcat('adhoc',properties.operationCategory),type =~ 'microsoft.dataprotection/backupVaults/backupJobs', tolower(properties.operationCategory), type =~ 'Microsoft.RecoveryServices/vaults/backupJobs' and tolower(properties.operation) =~ 'backup' and properties.isUserTriggered == 'true',strcat('adhoc',properties.operation),type =~ 'Microsoft.RecoveryServices/vaults/backupJobs',tolower(properties.operation), '--'),startTime = todatetime(properties.startTime),endTime = properties.endTime, duration = properties.duration   
    | where startTime >= ago(24h)  
    | where (dataSourceType in~ ('AzureIaasVM'))  
    | where jobStatus=='Failed'  
    | where operation == 'backup' or operation == 'adhocBackup'  
    | project vaultSub, vaultId, protectedItemName, startTime, endTime, jobStatus, operation  
    | sort by vaultSub"  
      
    $subscriptions = Get-AzSubscription | foreach {$_.SubscriptionId}  
      
    $result = Search-AzGraph -Subscription $subscriptions -Query $query -First 5  
      
    $result = $result.data  
      
    $result[0]  
      
    $prevsub = ""  
    foreach($jobresponse in $result)  
    {  
                  if($jobresponse.vaultSub -ne $prevsub)  
                  {  
                               Set-AzContext -SubscriptionId $jobresponse.vaultSub  
                               $prevsub = $jobresponse.vaultSub  
                  }  
      
                  $item = Get-AzRecoveryServicesBackupItem -VaultId $jobresponse.vaultId -BackupManagementType AzureVM -WorkloadType AzureVM -Name $jobresponse.protectedItemName  
      
                  Backup-AzRecoveryServicesBackupItem -ExpiryDateTimeUTC (get-date).AddDays(10) -Item $item -VaultId $jobresponse.vaultId  
      
    }  
    

    Hope this helps!

    ---------------------------------------------------------------------------------------------------------------

    If the response helped, do "Accept Answer" and up-vote it.


  2. SadiqhAhmed-MSFT 45,181 Reputation points Microsoft Employee
    2021-07-26T06:13:57.273+00:00

    @Kalaimani Thirupathi You can use the below ARG query to get the latest backup job for each VM. In the PS script shared earlier, replace the contents of the highlighted line with the below ARG query.

    $query = “RecoveryServicesResources   
    | where type in~ ('microsoft.recoveryservices/vaults/backupjobs')  
    | extend vaultName = case(type =~ 'microsoft.dataprotection/backupVaults/backupJobs',properties.vaultName,type =~ 'Microsoft.RecoveryServices/vaults/backupJobs',split(split(id, '/Microsoft.RecoveryServices/vaults/')[1],'/')[0],'--')  
    | extend friendlyName = case(type =~ 'microsoft.dataprotection/backupVaults/backupJobs',strcat(properties.dataSourceSetName , '/', properties.dataSourceName),type =~ 'Microsoft.RecoveryServices/vaults/backupJobs', properties.entityFriendlyName, '--')  
    | extend dataSourceType = case(type =~ 'Microsoft.RecoveryServices/vaults/backupJobs',properties.backupManagementType,type =~ 'microsoft.dataprotection/backupVaults/backupJobs',properties.dataSourceType,'--')  
    | extend protectedItemName = split(split(properties.backupInstanceId, 'protectedItems')[1],'/')[1]  
    | extend vaultId = tostring(split(id, '/backupJobs')[0])  
    | extend vaultSub = tostring( split(id, '/')[2])  
    | extend jobStatus = case (properties.status == 'Completed' or properties.status == 'CompletedWithWarnings','Succeeded',properties.status == 'Failed','Failed',properties.status == 'InProgress', 'Started', properties.status), operation = case(type =~ 'microsoft.dataprotection/backupVaults/backupJobs' and tolower(properties.operationCategory) =~ 'backup' and properties.isUserTriggered == 'true',strcat('adhoc',properties.operationCategory),type =~ 'microsoft.dataprotection/backupVaults/backupJobs', tolower(properties.operationCategory), type =~ 'Microsoft.RecoveryServices/vaults/backupJobs' and tolower(properties.operation) =~ 'backup' and properties.isUserTriggered == 'true',strcat('adhoc',properties.operation),type =~ 'Microsoft.RecoveryServices/vaults/backupJobs',tolower(properties.operation), '--'),startTime = todatetime(properties.startTime),endTime = properties.endTime, duration = properties.duration   
    | where (dataSourceType in~ ('AzureIaasVM'))  
    | where jobStatus=='Failed'  
    | where operation == 'backup' or operation == 'adhocBackup'  
    | project vaultSub, vaultId, protectedItemName=tostring(protectedItemName), startTime, endTime, jobStatus, operation  
    | summarize arg_max(startTime,*) by protectedItemName, vaultId  
    | sort by vaultSub”  
    

    117844-image.png

    ---------------------------------------------------------------------------------------------------------------

    If the response helped, do "Accept Answer" and up-vote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.