Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 89restic · System

Install and set up restic (encrypted backups)

restic makes fast, encrypted, deduplicated backups of files to a local disk, an SFTP server, S3/MinIO, Backblaze B2, Azure, Google Cloud or a restic REST server. Only changed data is uploaded after the first run, every snapshot is a full point-in-time view, and everything is encrypted before it leaves the server. This guide installs restic on RHEL and Ubuntu, creates a repository on S3, backs up files and database dumps, sets retention, checks the backups, restores, and runs it all with a systemd timer.

  • 11 Lessen
  • 12 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

89.1

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.

ItemValue
Packagerestic (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)
Backendslocal path, sftp:, s3:, b2:, azure:, gs:, rest:, rclone:

89.2

Install on RHEL, Rocky, Alma and Fedora

dnf -y install epel-release
dnf -y install restic
restic version

Commando's in deze les

89.3

Install on Ubuntu and Debian

apt-get update
apt-get install -y restic
restic version

The distro version can be old; the binary from github.com/restic/restic/releases can update itself (restic self-update).

89.4

First configuration: repository and secrets

Keep the settings in a root-only environment file, and the password in its own file:

/etc/restic/env
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/restic
mkdir -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/web1

Let 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:

/etc/restic/excludes
/proc
/sys
/dev
/run
/tmp
/var/tmp
/var/cache
/var/lib/docker
/home/*/.cache
*.iso

89.5

Back 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 / optionWhy
--exclude-file, --one-file-systemNo caches, virtual file systems or other mounts.
--stdinBack up a database dump directly from the pipe.
--tagFind and manage snapshots by type.
forget … --pruneThe 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.

89.6

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/restic

restic mount shows all snapshots as folders — copy what you need, then umount /mnt/restic.

89.7

Run it every night with systemd

/etc/systemd/system/restic-backup.service
[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
/etc/systemd/system/restic-backup.timer
[Unit]
Description=Nightly restic backup
 
[Timer]
OnCalendar=*-*-* 02:00
RandomizedDelaySec=30m
Persistent=true
 
[Install]
WantedBy=timers.target
systemctl daemon-reload
systemctl enable --now restic-backup.timer
systemctl start restic-backup.service
journalctl -u restic-backup -n 30

Send 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 copy between them.

89.8

Make it safe

Security checklist:

  • Repository password in a password manager (two copies); env and password files mode 600.
  • One S3 user per server, rights only on its prefix; bucket versioning/object lock against ransomware.
  • 3-2-1: at least one copy offsite; check regularly; test restores every month.
  • Alert when a backup did not run (heartbeat), not only when it failed.
  • Keep restic updated (bug fixes, faster formats).

Commando's in deze les

89.9

Update and remove

dnf -y upgrade restic
apt-get install --only-upgrade -y restic
restic self-update
systemctl disable --now restic-backup.timer

89.10

Fix common problems

ProblemCauseFix
unable to create lock in backend: repository is already lockedAnother run is busy, or a run crashed.Wait; if no restic process runs: restic unlock.
wrong password or no key foundWrong password file or variable.Check RESTIC_PASSWORD_FILE; use the saved password.
Fatal: unable to open config file / repository does not existWrong RESTIC_REPOSITORY or not initialised.Check the URL; restic init once.
Backups are slow every timeNo cache, or many changed files (logs, caches).Set RESTIC_CACHE_DIR; exclude caches and Docker data.
The repository grows foreverNo forget --prune.Add the retention policy and prune.
SignatureDoesNotMatch with S3Wrong keys or clock skew.Check keys; sync time with chrony.

89.11

Next steps

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.

Commando's in deze les

Alle commando's in dit hoofdstuk