Restic: backups with encryption and history
How to set up backups with end-to-end encryption, deduplication, and date-based snapshots, automate them, and verify integrity.
Updated August 23, 2026
Restic solves what rsync can't: it encrypts data before sending, keeps a snapshot history, doesn't copy the same chunks twice, and can store backups in S3-compatible storage. One program with no dependencies.
Installation and your first repository
sudo apt install -y restic
restic version
A repository is where your backups live. It can be a directory, a machine over SFTP, or object storage:
export RESTIC_REPOSITORY="sftp:backup@backup.example.com:/srv/restic"
export RESTIC_PASSWORD_FILE=/root/.restic-pass
head -c 32 /dev/urandom | base64 > /root/.restic-pass
chmod 600 /root/.restic-pass
restic init
The repository password cannot be recovered. If you forget it, your data is gone — no support exists here by design. Store it separately from the machine: in a password manager, on paper, anywhere — but not only in the
/root/.restic-passfile on the very machine you're backing up.
Creating a backup
restic backup /var/www /etc/nginx /opt/myapp \
--exclude-file=/root/restic-exclude.txt \
--tag daily
restic snapshots
restic ls latest
restic stats
The second and subsequent runs are fast: only new chunks of data are transferred.
Restoring
restic restore latest --target /restore
restic restore <snapshot-id> --target /restore --include /var/www/uploads
Even more convenient is to view the contents without unpacking everything:
mkdir /mnt/snapshots
restic mount /mnt/snapshots
The directory shows all snapshots by date as regular folders. It's the best way to pull out a single accidentally deleted file.
Scheduling and cleanup
The /usr/local/bin/backup.sh script:
#!/bin/bash
set -euo pipefail
export RESTIC_REPOSITORY="sftp:backup@backup.example.com:/srv/restic"
export RESTIC_PASSWORD_FILE=/root/.restic-pass
docker compose -f /opt/myapp/compose.yaml exec -T db \
pg_dump -U postgres app | gzip > /var/backups/db.sql.gz
restic backup /var/www /etc/nginx /opt/myapp /var/backups --tag daily
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
chmod 700 /usr/local/bin/backup.sh
Next comes a systemd timer, see scheduled tasks. forget --prune removes extra snapshots and frees up space; without --prune, snapshots disappear from the list but the data remains.
Integrity checks
restic check
restic check --read-data-subset=5%
The first command checks the structure, the second reads part of the data and verifies checksums. Run the second once a month: it loads the disk and bandwidth, but it's what catches silent corruption.
A structure check doesn't replace a real restore — see restore drill.
Resources
Restic keeps an index in memory: on large datasets that's hundreds of megabytes. On VDS-1 with 2 GB of RAM, backing up tens of gigabytes may run short — limit parallelism or move heavy backups one tier up. The disk load is noticeable, so schedule for the night: see disk speed.
Common mistakes
- The password is stored only on the machine being backed up. The classic: the machine is lost along with the key to the backups.
forgetwithout--prune. Space isn't freed and the repository keeps growing.- A backup in the same directory on the same disk. You'll have nowhere to restore from — see backups at another location.
- Caches and
/var/lib/dockeraren't excluded. The backup balloons fourfold for no benefit; the list of what to include is in the article what to back up. - Parallel runs. A second run will hit a repository lock. Wrap the call in
flock.