Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
A repository holds encrypted, deduplicated data. Every restic backup creates a snapshot. forget removes snapshots by a policy (keep 7 daily, 4 weekly …) and prune frees the space. Without the repository password, the data can never be read — by anyone, including you.
| Item | Value |
|---|---|
| Package | restic (RHEL: EPEL; Ubuntu: universe) — or the binary from GitHub |
| Settings (environment) | RESTIC_REPOSITORY, RESTIC_PASSWORD_FILE, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY |
| Cache | ~/.cache/restic (root: /root/.cache/restic) |
| Backends | local path, sftp:, s3:, b2:, azure:, gs:, rest:, rclone: |
Install on RHEL, Rocky, Alma and Fedora
Install on Ubuntu and Debian
apt-get update
apt-get install -y restic
restic versionThe distro version can be old; the binary from github.com/restic/restic/releases can update itself (restic self-update).
First configuration: repository and secrets
Keep the settings in a root-only environment file, and the password in its own file:
RESTIC_REPOSITORY=s3:https://s3.example.com:9000/backups/web1
RESTIC_PASSWORD_FILE=/etc/restic/password
AWS_ACCESS_KEY_ID=restic-web1
AWS_SECRET_ACCESS_KEY=another-long-secret
RESTIC_CACHE_DIR=/var/cache/resticmkdir -p /etc/restic /var/cache/restic
openssl rand -base64 32 > /etc/restic/password
chmod 600 /etc/restic/env /etc/restic/password
set -a; . /etc/restic/env; set +a
restic init
created restic repository 3f9a2c1b7e at s3:https://s3.example.com:9000/backups/web1Let op
Save the repository password in your password manager now (and a second safe place). If the server dies with the only copy of /etc/restic/password, the backups are useless.
An exclude list keeps backups small:
/proc
/sys
/dev
/run
/tmp
/var/tmp
/var/cache
/var/lib/docker
/home/*/.cache
*.isoBack up, forget, check
Files and a database dump (streamed, never written to disk):
restic backup /etc /home /srv /var/www --exclude-file /etc/restic/excludes --tag files --one-file-system
sudo -u postgres pg_dump -Fc shop | restic backup --stdin --stdin-filename shop.dump --tag postgres
restic snapshots
ID Time Host Tags Paths
--------------------------------------------------------------
4f1c9a2e 2026-11-17 02:00:12 web1 files /etc,/home,/srv,/var/www
b7d02e11 2026-11-17 02:04:40 web1 postgres /shop.dump
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
restic check --read-data-subset=5%
no errors were found| Command / option | Why |
|---|---|
--exclude-file, --one-file-system | No caches, virtual file systems or other mounts. |
--stdin | Back up a database dump directly from the pipe. |
--tag | Find and manage snapshots by type. |
forget … --prune | The retention policy: 7 daily, 4 weekly, 12 monthly snapshots. |
check --read-data-subset=5% | Read and verify 5 % of the data each time — over weeks, all data is tested. |
Restore
restic ls latest --tag files /etc/nginx
restic restore latest --tag files --target /restore --include /etc/nginx
restic dump latest --tag postgres shop.dump > /tmp/shop.dump
sudo -u postgres pg_restore -d shop_test /tmp/shop.dump
mkdir -p /mnt/restic && restic mount /mnt/resticrestic mount shows all snapshots as folders — copy what you need, then umount /mnt/restic.
Run it every night with systemd
[Unit]
Description=restic backup
After=network-online.target
[Service]
Type=oneshot
EnvironmentFile=/etc/restic/env
ExecStart=/usr/bin/restic backup /etc /home /srv /var/www --exclude-file /etc/restic/excludes --tag files --one-file-system
ExecStart=/bin/sh -c 'sudo -u postgres pg_dump -Fc shop | /usr/bin/restic backup --stdin --stdin-filename shop.dump --tag postgres'
ExecStartPost=/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
ExecStartPost=/usr/bin/restic check --read-data-subset=5%
Nice=10
IOSchedulingClass=idle[Unit]
Description=Nightly restic backup
[Timer]
OnCalendar=*-*-* 02:00
RandomizedDelaySec=30m
Persistent=true
[Install]
WantedBy=timers.targetsystemctl daemon-reload
systemctl enable --now restic-backup.timer
systemctl start restic-backup.service
journalctl -u restic-backup -n 30Send a success heartbeat to Uptime Kuma (push monitor) or write a metric for Node Exporter's textfile collector, so a missing backup raises an alert.
Real uses at work:
- Nightly encrypted backups of servers and databases to S3/MinIO or another site.
- Fast restores of single files or whole folders; database restore tests.
- Offsite copies: a second repository and
restic copybetween them.
Make it safe
Security checklist:
- Repository password in a password manager (two copies);
envandpasswordfiles mode600. - One S3 user per server, rights only on its prefix; bucket versioning/object lock against ransomware.
- 3-2-1: at least one copy offsite;
checkregularly; test restores every month. - Alert when a backup did not run (heartbeat), not only when it failed.
- Keep restic updated (bug fixes, faster formats).
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
unable to create lock in backend: repository is already locked | Another run is busy, or a run crashed. | Wait; if no restic process runs: restic unlock. |
wrong password or no key found | Wrong password file or variable. | Check RESTIC_PASSWORD_FILE; use the saved password. |
Fatal: unable to open config file / repository does not exist | Wrong RESTIC_REPOSITORY or not initialised. | Check the URL; restic init once. |
| Backups are slow every time | No cache, or many changed files (logs, caches). | Set RESTIC_CACHE_DIR; exclude caches and Docker data. |
| The repository grows forever | No forget --prune. | Add the retention policy and prune. |
SignatureDoesNotMatch with S3 | Wrong keys or clock skew. | Check keys; sync time with chrony. |
Next steps
- Quick how-to: Back up a server with restic.
- Quick how-tos: Create and extract tar.gz archives, Copy files between servers, Create a systemd timer.
- Where to store: MinIO / S3, AWS CLI. Database dumps: PostgreSQL, MySQL.
- Alert when it does not run: Uptime Kuma push monitors, Node Exporter textfile.
- Simple copies: Command page: rsync. The 3-2-1 rule: Backups.
1What happens if you lose the restic repository password?
The backups can never be decrypted — save the password in a password manager.
2Why run restic check --read-data-subset=5% regularly?
It reads and verifies a part of the data each time, so damaged backups are found before you need them.