6.3 KiB
Disaster Recovery and Backup Runbook
Archie keeps durable state across three separate stores: PostgreSQL, the age sealing keys, and the external deletion ledger (deletions.jsonl). Back up and protect each store independently. Restoring PostgreSQL alone is never enough if age keys or the deletion ledger are lost.
Recovery Objectives
| Store | What it holds | RPO target | RTO target | Backup mechanism |
|---|---|---|---|---|
PostgreSQL (archie database) |
Workflows, runs, approvals, events, governance, sealed credentials, audit events | 5 minutes or less | 30 minutes | Automated base snapshots plus continuous WAL archiving (PITR) |
age recovery keys (age_backup_recipients) |
Ability to open sealed connector credentials and event HMAC secrets | Zero key loss | Immediate on restore | Offline escrow in enterprise secret manager or HSM vault |
Deletion ledger (state_dir/deletions.jsonl) |
Append-only record of deleted memory notes | Zero acknowledged deletion loss | 15 minutes | Independent PVC or host volume snapshots replicated off-cluster |
Independent Backup Strategy
1. PostgreSQL Database
Back up the PostgreSQL cluster using continuous WAL archiving and scheduled base backups so you can restore to a point in time.
- Back up as the
postgresorarchie_owneradministrative role, notarchie_app. - Include the
public.goose_db_versiontable and every Archie module schema (runs,connectors,events,governance,deliveries,judgement,approvals,memory,alerts,proposals,chat, andaudit). - Exclude
state_dirandageprivate keys from database backup media so a database dump alone cannot decrypt stored credentials.
2. age Sealing Keys and Key Rotation
internal/platform/seal/seal.go seals connector credentials (connectors.credentials) and webhook secrets (events.sources.hmac_secret_sealed) with age X25519 keys bound to record labels. If the active age_identity and all age_backup_recipients are lost, every sealed secret in the database is unrecoverable.
Protect sealing keys with two controls:
- Configure offline backup recipients: Generate a recovery
agekeypair in your enterprise vault (archie -new-age-identityorage-keygen) and list its publicage1...string underage_backup_recipientsinconfig.toml. Keep the matchingAGE-SECRET-KEY-1...offline in your secret manager. - Rotate keys with
archie rekey: Rotate compromised or expiringageidentities atomically usingarchie rekey. The command takes a PostgreSQL advisory lock (archie.rekey.owner). It opens every sealed credential and webhook secret with the old identity, re-seals and checks decryption with the new identity in one transaction, and writes a JSON audit log.
Never delete the old identity from your vault until the post-rotation database backup completes.
3. External Deletion Ledger (deletions.jsonl)
When a user deletes a memory note, modules/memory commits the deletion in PostgreSQL and appends an Entry (table, org_id, id, at) to deletions.jsonl inside state_dir (internal/platform/deletions/deletions.go). Each append uses flock and fsync on both the file and parent directories so the record outlives the database.
Keep state_dir on an independent ReadWriteOnce persistent volume (or dedicated host volume in Compose) and snapshot it separately from PostgreSQL. Never restore state_dir from a snapshot older than the database snapshot you are restoring. If deletions.jsonl is lost on an instance that previously recorded deletions, memory.ReapplyDeletions returns deletions.ErrUnsafeRollback and stops startup rather than exposing deleted notes.
Restore Procedure
Follow these steps to recover a stage from backup:
- Stop active Archie pods or containers: Scale the
StatefulSetto0(kubectl scale statefulset archie --replicas=0) or rundocker compose stop archie. - Acquire the exclusive serve lock: If restoring onto an active PostgreSQL instance, hold
pg_advisory_lock(hashtextextended('archie.serve.owner', 0))in your restore session so no stray Archie process can passpg.ClaimServebefore recovery finishes. - Restore PostgreSQL: Restore the base snapshot and replay WAL logs to the target recovery timestamp. Verify
public.goose_db_versionis intact. - Restore or preserve
state_dir: Keep the existingstate_dirvolume containing the latestdeletions.jsonl, or restore the neweststate_dirbackup taken at or after the database restore timestamp. - Restore
agekey material: EnsureARCHIE_AGE_IDENTITY_FILEmounts a validage_identity(or the backup identity stored in your vault if the primary key was lost). If you recover with the backup identity, runarchie rekeyright after startup to rotate to a new runtime key. - Run migrations and start Archie: Run the
archie migrateJob if the restored snapshot precedes the deployed binary schema version, then scale theStatefulSetback to1. - Verify reconciliation and readiness: Watch stdout JSON logs for
applied the record of deletions(memory.ReapplyDeletions) and confirm/startupzand/readyzreturn200.
Restore Verification Drill
Run this drill in staging each quarter and after any backup architecture change. Record the completion timestamp, operator, and measured RTO in your compliance log.
- Sign in to the
staginginstance and create a test memory note. Record its note ID and confirm it appears inGET /api/memory/notes. - Take an on-demand PostgreSQL snapshot (
pre-deletion snapshot). - Delete the test memory note through the UI or API. Verify
state_dir/deletions.jsonlcontains a new JSON line matching the deleted note ID. - Scale the
stagingArchieStatefulSetto0. - Restore the
stagingPostgreSQL database to thepre-deletion snapshottaken in step 2. Leavestate_diruntouched. - Verify the deleted note row is temporarily present again in PostgreSQL before Archie starts.
- Scale the
stagingArchieStatefulSetback to1. - Check pod logs for
applied the record of deletionsand wait for/readyzto return200. - Query
GET /api/memory/notesand PostgreSQL to confirm the test note remains deleted. - Verify credential decryption works using the backup
agerecipient key (or perform a testarchie rekeyrotation and confirm an existing connector still passes health checks).