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 resticCentOS/AlmaLinux
dnf install resticNeueste 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/resticAuto-Completion
restic generate --bash-completion /etc/bash_completion.d/resticRepository erstellen
Ein Repository ist der Speicherort für Backups.
Lokales Repository
restic init --repo /backup/restic-repoSFTP-Repository
restic init --repo sftp:user@server:/backup/resticS3-Repository
export AWS_ACCESS_KEY_ID="IHRE_KEY_ID"
export AWS_SECRET_ACCESS_KEY="IHR_SECRET"
restic init --repo s3:s3.amazonaws.com/bucket-nameBackblaze B2
export B2_ACCOUNT_ID="ID"
export B2_ACCOUNT_KEY="KEY"
restic init --repo b2:bucket-name:/resticSie werden nach einem Passwort gefragt - merken Sie es sich!
Erstes Backup
Einfaches Backup
restic -r /backup/restic-repo backup /var/wwwMehrere Verzeichnisse
restic -r /backup/restic-repo backup /var/www /home /etcMit 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.txtSnapshots anzeigen
restic -r /backup/restic-repo snapshotsAusgabe:
ID Time Host Tags Paths
a1b2c3d4 2024-01-20 03:00:00 server /var/www
e5f6g7h8 2024-01-21 03:00:00 server /var/wwwDaten wiederherstellen
Komplettes Snapshot
restic -r /backup/restic-repo restore latest --target /restoreBestimmter Snapshot
restic -r /backup/restic-repo restore a1b2c3d4 --target /restoreEinzelne Datei/Verzeichnis
restic -r /backup/restic-repo restore latest --target /restore \
--include /var/www/config.phpDateien mounten
mkdir /mnt/restic
restic -r /backup/restic-repo mount /mnt/resticSnapshots 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 12Mit Prune (Speicher freigeben)
restic -r /backup/restic-repo forget \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 12 \
--pruneBackup-Integrität prüfen
# Schnell (nur Metadaten)
restic -r /backup/restic-repo check
# Gründlich (alle Daten)
restic -r /backup/restic-repo check --read-dataAutomatisierung 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_FILEchmod 700 /root/backup.shCronjob
crontab -e0 3 * * * /root/backup.shPasswort 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-envNützliche Optionen
Bandbreite begrenzen
restic backup /var/www --limit-upload 5000 # 5 MB/s
restic restore latest --limit-download 5000Tags verwenden
restic backup /var/www --tag webserver --tag daily
restic snapshots --tag webserverFortschritt anzeigen
restic backup /var/www --verboseTrockenlauf
restic backup /var/www --dry-runVergleich: 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 16Langsame Netzwerke
restic backup /var/www \
--limit-upload 1000 \
--verboseGroße Repositories
# Cache nutzen
restic --cache-dir /var/cache/restic backup /var/wwwTroubleshooting
"Repository not initialized"
restic init --repo /pfad/zum/repoPasswort 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 pruneRepository reparieren
restic -r /backup/restic-repo check --read-data
restic -r /backup/restic-repo rebuild-indexFazit
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.