Encrypted backups for a small server, copied along server → home computer → NAS. The server encrypts each archive to an age recipient; only the owner keeps the identity needed to decrypt it. The pull job verifies the archive hash and alerts you when the newest backup is too old or when the pull itself fails (server down, hash mismatch, NAS unreachable): silence never means "all good".
- A server compromise may expose current source data and the public age recipient.
- It does not give the attacker the age identity used to decrypt existing archives.
- Archives are encrypted before they leave the server's temporary workspace.
- SHA-256 detects corruption or replacement during transfer; it is not an authenticity signature against a compromised server.
- The home computer and NAS are separate copies, but their security depends on their own access controls and credentials.
POSIX sh, age, rsync, ssh; optional pg_dump, sqlite3, and docker for their respective features. sha256sum is used on the server. The pull script also supports macOS shasum.
Install server/backup-chain-make on the server and pull/backup-chain-pull on the home computer. Install restore/backup-chain-verify where restores are checked. Keep the age identity offline or on an owner-controlled device; install only the public recipient file on the server.
Create /etc/backup-chain.conf on the server:
OUT_DIR=/var/backups/backup-chain
RECIPIENTS=/etc/backup-chain-recipients.txt
PG_DSN=postgresql://backup@localhost/app
# Or use a container instead:
# PG_CONTAINER=postgres
# PG_DATABASE=app
SQLITE_DB=/var/lib/app/app.db
FILES=/etc/app /var/lib/app/uploads
KEEP_DAYS=14The config is parsed as data, never sourced as shell. Only documented keys are accepted. FILES is whitespace separated; paths containing whitespace are unsupported. Run the server script from the backup-chain service account with read access to its configured sources.
Create ~/.config/backup-chain.conf on the home computer:
SERVER=backup@example.net
REMOTE_DIR=/var/backups/backup-chain
LOCAL_DIR=/srv/backup-chain
NAS_PATH=/mnt/nas/backup-chain
# For an NAS reachable over SSH, use both settings instead:
# NAS_PATH=/backups/backup-chain
# NAS_SSH=backup@nas.example.net
KEEP_DAYS=30
MAX_AGE_HOURS=30The pull host needs SSH key access to the server and the NAS when NAS_SSH is set. A mounted NAS_PATH must already exist. Alerts: set BC_TELEGRAM_TOKEN and BC_TELEGRAM_CHAT in the environment of the pull job for Telegram (the token is handed to curl through stdin, so it never appears in ps), and/or ALERT_CMD in the config, which gets the alert text as its first argument. Alerts are always written to stderr too. Age is calculated from the UTC timestamp in the archive filename, so keep the server and pull host clocks synchronized. Do not put secrets in a shell-sourced config.
Run backup-chain-make on the server, then backup-chain-pull at home. The latest pointer contains the archive filename and its SHA-256 digest. Example schedules are in examples/ for systemd, launchd, and systemd user timers.
backup-chain-verify /srv/backup-chain/20261126T120000Z.tar.gz.age /secure/age-identity.txt
# Or read the identity from stdin:
backup-chain-verify /srv/backup-chain/20261126T120000Z.tar.gz.age - < /secure/age-identity.txtThe verifier decrypts into a private temporary directory, checks the gzip tar listing and requires nonempty database dumps. PostgreSQL can optionally be restored and checked in Docker with --check-postgres; test the actual application restore procedure separately before relying on a backup.
On a Linux test laptop, run:
cd /path/to/backup-chain
sh tests/run.shThe suite is offline: it uses the real age (install it first) and PATH stubs for ssh, rsync, pg_dump and curl. It checks that no plaintext reaches the server's output directory, that a tampered hash, an old backup and an unreachable server each raise an alert, and that the Telegram token stays off the command line. restore/backup-chain-verify --check-postgres restores the dump into a throwaway postgres:17-alpine container (override with BC_PG_IMAGE). ShellCheck can be run separately with shellcheck server/backup-chain-make pull/backup-chain-pull restore/backup-chain-verify tests/run.sh.
Сервер создаёт архив и шифрует его публичным получателем age. Домашний компьютер забирает latest, проверяет SHA-256 и копирует архив на NAS. Закрытый ключ хранится у владельца. Настрой конфиги из примеров выше, затем запускай скрипты по расписанию из examples/. Проверка расшифровывает архив во временный каталог; перед использованием обязательно проверь восстановление на тестовой системе.