When to Embed Disaster Recovery in CI/CD Pipelines

When to put disaster recovery in CI/CD: RTO/RPO signals, four automation levels, backup restore tests, rebuilds from code, failover drills and AWS FIS.

Aug 21, 2025 - 14:24
Nov 15, 2026 - 01:47
 0  45
TOPICDevOps BasicsPractical guide
When to Embed Disaster Recovery in CI/CD Pipelines

Disaster recovery should be embedded in CI/CD when your infrastructure is already defined as code, your recovery targets are tight, and changes ship often enough that a yearly manual DR test cannot keep up. In that case, pipelines should build recovery environments from code, verify backups by restoring them, and run scheduled failover drills automatically.

This guide explains when that approach makes sense, when it does not, and how to add DR steps to a pipeline in stages. It assumes you know the basics of backups and pipelines. For backup fundamentals on Linux servers, see our guide to backup and recovery best practices. For how pipelines are structured in general, see our pillar on CI/CD pipeline examples.

Key takeaways

  • A DR plan that has not been tested recently is a guess. Pipelines make testing frequent and repeatable.
  • Embed DR in CI/CD when infrastructure is in code, RTO and RPO targets are tight, releases are frequent, or auditors require evidence of tests.
  • Start with backup verification by restore, then rebuild environments from code, then scheduled failover drills, then controlled fault injection.
  • Keep the DR pipeline separate from the release pipeline so a broken release does not block a recovery, and give it its own credentials.
  • Tools commonly used include Terraform for rebuilds, Velero for Kubernetes backup and restore, and AWS Fault Injection Service for controlled failure tests.
  • Do not automate failover of production without human approval unless the design and the team are mature enough to trust it.

What "DR in CI/CD" actually means

Traditional disaster recovery lives in a document. It lists the steps to restore systems after a major failure, and once a year a team schedules a weekend to try them. The test often reveals that the document is out of date, that a backup cannot be restored, or that nobody remembers a manual step. Then the findings sit in a ticket until the next test.

Embedding DR in CI/CD means turning those steps into automated jobs that run regularly: on a schedule, after infrastructure changes, or on demand during an incident. The pipeline proves continuously that you can do what the DR plan claims. It does not replace the plan or the people; it makes the plan executable and keeps it honest.

The idea fits naturally with infrastructure as code. If your networks, clusters and databases are defined in Terraform or a similar tool, then rebuilding them in another region is, in principle, running the same code with different inputs. The pipeline is where you prove that principle holds.

RTO and RPO set the bar

Two numbers define what a DR design must achieve. Recovery Time Objective (RTO) is the maximum acceptable time to restore service after a disruption. Recovery Point Objective (RPO) is the maximum acceptable amount of data loss, measured in time. A system with an RTO of four hours and an RPO of one hour can lose up to an hour of data and must be running again within four hours. The tighter those numbers, the less room there is for manual steps, and the stronger the case for automation.

When to embed DR in CI/CD

Not every system needs DR automation, and automating too early wastes effort. These signals suggest it is time.

Your infrastructure is already in code

Automation needs something to automate. If environments are still built by hand, the first job is getting them into code. Once they are, adding a DR rebuild job is a relatively small step. Our post on how Terraform fits into the DevOps workflow covers that groundwork.

Recovery targets are measured in minutes or a few hours

When the business needs recovery within minutes or a few hours, manual runbooks executed by a stressed on-call engineer at 3 a.m. are too slow and too error prone. Automated, rehearsed steps are the only realistic way to hit tight targets.

You release often

If you deploy many times a week, the system you tested in last year's DR exercise no longer exists. New services, new dependencies and new data stores appear constantly. Regular automated drills catch the new service that nobody added to the backup policy.

Auditors or customers want evidence

Many regulated industries and enterprise customers ask for proof that DR is tested. A pipeline produces timestamped logs, restore results and recovery times for every run, which is far stronger evidence than a yearly test report.

You have had a backup surprise

If a restore has ever failed when you needed it, or a backup job was silently broken for weeks, that alone justifies automating restore tests.

When not to, or not yet

Some situations call for caution. If infrastructure is mostly manual, automate provisioning before automating DR. If the team is small and the system is low risk, a well-written runbook tested twice a year may be enough. If the architecture has hard dependencies that cannot be rebuilt automatically, such as a third-party system that needs a phone call, the pipeline can still automate everything else, but you must keep the manual parts documented and tested. And automated failover of production traffic, without a person approving it, is a high bar: a false positive can cause an outage of its own. Most teams automate the preparation and verification and keep a human approval step for the actual switch.

Levels of DR automation

It helps to think of DR automation in levels and move up one at a time.

LevelWhat the pipeline doesWhat it provesTypical frequency
1. Backup verificationRestores recent backups into a scratch environment and runs checksBackups exist and can be restoredDaily or weekly
2. Environment rebuildCreates a full environment in another region or account from codeInfrastructure code is complete and worksWeekly or after infra changes
3. Failover drillRebuilds, restores data, deploys apps and runs smoke tests, then measures timeRTO and RPO can be met end to endMonthly or quarterly
4. Fault injectionIntroduces controlled failures and checks the system recoversAutomatic resilience mechanisms workRegularly, in pre-production first

Level 1: verify backups by restoring them

A backup job that reports success only proves that a file was written. The only real test is a restore. A verification job takes the latest backup, restores it into an isolated environment, and runs checks: does the database start, are key tables present, do row counts look sensible, does the application connect?

For managed databases on AWS, the job can restore a snapshot to a temporary instance, run queries, record the result and delete the instance. Our post on RDS snapshots and automated backups explains the backup side. For Kubernetes, Velero backs up cluster resources and persistent volumes and can restore them into another cluster. Its documentation shows scheduled backups and restores with commands like these:

# Daily scheduled backup at 07:00
velero schedule create daily-backup --schedule "0 7 * * *"

# Restore from a specific backup produced by the schedule
velero restore create --from-backup daily-backup-20261118070000

Velero's disaster recovery guide also recommends switching the backup storage location to read-only during a restore so that new backups do not overwrite the ones you are restoring from. The current Velero release at the time of writing is v1.18.4.

Level 2: rebuild environments from code

The next step proves that your infrastructure code can create a working environment from scratch somewhere else. A scheduled job runs Terraform against a DR account or region with DR-specific variables, waits for it to finish, runs basic checks, and then destroys the environment if it is not meant to stay up.

terraform init -backend-config=backend-dr.hcl
terraform plan -var-file=dr.tfvars -out=dr.plan
terraform apply dr.plan
./scripts/smoke-test.sh --env dr
terraform destroy -var-file=dr.tfvars -auto-approve

This job finds the gaps that only appear on a fresh build: hard-coded region names, resources created by hand and never codified, missing service quotas in the DR region, AMIs or container images that only exist in the primary region, and secrets that were never replicated. Each failure is a defect in your DR readiness, found on a quiet weekday instead of during a disaster. Keep the remote state for the DR environment separate from production state, so a mistake in one cannot damage the other.

Level 3: scheduled failover drills

A full drill combines the previous levels and adds the application and the clock. The pipeline rebuilds or scales up the DR environment, restores the latest data, deploys the current application versions, runs smoke and integration tests, and records how long each step took. Comparing the measured time with your RTO, and the age of the restored data with your RPO, tells you whether your targets are realistic.

For drills that move real traffic, add a manual approval gate before the traffic switch and another before switching back. Publish the results, including failures, to the team. Over time the trend in recovery times is one of the most useful reliability signals you have, and it connects directly to the work of site reliability engineers; see our post on the role of SREs in DevOps teams.

Level 4: controlled fault injection

Many failures are partial: one Availability Zone loses capacity, one dependency slows down, instances are terminated. Fault injection tests whether the system's automatic resilience handles those without a full DR event. AWS Fault Injection Service (AWS FIS) is a managed service for running such experiments on AWS workloads. You define an experiment template with actions, targets and stop conditions; a stop condition is a CloudWatch alarm that halts the experiment if a threshold is crossed. AWS recommends planning carefully and running experiments in pre-production before production, because FIS performs real actions on real resources.

A pipeline can start a FIS experiment after a deployment to staging, watch the stop-condition alarms, and fail the pipeline if the service does not stay within its error budget. Start small, with a single instance termination, and expand only when results are well understood.

Designing the DR pipeline

Keep it separate from the release pipeline

The DR pipeline should not depend on the release pipeline's health. If a broken release blocks your release pipeline, you still need to be able to recover. Give DR jobs their own pipeline definitions, runners or agents that do not live only in the primary region, and their own credentials.

Protect credentials and backups

DR jobs need powerful permissions in the DR account. Scope them to what the jobs need, store them in a secrets manager, and require approval for the destructive steps. Backups should be stored in a separate account with restricted delete permissions, and immutability features such as S3 Object Lock help protect them from accidental or malicious deletion. Our post on S3 access logging and Object Lock covers that setup.

Make results visible

Every run should record what was restored, from which backup, how long each step took, and whether checks passed. Send results to a dashboard and alert on failures exactly as you would for a production incident. A silent DR job that fails for a month is as dangerous as no job.

Control cost

DR environments cost money while they run. Tear down drill environments automatically, use smaller instance sizes for verification-only runs where that still proves the point, and schedule heavy drills at sensible intervals. Pilot light and warm standby designs keep a minimal footprint running in the DR region and scale it up during a drill or real event.

Ownership and process

Automation does not remove the human side. Someone must own the DR pipeline, review failures and fix the underlying gaps. The incident response process should say who can trigger a real failover and how the decision is made. Our post on who should own incident response in a DevOps and SRE team discusses those roles. After every drill, hold a short review, update the runbook where the automation still relies on manual steps, and track the action items like any other engineering work.

A sensible rollout plan

For most teams a practical order is to start with a nightly job that restores the main database backup into a scratch environment and checks it. Next, add a weekly job that builds the core infrastructure in the DR region from code and tears it down. Then run a monthly or quarterly drill that brings up the full application in DR and measures recovery time against RTO. Finally, introduce small fault injection experiments in staging, and only consider production experiments with stop conditions once the team is confident.

Each step produces value on its own, and each one makes the next easier. The goal is simple: when a real disaster happens, recovery should feel like running a job the team has run many times before.

Disaster recovery strategies, infrastructure as code and pipeline automation on AWS are covered in our AWS DevOps Engineer Professional training, and the Terraform side in our Terraform training. Both are available in the Kharadi, Pune classroom and live online.

Official references

FAQs

When should disaster recovery be part of a CI/CD pipeline?

When infrastructure is defined as code, recovery targets are tight, releases are frequent, or auditors need evidence of regular testing. Without infrastructure as code, automate provisioning first.

What is the difference between RTO and RPO?

RTO is the maximum acceptable time to restore service after a disruption. RPO is the maximum acceptable data loss, measured as time between the last recoverable point and the failure.

Should failover to the DR region be fully automatic?

For most teams, no. Automate preparation, data restore and testing, but keep a human approval step before switching production traffic, because a false trigger can cause its own outage.

How do you test backups automatically?

Restore the latest backup into an isolated environment on a schedule, run checks such as starting the database and validating key data, record the result, and delete the temporary environment.

What tools help automate disaster recovery?

Terraform or similar IaC tools rebuild infrastructure, Velero backs up and restores Kubernetes resources and volumes, and AWS Fault Injection Service runs controlled failure experiments on AWS.

Should the DR pipeline be separate from the release pipeline?

Yes. Separate pipelines, runners outside the primary region and dedicated credentials mean a broken release or a regional outage does not stop you from recovering.

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.