3.1.4.5. Configure Azure Site Recovery for Azure VMs
3.1.4.5. Configure Azure Site Recovery for Azure VMs
💡 First Principle: A backup lets you rebuild a VM from yesterday; replication keeps a copy that is only minutes behind and ready to boot somewhere else. Azure Site Recovery exists for the second job: it continuously copies a VM's disk writes to another region so that a regional outage costs you minutes of data, not a day.
Scenario: Your order-processing VMs run in East US. The business requires that they can be running in West US 2 within an hour of an East US outage, with no more than a few minutes of lost data, and the database tier must recover to a point that SQL Server considers consistent. You need to set up the replication, decide how long recovery points are kept, and make sure the three tiers start in the right order after a failover.
What It Is: Azure Site Recovery (ASR) for Azure VMs ("Azure-to-Azure") continuously replicates Azure VMs from a source region to a target region. If the source region fails, you fail the VMs over and run them from the target; when the source recovers, you fail back. Site Recovery is managed from a Recovery Services vault, the same resource type Azure Backup uses (3.1.4.1).
The Moving Parts (architecture)
| Component | What you need to know |
|---|---|
| Recovery Services vault | Create it in any region except the source region. In practice you put it in the target region, so it survives the outage it protects against. |
| Cache storage account | Lives in the source region. Disk writes land here first and are then sent to the target, which keeps replication from slowing the production VM. A standard account is used by default; the High Churn option uses a Premium Block Blob account for VMs with a high data change rate. |
| Mobility service extension | Installed on the VM automatically when you enable replication. It registers the VM with Site Recovery; you don't install an agent yourself. |
| Replica managed disks | Created in the target region with an -ASRReplica suffix. Source VMs must use managed disks. |
| Target resources | By default Site Recovery creates a target resource group, VNet, and (if the source uses one) availability set, each with an asr suffix. You can choose existing ones instead. |
Replication needs only outbound connectivity from the VM (HTTPS 443 to Storage, Microsoft Entra ID, Event Hubs, and the AzureSiteRecovery service tag); Site Recovery never needs inbound access to the VM.
Replication Policy
When you enable replication, Site Recovery creates a replication policy with these defaults, which you can change at enable time or replace with a policy you create first:
| Setting | Default | Meaning |
|---|---|---|
| Recovery point retention | One day | How far back you can pick a recovery point at failover. Longer retention keeps more points and costs more storage. |
| App-consistent snapshot frequency | 0 hours (disabled) | How often a VSS-based snapshot that flushes in-memory and in-flight transactions is taken. Keep it shorter than the retention period. |
| Crash-consistent recovery points | Every 5 minutes | Created automatically and can't be modified. Equivalent to pulling the power cord: on-disk data only. |
A database server is the classic case for turning on app-consistent snapshots, because a crash-consistent point doesn't guarantee consistency for the apps on the VM. App-consistent snapshots take longer and affect the VM's performance, so don't take them more often than you need. If several VMs must recover to the same point in time, put them in a replication group (multi-VM consistency); this also costs performance, so use it only for workloads that genuinely need it.
Enabling Replication (portal)
In the vault, select Enable Site Recovery, then under Azure virtual machines select Enable replication and work through the tabs: Source (region, subscription, resource group), Virtual machines (up to 10 per run), Replication settings (target region, subscription, resource group, VNet, availability option, storage), Manage (replication policy, replication group, and the extension update settings with an Automation account), then Review. The VM appears under Replicated items.
Two settings deserve care:
- Network mapping decides which target VNet a source VNet fails over to. If you pick a target network while enabling replication, Site Recovery creates the mapping in both directions automatically. You can also create it beforehand under Site Recovery infrastructure > Network mapping. The target subnet is chosen by matching the source subnet's name; if the address spaces match, the target NIC gets the same IP when it's available.
- Availability option (single instance, availability set, or availability zone) is the one target setting you can't change after replication starts. Other target settings, including the target VM size, can be edited later. Changing the availability type means disabling replication and enabling it again.
Recovery Plans
A recovery plan orders the failover of several machines. Machines start in Group 1 by default; you can add groups (up to seven), and groups start in order while machines inside one group start in parallel. That is how you bring up the SQL tier, then middleware, then the web front end. A plan holds up to 100 protected instances, and all VMs in one plan must replicate into a single subscription. You can add pre- and post-actions to each group: for Azure-to-Azure these are Azure Automation runbooks (for example, to attach a public IP or an NSG after failover), plus manual actions, which pause the plan until someone confirms the step is done. Scripts stored on a VMM server apply only to Hyper-V scenarios.
Practical Implementation: Vault, Policy, and Cache Account with PowerShell
# Vault in the recovery region (West US 2), not the source region
$vault = New-AzRecoveryServicesVault -Name "a2aDemoRecoveryVault" `
-ResourceGroupName "a2ademorecoveryrg" -Location "West US 2"
Set-AzRecoveryServicesAsrVaultContext -Vault $vault
# Policy: keep 24 hours of recovery points, app-consistent snapshot every 4 hours
New-AzRecoveryServicesAsrPolicy -AzureToAzure -Name "A2APolicy" `
-RecoveryPointRetentionInHours 24 -ApplicationConsistentSnapshotFrequencyInHours 4
# Cache storage account in the SOURCE region (East US)
New-AzStorageAccount -Name "a2acachestorage" -ResourceGroupName "A2AdemoRG" `
-Location "East US" -SkuName Standard_LRS -Kind Storage
The full PowerShell flow also creates fabric objects, protection containers, container mappings, and network mappings before New-AzRecoveryServicesAsrReplicationProtectedItem starts replication; the portal does all of that for you.
Visual: Azure-to-Azure Replication Path
⚠️ Common Pitfall: Leaving the default policy on a database VM. App-consistent snapshots are disabled by default, so every recovery point is crash-consistent, and the database has to run crash recovery after failover.
⚠️ Exam Trap: Azure Backup and Site Recovery share the vault type, but they answer different questions. Backup restores data from a point in time (often in the same region); Site Recovery keeps a running copy in another region for failover. Also remember where things live: the vault goes in a region other than the source, while the cache storage account sits in the source region.
Key Trade-Offs:
- Retention vs. Cost: More hours of recovery points widen your choice at failover but store more data.
- App-Consistency vs. Performance: App-consistent snapshots give clean database recovery but take longer and load the VM; crash-consistent points are free and frequent.
- Multi-VM Consistency vs. Performance: Shared recovery points across VMs simplify recovering a distributed app but reduce workload performance.
Reflection Question: For a three-tier app whose SQL Server VM must recover to a consistent state, which replication policy settings, replication group choices, and recovery plan groups would you configure, and why does the vault's region matter?