Backup and Restore for Azure Virtual Machines
Azure Backup provides simple, secure, and cost‑effective solutions to protect your Virtual Machines (VMs). This article explains how to enable backup, manage recovery points, and restore VMs using the Azure portal, Azure CLI, and Azure PowerShell.
Prerequisites
- An Azure subscription with appropriate permissions (Owner or Contributor on the target resource group).
- Azure VM(s) running a supported OS (Windows Server 2012‑2022, Linux distributions listed here).
- A Recovery Services vault in the same region as the VM.
Configure backup
- Navigate to Backup in the Azure portal.
- Select +Create a Recovery Services vault, choose a name and region, then click Review + create.
- After the vault is created, go to Backup → Backup Goal → Azure Virtual Machine → Backup Policy.
- Choose an existing policy or create a new one (e.g., daily backup at 2 AM, retain 30 days).
- Select the VM(s) you want to protect and click Enable backup.
Restore a VM
To restore, you can perform a full VM restore or a file‑level restore from a recovery point.
Full VM restore (Azure portal)
- Open the Recovery Services vault → Backup items → Azure Virtual Machine.
- Select the VM and click Restore VM.
- Choose a recovery point, target resource group, and virtual network.
- Click Restore to create the new VM.
File‑level restore (CLI)
# List available recovery points
az backup recoverypoint list \
--resource-group MyResourceGroup \
--vault-name MyRecoveryVault \
--container-name IaasVMContainer;iaasvmcontainerv2;myResourceGroup;myVM \
--item-name myVM \
--query "[].{Name:name, Time:recoveryPointTime}" -o table
# Mount the recovery point and copy files
az backup restore restore-disks \
--resource-group MyResourceGroup \
--vault-name MyRecoveryVault \
--container-name IaasVMContainer;iaasvmcontainerv2;myResourceGroup;myVM \
--item-name myVM \
--recovery-point-id \
--restore-to-staging-storage-account true
Azure CLI samples
# Enable backup for a VM
az backup protection enable-for-vm \
--resource-group MyResourceGroup \
--vault-name MyRecoveryVault \
--vm myVM \
--policy-name DefaultPolicy
# List backups
az backup protection show \
--resource-group MyResourceGroup \
--vault-name MyRecoveryVault \
--vm myVM
Azure PowerShell samples
# Install the Az.RecoveryServices module if not present
Install-Module -Name Az.RecoveryServices -Force
# Connect to Azure
Connect-AzAccount
# Enable backup
$vault = Get-AzRecoveryServicesVault -Name "MyRecoveryVault"
Set-AzRecoveryServicesVaultContext -Vault $vault
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name "DefaultPolicy"
Enable-AzRecoveryServicesBackupProtection -Vault $vault -Policy $policy -ResourceGroupName "MyResourceGroup" -VMName "myVM"
# Trigger an on-demand backup
Backup-AzRecoveryServicesBackupItem -Item (Get-AzRecoveryServicesBackupItem -Vault $vault -WorkloadType "AzureVM" -Name "myVM")
Troubleshooting
- Backup fails with error 0x8000FFFF: Verify that the VM's boot diagnostics are enabled and that the VM has a managed disk.
- Unable to restore a VM: Ensure the target region has enough quota for the chosen VM size.
- Missing recovery points: Check the backup policy retention settings and verify the vault's storage redundancy.