Skip to Content
DokumentationBetriebSystemadministrationSicherung und Wiederherstellung

Sicherung und Wiederherstellung

Die Datensicherung ist einer der wichtigsten Aspekte der Systemadministration. In diesem Artikel werden verschiedene Backup- und Wiederherstellungslösungen in Ubuntu 26.04 vorgestellt, um Ihnen bei der Auswahl des richtigen Tools für Ihre Anforderungen zu helfen.

rsync – Flexibles Synchronisierungstool

rsync ist ein schnelles, flexibles Tool zur Dateisynchronisierung, das inkrementelle Übertragungen unterstützt und eines der am häufigsten verwendeten Backup-Tools unter Linux ist.

Grundlegende Verwendung

# Local directory sync rsync -av /source/directory/ /backup/directory/ # Note: the trailing slash on the source path matters # /source/dir/ -> syncs the contents of the directory # /source/dir -> syncs the directory itself (including the directory name)

Allgemeine Optionen

# -a archive mode (preserves permissions, timestamps, symlinks, etc.) # -v verbose output # -z compress during transfer # -h human-readable output # --progress show progress # --delete delete files in the target that don't exist in the source # Complete local backup command rsync -avh --progress /home/user/ /backup/home-user/ # Backup with exclusion rules rsync -avh --progress \ --exclude='.cache' \ --exclude='node_modules' \ --exclude='.local/share/Trash' \ /home/user/ /backup/home-user/ # Using an exclude file rsync -avh --exclude-from='/home/user/rsync-excludes.txt' \ /home/user/ /backup/home-user/

Remote-Backup

# Backup to a remote server via SSH rsync -avz -e ssh /home/user/ user@remote:/backup/home-user/ # Specify SSH port rsync -avz -e "ssh -p 2222" /home/user/ user@remote:/backup/home-user/ # Restore from a remote server rsync -avz user@remote:/backup/home-user/ /home/user/ # Use --delete to keep both sides in sync rsync -avz --delete /home/user/ user@remote:/backup/home-user/

Automatisiertes Rsync-Sicherungsskript

Erstellen Sie ein Backup-Skript:

sudo nano /usr/local/bin/daily-backup.sh
#!/bin/bash # Configuration SOURCE="/home/" DEST="/backup/daily" LOG="/var/log/backup.log" DATE=$(date +%Y-%m-%d_%H%M%S) # Create log entry echo "===== Backup started: $DATE =====" >> "$LOG" # Execute backup rsync -avh --delete \ --exclude='.cache' \ --exclude='node_modules' \ --exclude='.local/share/Trash' \ "$SOURCE" "$DEST" >> "$LOG" 2>&1 # Record result if [ $? -eq 0 ]; then echo "Backup completed successfully: $(date)" >> "$LOG" else echo "Backup failed: $(date)" >> "$LOG" fi
sudo chmod +x /usr/local/bin/daily-backup.sh

Planen Sie es mit cron:

# Run backup every day at 2 AM sudo crontab -e # Add: 0 2 * * * /usr/local/bin/daily-backup.sh

Timeshift – System-Snapshots

Timeshift konzentriert sich auf Systemdatei-Snapshots und -Wiederherstellung, ähnlich wie die Windows-Systemwiederherstellung.

Installation und Konfiguration

# Install Timeshift sudo apt install timeshift # Launch the graphical interface sudo timeshift-gtk # Create a snapshot via command line sudo timeshift --create --comments "Before installing NVIDIA driver" # List all snapshots sudo timeshift --list # Restore to a specific snapshot sudo timeshift --restore --snapshot '2026-03-24_10-00-00' # Delete a snapshot sudo timeshift --delete --snapshot '2026-03-24_10-00-00'

Befehlszeilenkonfiguration

# View current configuration sudo timeshift --config # Set snapshot type (RSYNC or BTRFS) sudo timeshift --snapshot-device /dev/sda2

Timeshift-Konfigurationsdatei

Bearbeiten Sie /etc/timeshift/timeshift.json:

{ "backup_device_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "parent_device_uuid": "", "do_first_run": false, "btrfs_mode": false, "include_btrfs_home": false, "schedule_monthly": false, "schedule_weekly": true, "schedule_daily": true, "schedule_hourly": false, "schedule_boot": false, "count_monthly": 2, "count_weekly": 3, "count_daily": 5, "count_hourly": 0, "count_boot": 0, "exclude": [ "/home/**", "/root/**" ] }

Btrfs-Snapshot-Modus

Wenn das System das Btrfs-Dateisystem verwendet, kann Timeshift native Btrfs-Snapshots nutzen, die schneller sind und weniger Speicherplatz beanspruchen:

# Verify filesystem type df -T / # If it's Btrfs, select BTRFS mode in Timeshift sudo timeshift --btrfs

Deja Dup – Desktop-Backup-Tool

Deja Dup (GNOME Backups) ist ein benutzerfreundliches Backup-Tool für die Ubuntu-Desktop-Umgebung, das für Privatanwender geeignet ist.

Installation und Nutzung

# Install (usually pre-installed on Ubuntu Desktop) sudo apt install deja-dup

Deja Dup bietet eine grafische Oberfläche, auf die Sie über „Einstellungen“ oder durch die Suche nach „Backups“ im App-Menü zugreifen können.

Hauptmerkmale:

  • Unterstützt Sicherungen auf lokale Festplatten, externe Laufwerke und Netzwerkspeicher
  • Unterstützt die Sicherung auf Google Drive und anderen Cloud-Speichern
  • Automatische Verschlüsselung von Backups
  • Unterstützung für inkrementelle Backups
  • Geplante automatische Backups

Befehlszeilenoperationen

Deja Dup verwendet Duplicity als Backend:

# Manually run a backup deja-dup --backup # Restore files deja-dup --restore

Disk-Image-Sicherung

Erstellen von Disk-Images mit dd

# Create a full disk image sudo dd if=/dev/sda of=/backup/sda.img bs=4M status=progress # Compressed image sudo dd if=/dev/sda bs=4M status=progress | gzip > /backup/sda.img.gz # Restore from an image sudo dd if=/backup/sda.img of=/dev/sda bs=4M status=progress # Restore from a compressed image gunzip -c /backup/sda.img.gz | sudo dd of=/dev/sda bs=4M status=progress

Verwendung von Clonezilla

Clonezilla ist ein leistungsstarkes Tool zum Klonen und Imaging von Datenträgern:

# Install Clonezilla sudo apt install clonezilla # It is generally recommended to boot from a Clonezilla Live USB # Download: https://clonezilla.org/downloads.php

Systemsicherung mit tar

# Back up the entire system (excluding unnecessary directories) sudo tar czpf /backup/system-$(date +%Y%m%d).tar.gz \ --exclude=/backup \ --exclude=/proc \ --exclude=/sys \ --exclude=/dev \ --exclude=/run \ --exclude=/tmp \ --exclude=/mnt \ --exclude=/media \ --exclude=/lost+found \ / # Restore the system sudo tar xzpf /backup/system-20260324.tar.gz -C /

Datenbanksicherung

MySQL / MariaDB

# Back up a single database mysqldump -u root -p database_name > /backup/db-$(date +%Y%m%d).sql # Back up all databases mysqldump -u root -p --all-databases > /backup/all-db-$(date +%Y%m%d).sql # Restore a database mysql -u root -p database_name < /backup/db-20260324.sql

PostgreSQL

# Back up a single database sudo -u postgres pg_dump dbname > /backup/pg-$(date +%Y%m%d).sql # Back up all databases sudo -u postgres pg_dumpall > /backup/pg-all-$(date +%Y%m%d).sql # Restore sudo -u postgres psql dbname < /backup/pg-20260324.sql

Empfehlungen zur Backup-Strategie

Die 3-2-1-Backup-Regel

  • 3 Kopien Ihrer Daten (das Original + 2 Backups)
  • 2 verschiedene Speichermedien (z. B. lokale Festplatte + Cloud-Speicher)
  • 1 Offsite-Backup (Schutz vor physischen Katastrophen)

Empfehlungen nach Szenario

SzenarioEmpfohlene WerkzeugeBackup-Häufigkeit
Persönlicher Desktop-BenutzerDeja Dup + TimeshiftTäglich / Wöchentlich
Entwicklungsarbeitsplatzrsync + TimeshiftTäglich
Webserverrsync + DatenbanksicherungTäglich/stündlich
Kritischer Unternehmensserverrsync + LVM-Snapshots + Offsite-BackupEchtzeit / stündlich

Sicherungen überprüfen

Die regelmäßige Überprüfung der Backup-Integrität ist unerlässlich:

# Verify a tar backup tar tzf /backup/system-20260324.tar.gz > /dev/null # Verify an rsync backup rsync -avhn --delete /source/ /backup/ # dry-run to compare differences # Perform periodic restore drills