Restic ist ein modernes Backup-Programm, das Deduplizierung, Verschlüsselung und verschiedene Storage-Backends unterstützt.

Vorteile von Restic

  • Schnell: Inkrementelle Backups durch Deduplizierung
  • Sicher: Verschlüsselung mit AES-256
  • Flexibel: Lokale Festplatten, SFTP, S3, Backblaze B2, etc.
  • Einfach: Intuitive Bedienung
  • Verifizierbar: Backup-Integrität prüfen

Installation

Ubuntu/Debian

apt install restic

CentOS/AlmaLinux

dnf install restic

Neueste Version

wget https://github.com/restic/restic/releases/latest/download/restic_0.16.4_linux_amd64.bz2
bunzip2 restic_*.bz2
chmod +x restic_*
mv restic_* /usr/local/bin/restic

Auto-Completion

restic generate --bash-completion /etc/bash_completion.d/restic

Repository erstellen

Ein Repository ist der Speicherort für Backups.

Lokales Repository

restic init --repo /backup/restic-repo

SFTP-Repository

restic init --repo sftp:user@server:/backup/restic

S3-Repository

export AWS_ACCESS_KEY_ID="IHRE_KEY_ID"
export AWS_SECRET_ACCESS_KEY="IHR_SECRET"

restic init --repo s3:s3.amazonaws.com/bucket-name

Backblaze B2

export B2_ACCOUNT_ID="ID"
export B2_ACCOUNT_KEY="KEY"

restic init --repo b2:bucket-name:/restic

Sie werden nach einem Passwort gefragt - merken Sie es sich!

Erstes Backup

Einfaches Backup

restic -r /backup/restic-repo backup /var/www

Mehrere Verzeichnisse

restic -r /backup/restic-repo backup /var/www /home /etc

Mit Ausschlüssen

restic -r /backup/restic-repo backup /var/www \
  --exclude="*.log" \
  --exclude="cache/" \
  --exclude="node_modules"

Mit Exclude-Datei

Erstellen Sie /etc/restic/excludes.txt:

*.log
*.tmp
cache/
node_modules/
.git/
__pycache__/
restic -r /backup/restic-repo backup /var/www \
  --exclude-file=/etc/restic/excludes.txt

Snapshots anzeigen

restic -r /backup/restic-repo snapshots

Ausgabe:

ID        Time                 Host    Tags   Paths
a1b2c3d4  2024-01-20 03:00:00  server         /var/www
e5f6g7h8  2024-01-21 03:00:00  server         /var/www

Daten wiederherstellen

Komplettes Snapshot

restic -r /backup/restic-repo restore latest --target /restore

Bestimmter Snapshot

restic -r /backup/restic-repo restore a1b2c3d4 --target /restore

Einzelne Datei/Verzeichnis

restic -r /backup/restic-repo restore latest --target /restore \
  --include /var/www/config.php

Dateien mounten

mkdir /mnt/restic
restic -r /backup/restic-repo mount /mnt/restic

Snapshots sind dann unter /mnt/restic/snapshots/ zugänglich.

Alte Backups löschen

Retention-Policies

# Behalte: 7 Tage, 4 Wochen, 12 Monate
restic -r /backup/restic-repo forget \
  --keep-daily 7 \
  --keep-weekly 4 \
  --keep-monthly 12

Mit Prune (Speicher freigeben)

restic -r /backup/restic-repo forget \
  --keep-daily 7 \
  --keep-weekly 4 \
  --keep-monthly 12 \
  --prune

Backup-Integrität prüfen

# Schnell (nur Metadaten)
restic -r /backup/restic-repo check

# Gründlich (alle Daten)
restic -r /backup/restic-repo check --read-data

Automatisierung mit Cron

Backup-Skript

Erstellen Sie /root/backup.sh:

#!/bin/bash

# Konfiguration
export RESTIC_REPOSITORY="/backup/restic-repo"
export RESTIC_PASSWORD="IhrPasswort"
# Oder mit Passwort-Datei:
# export RESTIC_PASSWORD_FILE="/root/.restic-password"

BACKUP_PATHS="/var/www /home /etc"
EXCLUDE_FILE="/etc/restic/excludes.txt"
LOG_FILE="/var/log/restic.log"

# Backup erstellen
echo "$(date): Backup gestartet" >> $LOG_FILE
restic backup $BACKUP_PATHS \
  --exclude-file=$EXCLUDE_FILE \
  >> $LOG_FILE 2>&1

# Alte Backups bereinigen
restic forget \
  --keep-daily 7 \
  --keep-weekly 4 \
  --keep-monthly 12 \
  --prune \
  >> $LOG_FILE 2>&1

# Integrität prüfen
restic check >> $LOG_FILE 2>&1

echo "$(date): Backup beendet" >> $LOG_FILE
chmod 700 /root/backup.sh

Cronjob

crontab -e
0 3 * * * /root/backup.sh

Passwort sicher speichern

Passwort-Datei

echo "IhrPasswort" > /root/.restic-password
chmod 600 /root/.restic-password

export RESTIC_PASSWORD_FILE="/root/.restic-password"

Environment-Variablen in Skripten

Nie im Klartext in Skripten, sondern:

# In .bashrc oder separater Datei
source /root/.restic-env

Nützliche Optionen

Bandbreite begrenzen

restic backup /var/www --limit-upload 5000    # 5 MB/s
restic restore latest --limit-download 5000

Tags verwenden

restic backup /var/www --tag webserver --tag daily
restic snapshots --tag webserver

Fortschritt anzeigen

restic backup /var/www --verbose

Trockenlauf

restic backup /var/www --dry-run

Vergleich: Restic vs. BorgBackup

| Feature | Restic | BorgBackup | |---------|--------|------------| | Geschwindigkeit | Schnell | Sehr schnell | | Cloud-Support | Ja (S3, B2, etc.) | Nur lokal/SSH | | Verschlüsselung | AES-256 | AES-256 | | Deduplizierung | Ja | Ja | | Mount-Funktion | Ja | Ja | | Single Binary | Ja | Nein |

Tipps für große Backups

Erstes Backup beschleunigen

# Mehrere parallele Uploads
restic backup /var/www --verbose --pack-size 16

Langsame Netzwerke

restic backup /var/www \
  --limit-upload 1000 \
  --verbose

Große Repositories

# Cache nutzen
restic --cache-dir /var/cache/restic backup /var/www

Troubleshooting

"Repository not initialized"

restic init --repo /pfad/zum/repo

Passwort vergessen

Ohne Passwort kein Zugriff möglich. Immer sicher aufbewahren!

Abgebrochenes Backup

# Lock entfernen
restic -r /backup/restic-repo unlock

# Unvollständige Daten aufräumen
restic -r /backup/restic-repo prune

Repository reparieren

restic -r /backup/restic-repo check --read-data
restic -r /backup/restic-repo rebuild-index

Fazit

Restic ist eines der besten modernen Backup-Tools. Die Kombination aus Deduplizierung, Verschlüsselung und Cloud-Unterstützung macht es ideal für Server-Backups. Die einfache Bedienung senkt die Einstiegshürde gegenüber komplexeren Lösungen.