Overview and What You Will Learn
Azure Backup stores recovery points for your VMs in a Recovery Services Vault according to a backup policy, and a backup is only proven when you restore from it and check the result. In this lab you will create a vault, protect a VM with a retention policy, trigger a backup, restore its disks to a separate resource group, and boot a new VM from them to confirm a marker file survived.
- Creating a Recovery Services Vault and enabling VM backup
- Reading a backup policy's schedule and retention
- Triggering an on-demand backup and finding its recovery points
- Restoring disks to an alternate location, never over the live VM
- Verifying the restore by booting a VM and reading test data
Why This Matters in Production
A successful backup job proves only that data was written to the vault, not that it can be restored into a working system. Imagine a fintech team at a company like Stripe that sees nightly backup jobs succeed for a year, then finds during a real data-loss incident that a critical table was never captured. Teams that rehearse restores find those gaps on a quiet afternoon instead of during an outage.
Core Principles
A Recovery Services Vault holds the backup policy and every recovery point created under it. The policy sets how often backups run and how long recovery points are kept, and each recovery point is the VM's data as of one moment. A restore is the only step that shows whether any of it is usable.
daily, 30-day retention]:::tool P --> R[Recovery points]:::soft R --> D[Restore disks
to alternate group]:::ok D --> T([Boot test VM
and verify data]):::warn classDef tool fill:#326CE5,color:#FFFFFF classDef soft fill:#DBEAFE,color:#1E293B classDef ok fill:#10B981,color:#FFFFFF classDef warn fill:#FFEDD5,color:#1E293B
A VM backup is crash-consistent or file-system consistent by default. Databases running inside a VM need application-aware backup, such as the vault's SQL Server in Azure VM support or the database service's own backups, or the restored data may need recovery before it opens cleanly.
Detailed Step-by-Step Practical Lab
- Create a resource group, a Recovery Services Vault, and a VM to back up:
az group create --name rg-backup-lab-central --location centralindia az backup vault create \ --resource-group rg-backup-lab-central \ --name rsv-backup-lab \ --location centralindia az vm create \ --resource-group rg-backup-lab-central \ --name vm-backup-lab \ --image Ubuntu2204 \ --size Standard_B1s \ --admin-username azureadmin \ --generate-ssh-keys- Write a marker file onto the VM. After the restore you will look for it to prove the data came back:
az vm run-command invoke \ --resource-group rg-backup-lab-central \ --name vm-backup-lab \ --command-id RunShellScript \ --scripts "echo 'ORD-48214 restore marker' | sudo tee /home/azureadmin/restore-marker.txt"- Review the default policy, then enable backup protection for the VM:
az backup policy show \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --name DefaultPolicy az backup protection enable-for-vm \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --vm vm-backup-lab \ --policy-name DefaultPolicy- Trigger an on-demand backup instead of waiting for the schedule, retained for 30 days:
az backup protection backup-now \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --container-name vm-backup-lab \ --item-name vm-backup-lab \ --retain-until $(date -u -d "+30 days" '+%d-%m-%Y')- Check the job until it shows Completed. The first backup of a VM can take 20 minutes or more:
az backup job list \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --output table- List the recovery points for this VM:
az backup recoverypoint list \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --container-name vm-backup-lab \ --item-name vm-backup-lab \ --output table- Create a separate resource group and a storage account to restore into:
az group create --name rg-restore-lab-central --location centralindia STORAGE=stbackuprestore$RANDOMaz storage account create \ --name "$STORAGE" \ --resource-group rg-restore-lab-central \ --location centralindia \ --sku Standard_LRSSecurityAlways restore to an alternate location during a test. Restoring to the original location replaces the disks of the live VM, which turns a test into an outage.
- Restore the disks from the newest recovery point into the separate resource group:
RP=$(az backup recoverypoint list \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --container-name vm-backup-lab \ --item-name vm-backup-lab \ --query "[0].name" --output tsv) az backup restore restore-disks \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --container-name vm-backup-lab \ --item-name vm-backup-lab \ --rp-name "$RP" \ --storage-account "$STORAGE" \ --restore-mode AlternateLocation \ --target-resource-group rg-restore-lab-central- When the restore job completes, build a VM from the restored OS disk and read the marker file. This verification is what actually proves the backup:
OSDISK=$(az disk list \ --resource-group rg-restore-lab-central \ --query "[?contains(name,'OsDisk')].name | [0]" --output tsv) az vm create \ --resource-group rg-restore-lab-central \ --name vm-restored \ --attach-os-disk "$OSDISK" \ --os-type linux \ --size Standard_B1s az vm run-command invoke \ --resource-group rg-restore-lab-central \ --name vm-restored \ --command-id RunShellScript \ --scripts "cat /home/azureadmin/restore-marker.txt" \ --query "value[0].message" --output tsv- Clean up. A vault with backup items cannot be deleted, and soft delete keeps deleted backups for 14 days by default, so turn it off and remove the backup data first:
az backup vault backup-properties set \ --resource-group rg-backup-lab-central \ --name rsv-backup-lab \ --soft-delete-feature-state Disable az backup protection disable \ --resource-group rg-backup-lab-central \ --vault-name rsv-backup-lab \ --container-name vm-backup-lab \ --item-name vm-backup-lab \ --delete-backup-data true --yes az group delete --name rg-restore-lab-central --yes --no-waitaz group delete --name rg-backup-lab-central --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakeConfiguring backups, watching the job report success, and never performing a test restore. A completed job proves data reached the vault, not that it can be brought back into a working state when it is needed.
TipSchedule a real restore test on a calendar, quarterly is a sensible starting point, and write down how long it took. That number is your real recovery time, which is what the business needs to know.
SecurityBackups are a target in ransomware attacks. Keep soft delete on in production and protect the vault with Resource Guard so that deleting backup data needs approval from a second person.
- Match retention to real requirements. A workload with a 7-year regulatory retention need requires a policy built for that, not the default 30-day window.
- Control who can delete backups. The vault has its own access controls, so grant backup deletion rights to as few identities as possible.
- Know the default storage redundancy. New vaults use geo-redundant storage, which costs more than locally redundant storage but allows cross-region restore. Choose deliberately before protecting the first item.
- Monitor failures, not just successes. Send backup alerts to a channel someone watches, since a silent failure looks identical to a quiet week.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az backup vault create |
Create a Recovery Services Vault |
az backup protection enable-for-vm |
Enable backup for a specific VM |
az backup protection backup-now |
Trigger an on-demand backup |
az backup recoverypoint list |
List available recovery points |
az backup restore restore-disks |
Restore disks from a recovery point |
az backup job list |
Check backup and restore job status |