Recovery Plans and Automated Failover
Create an ASR recovery plan that sequences VM failover across application tiers, add manual approval gates, and include pre- and post-failover scripts.
Recovery Plans and Automated Failover is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is an ASR Recovery Plan?
A Recovery Plan in Azure Site Recovery is a structured, ordered sequence of steps that orchestrates the failover of multiple VMs together. Rather than failing over each VM individually, a recovery plan groups them into groups that fail over in sequence — ensuring that infrastructure (database, middleware, web) comes up in the correct order, just as it would during initial deployment.
Creating a Recovery Plan
To create a recovery plan, you select the source site (primary region) and target site (secondary region), then add the VMs you want to include. The plan wizard automatically creates a default group, but you can add more groups to control the failover sequence. VMs in the same group fail over simultaneously; groups execute in numbered order.
# Create an ASR Recovery Plan via CLI:
az site-recovery recovery-plan create \
--resource-group myRG \
--vault-name myRecoveryVault \
--name myRecoveryPlan \
--primary-fabric-id '/subscriptions/.../replicationFabrics/eastus' \
--recovery-fabric-id '/subscriptions/.../replicationFabrics/westus' \
--groups '[{"groupType":"Boot","replicationProtectedItems":[...]}]'Sequencing Groups for Multi-Tier Apps
For a typical three-tier application, the recovery plan should have three groups:
- Group 1 — Database tier VMs (must start first)
- Group 2 — Application/middleware tier VMs
- Group 3 — Web frontend VMs (start last)
Each group waits for the previous group to complete failover successfully before starting. This mirrors the correct startup order and prevents web tier VMs from starting before the database is ready to accept connections.
Adding Manual Actions and Scripts
Recovery plans support pre-actions and post-actions at each group boundary. These can be:
- Manual actions — pause the failover and wait for a human to confirm (e.g., 'Verify database is ready')
- Azure Automation runbooks — automatically execute a script (e.g., update DNS records, disable maintenance mode)
Using Automation runbooks enables fully automated failover without human intervention for Tier 1 workloads.
# Example Automation runbook action in a recovery plan:
# Pre-group-2 action: Run runbook 'UpdateConnectionStrings'
# This runbook updates app config to point to secondary DB endpoint
# before the application tier VMs startUnplanned vs. Planned Failover
Azure Site Recovery supports two types of failover:
- Planned failover — initiated before a known event (e.g., data centre maintenance). The primary VM is shut down cleanly, data is synchronised, and then the secondary VM starts. No data loss.
- Unplanned failover — triggered during an actual disaster. The primary VM may be unavailable, so ASR uses the most recent replication checkpoint. Some data loss is possible depending on the RPO.
# Trigger an unplanned failover via CLI:
az site-recovery recovery-plan failover-unplanned \
--resource-group myRG \
--vault-name myRecoveryVault \
--name myRecoveryPlan \
--failover-direction PrimaryToRecoveryCommit and Failback
After a failover, the recovered VMs in the secondary region are in a pending commit state. You must commit the failover to confirm that the secondary site is now the active site and that you do not want to roll back. Once committed, you can set up reverse replication to protect the secondary site and eventually fail back to the primary region when it is restored.
# Commit the failover:
az site-recovery recovery-plan commit \
--resource-group myRG \
--vault-name myRecoveryVault \
--name myRecoveryPlan
# Then configure reverse replication to enable failback laterReprotect After Failover
After committing a failover, the replicated items in the original primary region are no longer actively replicated. To restore protection, you must reprotect the items — this reverses the replication direction so the new primary (formerly secondary) replicates to the original primary region. Reprotection takes time and should be initiated as soon as the original primary region is available again.
RTO Measurement in Recovery Plans
Every step in a recovery plan adds to the total RTO. Common time consumers include:
- VM startup time (2-5 minutes per VM)
- Application warm-up time (database connection pool initialisation, cache warming)
- DNS propagation after IP changes
- Manual approval gate wait times
Measure each step during test failovers and sum them to calculate your actual RTO versus your target.
Automating DNS Updates
After a failover, VMs in the secondary region have different IP addresses. For applications that expose a public DNS name, you must update DNS to point to the new IPs. Use an Azure Automation runbook as a post-failover action to update Azure DNS or Traffic Manager endpoint health to redirect traffic automatically — avoiding a manual step that could delay your RTO.
# Example: Update Azure DNS record in a runbook after failover:
# az network dns record-set a update \
# --resource-group dnsRG \
# --zone-name myapp.com \
# --record-set-name '@' \
# --set 'ARecords[0].ipv4Address=<new-secondary-ip>'Monitoring Recovery Plan Execution
During a failover, the Azure portal Jobs view in the Recovery Services vault shows real-time progress for each step in the recovery plan. You can see which group is executing, which VMs have successfully started, and whether any scripts or manual actions are pending. Monitoring this view allows the recovery team to intervene quickly if a step fails.
Recovery Plan Best Practices
Key best practices for recovery plans:
- Keep groups small (5-10 VMs) to limit blast radius if a group fails
- Use Automation runbooks instead of manual actions wherever possible to reduce RTO
- Document the expected startup time for each group so RTO can be calculated
- Run a test failover at least quarterly to validate the plan
- Review and update the plan whenever new VMs are added or application architecture changes
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: a recovery plan orchestrates the ordered failover of multiple VMs with pre/post actions at each group; unplanned failover uses the last replication checkpoint while planned failover has zero data loss; and after failover you must commit and reprotect to restore DR protection. Next up we explore how to test DR plans without impacting production.
Frequently asked questions
Is the “Recovery Plans and Automated Failover” lesson free?
Yes — the full text of “Recovery Plans and Automated Failover” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Recovery Plans and Automated Failover”?
Create an ASR recovery plan that sequences VM failover across application tiers, add manual approval gates, and include pre- and post-failover scripts. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Recovery Plans and Automated Failover” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Defining RTO, RPO, and Recovery Tiers
- Recovery Plans and Automated Failover
- DR Testing Without Impact
- DR for PaaS Services