Backup Plugin

A Python CLI plugin (integrations/zoidmatter-backup/) that orchestrates restic backups of the database, session logs, and documents to the storage provider of your choice.

Capabilities

Repository encryption

RESTIC_PASSWORD is not a storage credential. restic encrypts every blob locally before upload, so the provider only ever holds ciphertext; the password unlocks the repository's master key. It is required for every provider, including local, and it is the one secret with no recovery path — if it is lost, the backups cannot be decrypted by anyone. Keep a copy somewhere separate from the bucket keys. RESTIC_PASSWORD_FILE and RESTIC_PASSWORD_COMMAND work as alternatives.

Storage providers

Set BACKUP_PROVIDER and fill in only that provider's variables. RESTIC_REPOSITORY overrides the whole assembly if you would rather write the repository URL yourself. Run docker compose --profile backup run backup config to print the resolved provider, repository URL, and credential sources with secrets masked.

BACKUP_PROVIDERRepository URLRequired variables
b2b2:<bucket>:<repo-id>BACKUP_B2_BUCKET, BACKUP_B2_REPO_ID, B2_ACCOUNT_ID, B2_ACCOUNT_KEY
s3s3:<endpoint>/<bucket>[/<prefix>]BACKUP_S3_ENDPOINT, BACKUP_S3_BUCKET, BACKUP_S3_ACCESS_KEY, BACKUP_S3_SECRET_KEY
local<path>BACKUP_LOCAL_PATH
sftpsftp:[user@]<host>:<path>BACKUP_SFTP_HOST, BACKUP_SFTP_PATH

Backblaze

Either provider reaches Backblaze. The native b2 backend uses the B2 API directly; the s3 provider goes through Backblaze's S3-compatible endpoint (s3.us-west-004.backblazeb2.com, region us-west-004 — match the digits to your bucket's region), which shares one code path with Garage and MinIO.

Self-hosted Garage

Point BACKUP_S3_ENDPOINT at the Garage instance (https://garage.example.com, or a bare http://host:3900 on a trusted LAN) and use an access key pair from garage key create.

Two Garage-specific settings matter. BACKUP_S3_REGION must equal the s3_region value in your garage.toml — Garage ships with "garage", not an AWS region name. It is not a location, just a string that SigV4 folds into the request signature, so a mismatch surfaces as SignatureDoesNotMatch rather than as a configuration error. And unless you have wildcard DNS pointing *.your-domain at Garage, set BACKUP_S3_BUCKET_LOOKUP=path so restic addresses buckets as endpoint/bucket instead of bucket.endpoint.

Multiple destinations

BACKUP_DESTINATIONS=primary,offsite turns every command into a fan-out over independent repositories. Each name is spliced into the variables above — BACKUP_S3_BUCKET becomes BACKUP_PRIMARY_S3_BUCKET, RESTIC_PASSWORD becomes BACKUP_PRIMARY_RESTIC_PASSWORD — and anything a destination does not set falls back to the unprefixed value, so shared settings are written once. Leaving the variable unset keeps the single-destination behaviour unchanged.

The destinations are genuinely separate repositories, each backed up, verified and pruned on its own. One failing does not stop the others, which is the entire point of keeping a second copy. The cost is that restic cannot dedupe across them, so every destination pays full storage.

Two destinations that resolve to the same repository URL are rejected at load. The fallback makes it easy to define an "offsite" copy that quietly inherits the primary bucket — which looks like redundancy right up until the moment it is needed.

The database is dumped once per run and the same bytes go to every repository, so the copies match instant for instant rather than drifting by however long the first upload took. The staged dump lives in BACKUP_TMP_DIR (default: system temp), is written 0600, and is deleted when the run ends. With a single destination nothing is staged at all — pg_dump streams straight into restic, exactly as before.

run, list and check cover every destination and exit non-zero if any failed; --dest <name> narrows to one. restore requires a single destination, because snapshot ids are per-repository and guessing would restore the wrong thing rather than fail.

Commands

Run inside the backup container with docker compose --profile backup run backup <command>.

CommandEffect
configResolved provider, repository URL, restic options and password source, with credentials masked. Validates without touching the network.
initCreate any repository that does not exist yet. Idempotent, so it is safe to re-run after adding a destination.
runAll targets. --db, --session-logs and --documents narrow it.
listSnapshots per destination; --json for machine output.
checkrestic check per destination.
restore--snapshot <id> --target <path>. The database snapshot lands at <target>/pgdump.custom in PostgreSQL custom format — load it with pg_restore, not psql.

--dest <name> narrows any command to one destination.

Scheduling

The container runs one backup and exits. BACKUP_SCHEDULE is parsed and validated but nothing acts on it yet, so --profile backup up -d does not give a recurring job. Drive it from a host cron entry, a systemd timer, or a scheduled call to POST /v1/backup/run.

Rust API Routes

MethodPathDescription
POST/v1/backup/runRun a backup
GET/v1/backup/listList backups
POST/v1/backup/restoreRestore a backup
POST/v1/backup/checkVerify backup integrity

The routes invoke the CLI via subprocess. A Docker backup service runs under the [backup] profile.