AI-Powered Disaster Recovery
Disaster recovery for AI-assisted teams spans two blast radii: a change an agent shipped, recovered through checkpoints, incremental commits, feature flags, and targeted reverts; and the infrastructure under it, recovered through Postgres point-in-time-recovery runbooks, Velero backups, and rehearsed failover. Both share one discipline — stated recovery objectives, a rehearsed procedure, and a human at every irreversible gate.
The AI agent just refactored your authentication module across 47 files. Tests pass, types check, you merge. Two hours later, session tokens are not being validated in the admin API, three other PRs have merged on top, and rolling back is no longer a single click. A month later a different disaster arrives: your primary region goes dark mid-deploy, the status page is still green because nobody updated it, and the runbook is a Confluence page last edited fourteen months ago referencing a Postgres host decommissioned in the spring.
Different scales, same question — how fast can you get back, and how much do you lose on the way? Disaster recovery is the one area where “we will write the docs later” quietly becomes “we lost six hours and a chunk of customer data.” The good news: the slow, tedious parts — drafting precise runbooks, writing chaos experiments that actually assert your RPO, capturing the current behavior of code before an agent rewrites it, turning a messy timeline into a blameless post-mortem — are exactly what AI coding tools are good at, as long as you anchor them to real tools and keep a human at the approval gate.
What this disaster-recovery playbook gives you
Section titled “What this disaster-recovery playbook gives you”- Safety-net configuration for all three tools so an agent cannot make a 47-file change you cannot unwind
- A prompt that forces an adversarial review of an agent’s diff, hunting the silent behavioral changes tests do not catch
- Recovery procedures for AI-introduced regressions at every stage: pre-merge, post-merge, and data corruption
- A copy-paste prompt that turns your stack into a Postgres point-in-time-recovery runbook with explicit RTO/RPO targets and WAL-chain verification
- A Chaos Mesh
Schedulethat kills your primary DB pod every week and asserts failover under a 5-minute RPO — generated, not hand-typed from memory - A human-gated playbook for the live regional outage, and a prompt that drafts a blameless post-mortem from real logs
- A list of failure modes that silently break recovery plans, and how to catch them before the disaster does
Two blast radii, one discipline
Section titled “Two blast radii, one discipline”A recovery plan is only useful if it names what it recovers from. Almost everything that goes wrong on an AI-assisted team lands in one of two buckets, and they want different tools:
- The change. An agent introduced a regression. The blast radius is a commit, a PR, or a deploy. Recovery is a checkpoint, a revert, a feature-flag flip, or a hotfix — measured in minutes, and mostly a question of whether the change was small enough to undo cleanly.
- The infrastructure. A database, a region, or a cluster is gone. The blast radius is everything on top of it. Recovery is a restore or a failover — measured against objectives you set in advance, and mostly a question of whether you rehearsed.
The discipline is identical in both: state the objective before the incident, rehearse the procedure, keep a person at every irreversible step, and capture what you learned. The rest of this guide runs that discipline at both scales.
Recovery objectives come first
Section titled “Recovery objectives come first”Every DR artifact downstream depends on two numbers per service tier: RTO (how long until service is restored) and RPO (how much data you can afford to lose). Write them down explicitly before you generate anything — a runbook that targets “fast recovery” is useless; one that targets “RTO 15 min, RPO 5 min for payments” is testable.
A realistic starting matrix looks like this:
| Tier | Example services | RTO | RPO | Backup approach |
|---|---|---|---|---|
| Critical | auth, payments | 15 min | 0–5 min | Synchronous/streaming replica + WAL archiving |
| High | core API | 1 hour | 5 min | WAL archiving + frequent base backups |
| Medium | secondary features | 4 hours | 1 hour | Hourly snapshots |
| Low | internal tooling | 24 hours | 24 hours | Daily backups |
Prevention: the safety net before the agent starts
Section titled “Prevention: the safety net before the agent starts”The best disaster recovery is not needing it. Each tool has a native place to put the rules, and the rules are what keep a large agent-driven change revertable.
Cursor’s checkpoint system provides automatic rollback points:
- Checkpoints are automatic snapshots of the Agent’s changes to your codebase
- To roll back, click
Restore Checkpointon the relevant earlier request, or the+button when hovering over a message - Checkpoints are stored locally and are separate from Git — use Git for permanent version control, not checkpoints
Add explicit safety rules:
SAFETY REQUIREMENTS:Before any multi-file refactoring:1. List all files that will be modified2. Verify the test suite passes BEFORE making changes3. After changes, run the full test suite4. If any test fails, revert ALL changes and report what went wrong
NEVER delete files without explicit user confirmation.NEVER modify configuration files (*.config.*, .env*, Dockerfile) without showing the diff first.Claude Code works with Git directly. Establish commit-based safety:
SAFETY PROTOCOL:Before starting any multi-file modification:1. Run: git stash (save any uncommitted work)2. Create a safety branch: git checkout -b ai/[task-description]3. Commit after each logical step with descriptive messages4. Run tests after each commit5. If tests fail, use git diff to identify the problem
After completing the task:- Run the FULL test suite (npm test)- Run type checking (npm run type-check)- Run linting (npm run lint)- Show the complete diff from main for review
NEVER force-push. NEVER modify the main branch directly.Claude Code’s permission system provides an additional safety layer — file writes require explicit approval unless auto-approved in settings.
Codex cloud tasks run in isolated sandboxes with built-in safety:
SAFETY PROTOCOL:- All changes happen in a new branch (never modify main)- Cloud tasks cannot push directly to main- Every task produces a PR for human review- Worktrees provide isolation between parallel tasks
Before submitting a PR:1. Run the full test suite2. Run the linter3. Generate a comprehensive PR description explaining all changes4. Flag any files that were deleted or had configuration changesCodex’s sandboxed environment means a runaway task cannot affect your local environment or other branches.
Review the diff adversarially
Section titled “Review the diff adversarially”Type checks and a green suite are the weakest evidence you have about an agent’s refactor. Ask for the review that hunts what they miss:
Make the change small enough to undo
Section titled “Make the change small enough to undo”Two habits do more for recoverability than any tooling: commit in steps that each pass tests, and capture existing behavior in tests before the rewrite.
Deploy so that a rollback is a flag, not a fire drill
Section titled “Deploy so that a rollback is a flag, not a fire drill”-
Feature flags for AI-generated changes
Deploy AI-assisted changes behind feature flags. If something goes wrong, flip the flag instead of rolling back the deployment.
-
Canary deployments
Route 5% of traffic to the new version. Monitor error rates, latency, and key business metrics for 30 minutes before expanding.
-
Automated rollback triggers
Set up automatic rollback when error rate exceeds 2x baseline or p99 latency exceeds 3x baseline.
-
Post-deployment monitoring
Watch dashboards for 4 hours after deploying AI-generated changes. The failure modes of AI code are often subtle — edge cases and race conditions rather than crashes.
Recovering from a change you shipped
Section titled “Recovering from a change you shipped”The agent broke tests before merge
Section titled “The agent broke tests before merge”The easiest recovery, and the one where the tool you used decides the mechanics.
Use Cursor’s checkpoints to restore the last good state:
- Find the request just before the breaking change
- Click its
Restore Checkpointbutton (or the+button when hovering over that message) to return to that state - Alternatively, use
Cmd+Zto undo recent edits
Checkpoints are stored locally and separate from Git, so reach for Git once you need a durable rollback point.
# If working on a branch (recommended):git diff main # See what changedgit stash # Save current stategit checkout main # Return to clean state
# If you committed incrementally (recommended):git log --oneline -10 # Find the last good commitgit revert HEAD~3..HEAD # Revert the bad commitsCodex PRs are the recovery boundary. If the PR breaks tests:
- Close the PR without merging
- Create a new task with more specific constraints
- Reference what went wrong: “The previous attempt broke auth middleware registration”
It merged, and production is hurting
Section titled “It merged, and production is hurting”Speed matters more than elegance here. Point the agent at the specific PR and forbid it from improving anything on the way past:
It corrupted data
Section titled “It corrupted data”The most dangerous scenario, and the one where the change-level and infrastructure-level playbooks meet: the fix is a restore.
-
Stop the bleeding
Deploy the rollback immediately. Do not try to fix forward when data integrity is at risk.
-
Assess the damage
Query the database for records modified during the incident window. Determine the scope of corruption.
-
Restore from backup
Use the point-in-time recovery runbook below to restore affected data to the state before the incident.
-
Root cause analysis
Identify which AI-generated code caused the corruption. Was it a missing validation? A wrong query? A race condition?
-
Prevent recurrence
Add specific test cases for the failure mode. Add database constraints that would catch the corruption at the data layer. Update your agent rules to prevent similar patterns.
Recovering the infrastructure underneath
Section titled “Recovering the infrastructure underneath”The single most valuable DR artifact for most teams is a Postgres point-in-time-recovery runbook that an on-call engineer can follow at 3 AM without thinking. The pattern that actually works in production is WAL archiving plus an external base-backup tool — pgBackRest or WAL-G — not a server-side plpgsql function. PITR restores set restore_command and recovery_target_time and rely on an unbroken WAL chain between the base backup and the target time.
Have your AI tool write the runbook against your actual config rather than a generic template:
Read what it produces critically. The two things AI most often gets wrong here are inventing pgBackRest flags and glossing over the WAL-chain gap check — the exact failure that strands you mid-recovery. If a command looks unfamiliar, check it against pgbackrest --help before it goes in the runbook.
Where each tool fits
Section titled “Where each tool fits”The runbook itself is identical regardless of tool — it is a Markdown file in your repo. What differs is how you drive the generation and keep it honest over time.
Open the runbook in the editor and use agent mode so Cursor can read your actual pgbackrest.conf, docker-compose.yml, and migration files for ground truth instead of guessing host names and stanza names. Iterate inline: when a step looks wrong, select it and ask Cursor to fix just that step. Use a checkpoint before letting it touch multiple files so you can roll back a bad rewrite in one click.
This is the fastest loop when DR config lives in the same repo you are editing and you want to see diffs as they happen.
Use headless mode to regenerate and validate the runbook as part of a scheduled DR drill or a pre-release check, so it never silently rots:
claude -p "Read infra/pgbackrest.conf and ops/runbooks/pitr.md. \Verify every pgBackRest flag in the runbook exists in this version, \and that the stanza name matches the config. List any drift as a \checklist of fixes. Exit non-zero if the runbook references a host or \stanza not present in the config." \ --allowedTools "Read,Grep"Wire that into a weekly CI job. A red build means your runbook drifted from reality — which is exactly when you want to find out, not during the outage. The --allowedTools "Read,Grep" flag keeps the check read-only so it can run unattended.
Hand the whole task to Codex Cloud: give it the repo and a task like “regenerate ops/runbooks/pitr.md from the current pgBackRest config and open a PR.” Running on GPT-5.6 Sol, it works in an isolated environment against a checked-out copy, so it can grep the real config, regenerate the runbook, and push a branch for review without touching your machine.
For local work, codex in a worktree keeps the DR changes isolated from your feature branches, and its GitHub integration can open the PR for a human to approve.
Backing up the rest of the stack
Section titled “Backing up the rest of the stack”A database is rarely the whole story. For Kubernetes-hosted workloads, Velero backs up cluster resources and persistent volumes and is the standard tool to prompt your AI assistant to configure — not an invented internal backup service.
For object storage and managed databases, prefer the provider’s native cross-region replication and point-in-time features (for example, RDS automated backups with PITR, or S3 Cross-Region Replication) over rolling your own. Ask your AI tool to generate the Terraform for those, then review the IaC the same way you reviewed the runbook.
Testing it: chaos drills that assert your RPO
Section titled “Testing it: chaos drills that assert your RPO”An untested DR plan is a hypothesis. The cheapest way to test failover continuously is a scheduled Chaos Mesh experiment that kills your primary DB pod and checks that the system recovers inside your stated objectives. The Schedule CRD (apiVersion: chaos-mesh.org/v1alpha1) runs a PodChaos pod-kill on a cron.
The generated manifest is the easy half. The runbook that defines pass/fail against your RTO/RPO is the half that makes the drill meaningful — without it, you are just killing pods and hoping. Treat a missed RTO in a Saturday drill as a P2 ticket, not a curiosity.
-
Run the drill in a staging cluster that mirrors production topology, never against live customer traffic.
-
Capture the timeline automatically: kill time, promotion time, first successful write to the new primary.
-
Compare measured RTO/RPO to your targets and file a ticket for any miss.
-
Feed the drill’s logs straight into the post-mortem prompt below so the gaps turn into action items instead of being forgotten by Monday.
When the real thing happens: the human-gated playbook
Section titled “When the real thing happens: the human-gated playbook”Mid-incident, AI is best used to generate and validate the next action — never to fire irreversible commands directly from free text. Keep a person at the approval gate for anything that promotes a replica, reroutes DNS, or disables writes.
For a ransomware scenario the same discipline applies: use the tool to find the last clean backup before encryption and to draft network-isolation rules, then have a human execute. A useful, specific Claude Code invocation:
claude -p "Given the pgBackRest backup catalog in this repo's logs/ \directory and the file-modification timeline in incident/timeline.csv, \identify the most recent backup whose stop time precedes the first \encryption event, and explain how you ruled out later backups." \ --allowedTools "Read,Grep"Note the claude -p headless form and the read-only tool allowlist: it analyzes and recommends, it does not restore.
When recovery plans break
Section titled “When recovery plans break”Both scales fail in predictable ways. Watch for these:
- WAL chain gaps. Bucket lifecycle rules or a silently-failing
archive_commandexpire segments between your base backup and target time. The restore aborts partway. Fix: the runbook must verify continuity, not assume it. - Replication lag exceeds RPO at the worst moment. Under the write spike that often precedes an outage, your standby falls minutes behind. Promoting it loses more data than your RPO allows. Fix: alert on lag against the RPO number, and have the failover step check lag before promoting.
- Failover that strands writes. You promote the standby but the old primary is still accepting writes (split-brain), or in-flight writes never replicated. Fix: the playbook’s first step is always disable writes on the failed primary, before promotion.
- The drill passes, the real thing fails. Staging has 3 nodes; production has 30 and a different topology. Fix: run drills against a cluster that mirrors production scale, and rotate the failure injected.
- AI invents flags or fields. A generated
pgBackRestflag or Chaos Mesh field that does not exist makes the artifact non-runnable. Fix: always validate generated commands against--helpor the CRD reference before committing — treat AI output as a draft, never as gospel. - You cannot roll back because other changes depend on the agent’s code. This is what incremental commits buy you. If one commit introduced the issue, revert that commit; if the changes are tangled, a targeted hotfix beats an untangling operation during an incident.
- The agent deleted files nobody noticed for weeks. Git has your back:
git log --diff-filter=Dfinds deleted files andgit checkout <commit>^ -- <filepath>restores them. Add a CI check that flags deletions for extra scrutiny in review. - The backup strategy does not cover AI-specific failure modes. Database backups and code in Git cover most of them. The unique risk is a subtle behavioral change that passes every check — which is why behavior-capture tests on critical paths and feature-flagged deploys belong in the backup strategy, not just in the coding standard.
Closing the loop: the post-mortem
Section titled “Closing the loop: the post-mortem”The incident is not over until the learning is captured. AI is genuinely good at turning a messy timeline and a wall of logs into a structured, blameless post-mortem — provided you feed it the real artifacts.
Run this with Claude Fable 5 (/model fable) when the causal chain is tangled across services — the reasoning quality is worth the cost on the one document everyone will read; fall back to Opus 5 if budget is a concern. Keep the output in the repo next to the runbook it should improve, so the next drill tests against the lessons from the last incident.