Get Available Azure Backup Restore Point using powershell

Kalaimani Thirupathi 411 Reputation points
2021-05-13T15:59:57.707+00:00

Dear All,

I was trying a lot to get the available restore points in Azure backup can someone help me with this.

trying with the below one but it's not working

$subscriptions = Get-AzSubscription
ForEach ($Subscription in $Subscriptions) {
Set-AzContext -SubscriptionId $Subscription.Id
$RCvaults = get-azrecoveryservicesvault
ForEach ($RCvault in $RCvaults)
{
Set-AzRecoveryServicesVaultContext -Vault $RCvault
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $RCvault.ResourceGroupName -Name $RCvault.Name
$StartDate = (Get-Date).AddDays(-30
$EndDate = Get-Date
$Container = Get-AzRecoveryServicesBackupContainer -ContainerType AzureVM -Status Registered -VaultId $vault.ID
$BackupItem = Get-AzRecoveryServicesBackupItem -ContainerType AzureVM -VaultId $vault.ID
$RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $Startdate.ToUniversalTime() -EndDate $Enddate.ToUniversalTime() -VaultId $vault.ID
}
}

Azure Backup
Azure Backup

An Azure backup service that provides built-in management at scale.


2 answers

Sort by: Most helpful
  1. Reddy, Vempalli Naresh Kumar 0 Reputation points
    2026-10-26T05:43:38.79+00:00

    Hi This is vempalli Naresh kumar Reddy from TCS , just give the vm name in $conatiner with capital letter

    $container = "VMHOSTNAME"

    $container = "Hostname"
    #$container = Read-Host "Enter VM / Container name"
    # 1. Fetch data from Resource Graph (Fixed query nesting and PowerShell variable injection)
    $graphJson = az graph query -q "recoveryservicesresources | where type =~ 'microsoft.recoveryservices/vaults/backupfabrics/protectioncontainers/protecteditems' | where id contains '$container' | project rg=resourceGroup, vaultId=split(id, '/')[8]" --query "data"
    $graphResult = $graphJson | ConvertFrom-Json
    # 2. Safely parse variables and handle empty results
    if ($graphResult) {
        # If the graph returns multiple rows, select the first one to avoid breaking single-string variables
        $rg = $graphResult[0].rg
        $vault = $graphResult[0].vaultId
        
        Write-Host "Success! Found Container in Vault: $vault (RG: $rg)" -ForegroundColor Green
        
        # 3. Execute your query
        az backup recoverypoint list `
          --resource-group $rg `
          --vault-name $vault `
          --container-name $container `
          --item-name $container `
          --backup-management-type AzureIaasVM `
          --query "[].{name:name,recoverydate:properties.recoveryPointTime,expiryTime:properties.recoveryPointProperties.expiryTime}" `
          --output tsv
    } else {
        Write-Warning "Could not find any backup vault containing: $container"
    }
    
    

    Was this answer helpful?

    0 comments No comments

  2. Joshua 1 Reputation point
    2021-05-14T12:15:17.817+00:00

    I see some syntaxial issues so here is a chunk of code I used to take backups from an RSV and move them to a less expensive storage account. I used this for a client who had created several backup plans on a 5 TB premium storage account and realized that was a bad idea after his bill tripled.

    $RG = 'StorageSnapTest'
    $RSV = 'Backups-rsv'
    $RSV_RG = 'Management-rg'

    $stgSrc = 'stgautomationsource'
    $stgDst = 'stgautomationdest'
    $target = 'filesrecovered'

    $vault = Get-AzRecoveryServicesVault -ResourceGroupName $RSV_RG -Name $RSV
    $container = Get-AzRecoveryServicesBackupContainer -ContainerType AzureStorage -Status Registered -VaultId $vault.ID -FriendlyName $stgSrc
    $backupItem = Get-AzRecoveryServicesBackupItem -Container $container -WorkloadType AzureFiles -VaultId $vault.ID

    $rp = (Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupItem -VaultId $vault.ID)

    $context_acct = (Get-AzStorageAccount -ResourceGroupName $RG -Name $stgDst).Context

    foreach($snap in $rp) {
    [string] $uri = $snap.FileShareSnapshotUri
    [string] $restoreFolder = ($uri.Substring($uri.IndexOf("sharesnapshot=")).Replace(':', '_'))

    try { 
        (Get-AzStorageShare -Context $context_acct -Name $target) | New-AzStorageDirectory -Path $restoreFolder | Out-Null
    } catch {}
    
    $restoreJob = Restore-AzRecoveryServicesBackupItem -VaultLocation $vault.Location -RecoveryPoint $snap -TargetStorageAccountName $stgDst -TargetFileShareName $target -TargetFolder $restoreFolder -ResolveConflict Overwrite -VaultId $vault.ID
    

    }

    Was this answer helpful?

    0 comments No comments

Your answer

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