OnCallReadyStart learning

Azure Lesson 32.41 · Azure IV: Governance, Storage & Backup · 13 min read

Site Recovery: replicate, test, fail over, re-protect

In plain words

Site Recovery keeps a ready-to-start twin of your computer in another city. Every few minutes it sends the twin all the changes, so the twin is never more than a few minutes behind.

If the first city floods, you start the twin and carry on. Before that ever happens, you practise: start the twin in a closed room where it can't disturb anyone (a test failover), check it works, then put it away again.

Site Recovery: replicate, test, fail over, re-protect

Backup answers "give me yesterday's data". Azure Site Recovery (ASR) answers "the region is down, run the service somewhere else now". It replicates VMs continuously to another region, so a failover starts them there from a recovery point a few minutes old. Backup measures loss in hours, ASR in minutes. The exam tests the order of the steps. On-call, the step that matters is the test failover you did last quarter, which tells you whether the real one will work.

Need to know:

  • RPO (recovery point objective): how much data you may lose, i.e. how old the newest usable point is. RTO (recovery time objective): how long until the service is back. ASR: RPO of minutes (crash- consistent points every 5 minutes, app-consistent on a schedule), RTO = how long your VMs take to boot and your runbook takes to run.
  • Azure-to-Azure replication uses a Recovery Services vault in the target region: West Europe VMs, vault in North Europe. (The same vault type as Backup, a different job.)
  • A replicated VM needs the Site Recovery Mobility extension (installed for you), outbound access to the ASR service endpoints, and target resources: a resource group, a VNet (mapped to the source one), storage for the replicas (managed disks), optionally availability zones.
  • Recovery plans group VMs into failover order (database first, then app, then web) with scripts/runbooks and manual steps between groups.

The flow

StepWhat happensThen
Enable replicationinitial replication copies every disk to the target region, then changes stream continuouslythe VM is Protected
Test failovera copy of the VM starts in the target region in an isolated (test) network, from a point you pick; production keeps runningcheck the app, then Cleanup test failover
Failoverthe VM starts in the target region from a point (latest, latest processed, latest app-consistent, or custom); the source VM is shut down when possibleyou can still change the recovery point
Commitmakes the failover final: no more changing points
Re-protectreplication now runs from the target back to the source regionlater, fail back the same way, and re-protect again

There is no general-availability CLI for Azure-to-Azure Site Recovery (the site-recovery extension is a preview with long fabric/container/mapping JSON). It is done in the portal (or with PowerShell / REST in automation). In this lab: Console › Cloud portal › Backup and Site Recovery. Each button runs the command shown below.

Doing it

$ az group create -n rg-try-dr -l westeurope -o none
$ az group create -n rg-try-dr-ne -l northeurope -o none
$ az vm create -g rg-try-dr -n vm-try-orders --image Ubuntu2404 --size Standard_B2s --generate-ssh-keys -o none 2>/dev/null
$ az backup vault create -g rg-try-dr -n rsv-try-we -l westeurope -o none
$ az backup vault create -g rg-try-dr-ne -n rsv-try-ne -l northeurope -o none
$ VM=$(az vm show -g rg-try-dr -n vm-try-orders --query id -o tsv)
$ azportal asr enable --vm $VM --vault $(az backup vault show -g rg-try-dr -n rsv-try-we --query id -o tsv)
Replication cannot be enabled: the Recovery Services vault rsv-try-we is in westeurope, the same region as the VM. For Azure-to-Azure disaster recovery the vault must be in the target region (northeurope).
$ azportal asr enable --vm $VM --vault $(az backup vault show -g rg-try-dr-ne -n rsv-try-ne --query id -o tsv)
(simulator) portal action: replication of vm-try-orders to northeurope enabled (initial replication takes about 30 minutes; recovery points every 5 minutes after that)
$ azportal asr test-failover --vm $VM
Test failover cannot start: the initial replication of the VM has not completed.

The first attempt failed for the classic reason: the vault was in the same region as the VM. The test failover is refused until initial replication has finished (about half an hour here, longer for big disks).

After initial replication (the Console shows the replication health), the test, then the real thing:

$ azportal asr test-failover --vm $VM
(simulator) portal action: test failover of vm-try-orders done: vm-try-orders-test runs in northeurope in an isolated test network (cleanup removes it)
$ azportal asr cleanup-test --vm $VM
(simulator) portal action: test failover cleaned up
$ azportal asr failover --vm $VM
(simulator) portal action: failover of vm-try-orders to northeurope done: the source VM was shut down, vm-try-orders now runs in northeurope. Commit (or change the recovery point) next.
$ az vm get-instance-view -g rg-try-dr -n vm-try-orders --query "instanceView.statuses[1].displayStatus" -o tsv
VM deallocated
$ azportal asr commit --vm $VM
(simulator) portal action: failover committed: you can no longer change the recovery point. Re-protect to replicate back.
$ azportal asr reprotect --vm $VM
(simulator) portal action: re-protect started: vm-try-orders now replicates northeurope -> westeurope

What makes a failover actually work

The VMs coming up is the easy part. What breaks in real failovers:

  • Networking: the target VNet's address space, NSGs, UDRs and DNS. Clients must find the new addresses (DNS records with short TTLs, Traffic Manager or Front Door in front).
  • Everything that isn't the VM: the database (geo-replication or a failover group), storage (RA-GZRS or object replication), Key Vault, identity, the certificates. ASR replicates VMs, not your architecture. A recovery plan's scripts handle the rest.
  • Capacity: the target region needs quota for the VM sizes. Check it before the disaster.
  • Practice: a test failover per quarter, with the runbook written down and the RTO measured. The test failover is free of production impact, so there is no excuse to skip it.

On the exam (AZ-104 5.2.5, 5.2.6): vault in the target region, initial replication, recovery point types, test failover in an isolated network + cleanup, failover, commit, re-protect, fail back, recovery plans, RPO vs RTO, Backup vs Site Recovery.

In an interview: "What is the difference between Azure Backup and Site Recovery?" - "Backup keeps point-in-time copies for restores: an accidental delete, corruption, ransomware, an audit. It loses hours of data and a restore takes a while. Site Recovery replicates VMs continuously to another region for disaster recovery: RPO of minutes, and you fail over the running service, then re-protect and fail back later. Most production systems need both, and both only count if you have tested them: a restore drill for Backup, a test failover for Site Recovery."

What you can now do

  • Enable Azure-to-Azure replication with the vault in the target region.
  • Run a test failover, clean it up, fail over, commit and re-protect, in that order.
  • Explain RPO and RTO, and what besides the VMs a failover needs.

Why it helps

Backup gets data back; Site Recovery gets a running service back in another region within minutes. It is the core of most Azure VM disaster recovery plans, and the steps have a strict order that both the exam and a real failover punish you for getting wrong.

Test failovers are free of production impact, so the real question in an interview is always: when did you last run one?

Commands in this lesson

az

FAQ

Where does the vault for Site Recovery go?

In the target region. To protect West Europe VMs into North Europe, the Recovery Services vault lives in North Europe. A vault in the source region is refused for Azure-to-Azure replication. The target resource group and virtual network are chosen when you enable replication.

What is the difference between RPO and RTO?

RPO is how much data you can lose: the age of the newest usable recovery point (minutes with Site Recovery). RTO is how long until the service works again: boot time plus everything your runbook does (DNS, databases, checks).

Does a test failover affect production?

No. It starts a copy in an isolated test network in the target region from a recovery point, while production keeps running and replicating. Clean it up afterwards so the next test starts fresh. Test regularly.

What does commit do?

After a failover you can still change which recovery point the VM runs from. Commit makes the choice final. Re-protect is only possible after commit. Re-protect then starts replication in the other direction, towards the original region, so that you can fail back later.

Does Site Recovery fail over my database and DNS?

No, it replicates VMs. Databases need their own geo-replication or failover groups, storage its own redundancy or replication, and DNS or a global load balancer must point clients to the new addresses. Recovery plans with scripts tie those steps to the VM failover.

In an interview Mid

What is the difference between Azure Backup and Azure Site Recovery?

Backup keeps point-in-time copies for restores: an accidental delete, corruption, ransomware, an audit. It loses hours of data and a restore takes a while. Site Recovery replicates VMs continuously to another region for disaster recovery: RPO of minutes, and you fail over the running service, then re-protect and fail back later. Most production systems need both, and both only count if tested: a restore drill for Backup, a test failover for Site Recovery.

Also asked: What are RPO and RTO, and how do you measure them? · What steps does an Azure-to-Azure failover and failback involve? · What besides the VMs must a disaster recovery plan cover?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.