You want a backup that is encrypted client-side, deduplicates across snapshots, supports many backends (local disk, SFTP, S3, B2, Azure, GCS), and has a real verify step. Restic is that tool. This article walks the install, repo initialization, the systemd timers that take a snapshot and prune retention, and the routine you need to run quarterly to actually trust the data is recoverable.
How to verify
For a host that already runs restic, the repo and snapshots speak for themselves:
restic version
restic -r "$RESTIC_REPOSITORY" snapshots --latest=10
restic -r "$RESTIC_REPOSITORY" stats --mode=raw-data
systemctl list-timers '*restic*'
journalctl -u restic-backup.service --since=yesterday | tail
restic -r "$RESTIC_REPOSITORY" check --read-data-subset=5%
The last command is the integrity check: it re-reads a sampled 5% of the data, re-hashes it, and verifies against the indexes. The full check --read-data is monthly; the subset check is weekly.
What’s happening
A restic repository is a content-addressed store of variable-sized chunks. When you back up a file tree, restic chunks each file with a rolling hash, deduplicates against the existing chunks, encrypts new chunks with AES-256-CTR using a key derived from the repository password, and writes them as pack files into the backend. A snapshot is a metadata object pointing at the tree, which points at the chunks. Two backups of the same data store the chunks once even across different hosts and snapshots.
The crucial property: the encryption is client-side. Restic never sends plaintext or the master key over the wire — the backend (whether your S3 bucket or a hosted Rest Server) sees only encrypted blobs. The repository password unlocks a per-repo master key; rotating either is supported. Lose the password and the repository is unrecoverable.
The procedure
-
Install restic. Use the upstream tarball, not the Debian package — the package lags.
sudo apt update && sudo apt install -y bzip2 ca-certificates curl -fsSL https://github.com/restic/restic/releases/download/v0.17.0/restic_0.17.0_linux_amd64.bz2 \ | bzip2 -d > /usr/local/bin/restic sudo chmod 0755 /usr/local/bin/restic restic version -
Generate and store the password securely. The repository password is the encryption key. Put it in
/root/.restic-passwordwith0400perms on the host, mirror it to a secret store, and document who has access.sudo install -m 0700 -d /root openssl rand -base64 48 | sudo tee /root/.restic-password >/dev/null sudo chmod 0400 /root/.restic-password -
Initialize the repo. Backend URL syntax differs per backend; S3 uses
s3:s3.amazonaws.com/<bucket>/<path>.export RESTIC_REPOSITORY='s3:s3.amazonaws.com/acme-backups/host-01' export RESTIC_PASSWORD_FILE=/root/.restic-password export AWS_ACCESS_KEY_ID=... export AWS_SECRET_ACCESS_KEY=... restic init -
Wire the systemd service+timer. The service reads credentials from a single environment file with
0400perms.# /etc/restic/env RESTIC_REPOSITORY=s3:s3.amazonaws.com/acme-backups/host-01 RESTIC_PASSWORD_FILE=/root/.restic-password AWS_ACCESS_KEY_ID=AKIA... AWS_SECRET_ACCESS_KEY=...# /etc/systemd/system/restic-backup.service [Unit] Description=Restic backup Wants=network-online.target After=network-online.target [Service] Type=oneshot EnvironmentFile=/etc/restic/env ExecStart=/usr/local/bin/restic backup \ --tag scheduled --one-file-system \ --exclude-file /etc/restic/excludes \ /etc /home /var/lib/myapp ExecStartPost=/usr/local/bin/restic forget \ --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune Nice=10 IOSchedulingClass=best-effort IOSchedulingPriority=7 ProtectSystem=strict ReadWritePaths=/var/lib/restic# /etc/systemd/system/restic-backup.timer [Unit] Description=Run restic backup nightly [Timer] OnCalendar=*-*-* 02:15:00 RandomizedDelaySec=900 Persistent=true [Install] WantedBy=timers.target -
Configure forget/prune retention.
forgetremoves snapshots that fall outside the policy;prunereclaims the storage of chunks that no remaining snapshot references.forget --prunedoes both in one pass.--keep-daily 7 --keep-weekly 4 --keep-monthly 12keeps a year of backups: seven days, four weeks, twelve months. -
Run check on a schedule. A second timer fires
restic check --read-data-subset=5%weekly andrestic check --read-datamonthly.restic check --read-data -
Test a restore. Pick a snapshot, restore to a scratch path, and diff against the live data or just verify the file count.
restic snapshots --latest=1 --json | jq '.[0].id' restic restore <snapshot-id> --target=/tmp/restore-test --include /etc diff -r /etc /tmp/restore-test/etc | head
Common pitfalls
- The repository password is the only key — losing it or forgetting to back it up to a second secret store means the backup is decorative.
--one-file-systemis essential — without it, restic will follow a mount into NFS or an external disk and balloon the snapshot.- A restic repo with no
checkever run is unverified; chunks can rot silently on object storage. forget --prunerewrites pack files and is bandwidth-heavy on remote backends — schedule it during the maintenance window.- Two hosts writing to the same repository must coordinate; restic uses a lock file but a stale lock from a crashed host needs
restic unlock.
In the engagements we run, restic is the default for application data backup where dedup ratios pay back the operational cost — encrypted client-side, repo in an offsite bucket with object-lock if the compliance regime needs immutability, retention via forget/prune, and quarterly restore drills tied to the /en/knowledge-base/disaster-recovery-drill/ cadence. See /en/services/managed-operations/.