This Article guide about
How to configure VM backup in azure recovery vault?
Azure Recovery Services vault is place where you can keep your backup. This act as storage space on Azure.
It is used to keep data backup, as well as backup like SQL Server in case of Disaster Recovery scenarios.
Azure Recovery Services vault helps to centralize the backup process of your on-premises and Azure workload.
You can setup backup policy as per your requirement and also setup monitoring for backup status.
These backups can be used to restore in case there is any disaster occurred. These restore can be done at any point as per your backup solution.
Configuration of Azure Recovery Services vault can be done by portal or PowerShell scripting.
Azure Recovery Services vault pricing is depending on your backup selection type, retention, restore point etc.
How to configure VM backup in azure recovery vault? using PowerShell
Step1: Connect Azure account
#Step 1
Connect-AzAccount
Some time you will receive the term ‘Connect-AzAccount’ is not recognized as the name of a cmdlet, function, script file, or operable program. if you received this message AZ module is not installed on your machine.
This below error because AZ module is not installedConnect-AzAccount : The term 'Connect-AzAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:16 char:1+ Connect-AzAccount -Credential $Credential -Tenant $tenant -Subscripti ...+ ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-AzAccount:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
To install AZ module run below command and run above script to connect Azure subscription.
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -AllowClobber
Step2: Set Azure Subscription context
#Step 2
Set-AzContext -SubscriptionName "Visual Studio Enterprise with MSDN" #Change Subscription Name
Step3: Register provider for Recovery Vault
#Step 3
Register-AzResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"nName "Visual Studio Enterprise with MSDN" #Change Subscription Name
Step4: Verify if Registered provider for Recovery Vault
#Step 4
Get-AzResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"Subscription Name
Step5: Create and Get recovery vault
#Step 5
New-AzRecoveryServicesVault -Name "AzureSQLBackupVault" -ResourceGroupName "AzureBackup" -Location "EAST US"
Get-AzRecoveryServicesVault
Step6: Set recovery vault context
#Step 6
Get-AzRecoveryServicesVault -Name "AzureSQLBackupVault" | Set-AzRecoveryServicesVaultContext
Step7: Fetch the vault ID
#Step 7
$testVault = Get-AzRecoveryServicesVault -ResourceGroupName "AzureBackup" -Name "AzureSQLBackupVault"
$testVault.ID
Step8:Configure Backup policy
#Step 8 : YOu can change workload type as per your VM type. In this script used MSSQL VM
$schPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "MSSQL"
$UtcTime = (Get-Date -Date "2022-07-30 01:30:00Z").ToUniversalTime()
$schPol.FullBackupSchedulePolicy.ScheduleRunTimes[0] = $UtcTime
$schPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "MSSQL"
$retPol = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType "MSSQL"
New-AzRecoveryServicesBackupProtectionPolicy -Name "NewSQLPolicy" -WorkloadType "MSSQL" -RetentionPolicy $retPol -SchedulePolicy $schPol
Step9: Change the storage redundancy configuration (LRS/GRS) of the vault
#Step 9
Get-AzRecoveryServicesVault `
-Name "myRecoveryServicesVault" | Set-AzRecoveryServicesBackupProperty -BackupStorageRedundancy LocallyRedundant/GeoRedundant
Step10: Register VM for backup
#Step 10
$myVM = Get-AzVM -ResourceGroupName "AzureBackup" -Name "SQL2019"
Register-AzRecoveryServicesBackupContainer -ResourceId $myVM.ID -BackupManagementType AzureWorkload -WorkloadType MSSQL -VaultId $testVault.ID -Force
Step11: Fetch databases from server
#Step 11
Get-AzRecoveryServicesBackupProtectableItem -WorkloadType MSSQL -VaultId $testVault.ID
Step12: Configure Backup
#Step 12
$SQLDB = Get-AzRecoveryServicesBackupProtectableItem -workloadType MSSQL -ItemType SQLDataBase -VaultId $testVault.ID -Name "sqldatabase;mssqlserver;master" -ServerName "sql2019"
Enable-AzRecoveryServicesBackupProtection -ProtectableItem $SQLDB -Policy $NewPolicy