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.
1,192 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 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
    

    }

    0 comments No comments