Files
akyldash/docs/operations/BACKUP.md
T
agent f8483badcf
CI / tests-and-images (pull_request) Successful in 2m12s
Runner smoke test / runner-smoke (pull_request) Successful in 3s
fix: validate Gitea workflow source identity
2026-10-26 22:55:29 +03:00

6.7 KiB

Backup and restore

Current status

No production data or backup existed during the 2026-10-11 audit. The repository now contains infra/backup/archive.py; it is not installed or run on the VPS, and /var/backups/akyldash was only a planned root-only location. The owner has since prohibited keeping a complete archive on the VPS, including temporarily. The local archive and full stop-create-verify-restart procedures below are superseded and not authorized on the VPS. The selected destination is externally managed Windows-controlled storage; its design and implementation are pending, so there is no verified backup path yet. Do not treat this plan or the uninstalled archive tool as a valid production backup.

Required release policy

  • Create a backup before every production change, including any future schema or index migration.
  • Include the normalized corpus, search-users.sqlite3, search-reviews.sqlite3, the OpenSearch index/snapshot, deployment digest, Caddy's certificate data, and required secret file in the protected backup set. Store secrets and Caddy private keys with equivalent access controls.
  • Verify archive readability, checksums, and SQLite integrity before relying on it. Never overwrite or delete the only usable backup.
  • Keep one current pre-release backup. If deployment fails, retain the backup required to restore the previous state.
  • Test restore into an isolated target before relying on the backup. Do not restore over production as a test.

Clean first deployment — superseded, not authorized on the VPS

No backup is needed only when Compose has no containers and all four persistent mounts are confirmed empty. For a first install with a preloaded corpus and not-yet-created named volumes, use --initial-deployment to create the pre-start backup. This flag is accepted only with no Compose containers and when DATA_ROOT contains exactly minjust-normalized/; it archives absent named volumes as empty components. In every normal backup, an absent volume is an error because it could mean that a previous installation lost data. Missing mount definitions, inaccessible Docker state, or partial service containers are also errors and must stop deployment. Do not create placeholder containers to make backup pass.

For the corpus-only initial case, run this before the first up from the approved checkout. Replace the timestamp with one real UTC timestamp:

cd /opt/akyldash/current
sudo python3 infra/backup/archive.py create \
  --compose-file deploy/production/compose.yaml \
  --env-file /etc/akyldash/production.env \
  --initial-deployment \
  --output /var/backups/akyldash/akyldash-initial-corpus-YYYYMMDDTHHMMSSZ.tar.gz
sudo python3 infra/backup/archive.py verify /var/backups/akyldash/akyldash-initial-corpus-YYYYMMDDTHHMMSSZ.tar.gz

Cold backup procedure — superseded, not authorized on the VPS

The script requires every Compose container to be stopped. Schedule downtime, then run from the approved checkout on the VPS:

cd /opt/akyldash/current
sudo docker compose --env-file /etc/akyldash/production.env -f deploy/production/compose.yaml stop
sudo python3 infra/backup/archive.py create \
  --compose-file deploy/production/compose.yaml \
  --env-file /etc/akyldash/production.env \
  --output /var/backups/akyldash/akyldash-YYYYMMDDTHHMMSSZ.tar.gz
sudo python3 infra/backup/archive.py verify /var/backups/akyldash/akyldash-YYYYMMDDTHHMMSSZ.tar.gz

Replace the timestamp placeholder with one real UTC timestamp before running. On a clean first deployment, create exits with a clear message that backup can be skipped. With existing data and all expected volumes present, it archives the storage even when no Compose containers exist. A preloaded corpus with no named volumes requires the explicit --initial-deployment mode; otherwise missing volumes are rejected. Partial service containers or running services are rejected as unsafe. The create command archives the application data, OpenSearch volume, Caddy data/config volumes, production environment file, and review secret. It records the checked-out Git revision, deployment-file hashes, and image references/IDs for each stopped Compose service, writes a SHA-256 sidecar, and refuses to overwrite an existing archive. It also runs SQLite quick_check. Start the stack again only after verification succeeds:

cd /opt/akyldash/current
sudo docker compose --env-file /etc/akyldash/production.env -f deploy/production/compose.yaml up -d

Initial post-setup baseline — superseded, not authorized on the VPS

After the first index has been loaded and validated, the initial admin account has been created, and /review responds over HTTPS, create a second backup. This one captures the initialized index, account database, and newly created Caddy/OpenSearch volumes. Stop all services, create and verify the archive, then start the stack again:

cd /opt/akyldash/current
sudo docker compose --env-file /etc/akyldash/production.env -f deploy/production/compose.yaml stop
sudo python3 infra/backup/archive.py create \
  --compose-file deploy/production/compose.yaml \
  --env-file /etc/akyldash/production.env \
  --output /var/backups/akyldash/akyldash-initial-baseline-YYYYMMDDTHHMMSSZ.tar.gz
sudo python3 infra/backup/archive.py verify /var/backups/akyldash/akyldash-initial-baseline-YYYYMMDDTHHMMSSZ.tar.gz
sudo docker compose --env-file /etc/akyldash/production.env -f deploy/production/compose.yaml up -d

Use one real UTC timestamp in both archive paths. Do not treat initial production setup as complete until this baseline archive verifies. Keep the pre-start corpus archive as well until the baseline is verified and copied to separately managed encrypted storage.

The historical procedure below assumes a local VPS archive and is superseded. Do not create or stage a full archive on the VPS, even temporarily. A restore procedure for the selected external Windows-controlled copy is pending its design and implementation. Until an external copy and separate-target restore are verified, the production backup gate is unmet. The old local-archive restore example is not authorized for production data:

sudo python3 infra/backup/archive.py restore /var/backups/akyldash/backup.tar.gz \
  --target-dir /var/tmp/akyldash-restore-test

This validates and stages the archive. On the replacement host only, after running bootstrap with --recovery-target and checking out the matching Git revision, apply the staged data:

sudo python3 infra/backup/apply_restore.py \
  --staging-dir /var/tmp/akyldash-restore-test

The apply command restores data and named volumes but leaves services stopped. Test the full procedure on a separate recovery host before relying on it. Do not run an unreviewed restore over existing data.