Azure Backup vaults – New era of snapshot backups – backup every 1h

If you think about backup in Azure – probably you think about Recovery Services vaults. But there is currently a new possibility named Backup vaults. Of the box, you can configure backups every 4 hours. Currently, it supports:

VM Managed Disk Backups (Snapshot)

Azure Blobs

Azure PostgreSQL Databases

You can create ad-hock backups using portal or PowerShell. If you using PowerShell and see an error like:

Backup-AzDataProtectionBackupInstanceAdhoc : Input provided for the call is invalid

Probably you are using wrong parameter for -BackupRuleOptionRuleName it should be:

-BackupRuleOptionRuleName “BackupDaily”

Or

-BackupRuleOptionRuleName “Daily”

Note “Default” like mentioned in Documentation.

Here is a code that can be implemented in the Azure function to do backup every 1h.

param($Timer)

Install-Module -Name Az.ResourceGraph -Force

Import-Module -Name Az.DataProtection
Import-Module -Name Az.ResourceGraph
Get-InstalledModule
$VaultBackupRG=”xxxx”
$VaultBackupName=”xxxx”
$AzureFunctionAppID = “xxxx”
$AzureFunctionAppPwd = “xxxx”
$TennantId = “xxxx”
$SubscrybtionDev=”xxxx”
$User = $AzureFunctionAppID
$Pass = ConvertTo-SecureString -String $AzureFunctionAppPwd -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential $User,$Pass
# Get the current universal time in the default string format.
Write-Host “Logging to Azure….”
Connect-AzAccount -Credential $Credential -TenantId $TennantId -ServicePrincipal
Set-AzContext -Subscription $SubscrybtionDev
Write-Host “Logged In and Starting Processing….”
$AllInstances = Get-AzDataProtectionBackupInstance -ResourceGroupName $VaultBackupRG -VaultName $VaultBackupName
Backup-AzDataProtectionBackupInstanceAdhoc -BackupInstanceName $AllInstances[0].Name -ResourceGroupName $VaultBackupRG -VaultName $VaultBackupName -BackupRuleOptionRuleName “BackupDaily”
$job = Search-AzDataProtectionJobInAzGraph -Subscription $SubscrybtionDev -ResourceGroup $VaultBackupRG -Vault $VaultBackupName -DatasourceType AzureDisk -Operation OnDemandBackup
Write-Host “Snapshots:”
Write-Host $job

requirements.psd1 file:

@{
# For latest supported version, go to ‘https://www.powershellgallery.com/packages/Az’.
# To use the Az module in your function app, please uncomment the line below.
# ‘Az’ = ‘6.*’
‘Az’ = ‘6.4.0’
‘Az.DataProtection’= ‘0.3.0’
‘Az.ResourceGraph’ = ‘0.11.0’
}

The line Install-Module -Name Az.ResourceGraph -Force is needed to avoid this error:

EXCEPTION: Az.ResourceGraph Module must be installed to run this command. Please run ‘Install-Module -Name Az.ResourceGraph’ to install and continue. Exception : Type : System.Management.Automation.RuntimeException