Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige Überarbeitung | |||
infrastruktur:host:billy:billy-borg-client-setup [05.09.2024 02:19] – gelöscht - Externe Bearbeitung (Unknown date) 127.0.0.1 | infrastruktur:host:billy:billy-borg-client-setup [05.09.2024 02:19] (aktuell) – ↷ Seitename wurde von infrastruktur:host:billy:client-setup auf infrastruktur:host:billy:billy-borg-client-setup geändert Linus Lüssing | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Borg Backup Client Setup ====== | ||
+ | Einrichtung eines Client-Gerätes zur Nutzung von BorgBackup auf [[infrastruktur: | ||
+ | |||
+ | ==== Initialisierung: | ||
+ | |||
+ | Anmerkung: Ersetze " | ||
+ | |||
+ | Erzeuge einen SSH Schlüssel, mit dem dein borg client im Hintergrund später die Backups machen darf: | ||
+ | |||
+ | < | ||
+ | $ ssh-keygen -f ~/ | ||
+ | </ | ||
+ | |||
+ | Füge willi und billy ähnlich wie folgt in deine ~/ | ||
+ | |||
+ | **~/ | ||
+ | < | ||
+ | Host willi | ||
+ | User tux | ||
+ | Hostname willi.nobreakspace.org | ||
+ | IdentityFile ~/ | ||
+ | |||
+ | Host billyborg | ||
+ | Hostname billy.nobreakspace.org | ||
+ | User tux | ||
+ | IdentityFile ~/ | ||
+ | ProxyCommand ssh -4 willi -o ControlMaster=no -W " | ||
+ | </ | ||
+ | |||
+ | Nun installiere den public key deines neuen SSH keys auf willi und billi: | ||
+ | |||
+ | < | ||
+ | $ ssh-copy-id -i ~/ | ||
+ | $ cat ~/ | ||
+ | </ | ||
+ | |||
+ | ==== Initialisierung: | ||
+ | |||
+ | Initilisiere dein Borg auf billy: | ||
+ | |||
+ | < | ||
+ | $ borg init --encryption=keyfile ssh:// | ||
+ | </ | ||
+ | |||
+ | Exportiere und drucke wie vom obigen "borg init" Befehl empfohlen deinen Borg Schlüssel aus und bewahre ihn und das Passwort sicher und getrennt voneinander auf. | ||
+ | |||
+ | WICHTIG: OHNE DIESE KOMMST DU SPÄTER NICHT MEHR AUF DEINE BACKUPS! | ||
+ | |||
+ | ==== Borg Backup Beispiel Script ==== | ||
+ | |||
+ | Dies ist ein Beispiel. Hier die BORG_PASSPHRASE anpassen, sowie die excludes. | ||
+ | |||
+ | Möglichst alle größeren oder Binär-Daten, | ||
+ | |||
+ | Dieses Skript kann dann so schon ausgeführt werden (nach einem "chmod +x ~/ | ||
+ | |||
+ | Der zweite, untere Befehle des Skripts löscht redundante Backups und stellt sicher, dass nur eine sinnvolle Anzahl an täglichen/ | ||
+ | |||
+ | **~/ | ||
+ | < | ||
+ | #!/bin/sh | ||
+ | |||
+ | export BORG_REPO=ssh:// | ||
+ | export BORG_PASSPHRASE="< | ||
+ | |||
+ | # some helpers and error handling: | ||
+ | info() { printf "\n%s %s\n\n" | ||
+ | trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM | ||
+ | |||
+ | info " | ||
+ | |||
+ | # | ||
+ | borg create \ | ||
+ | --verbose | ||
+ | --filter AME \ | ||
+ | --list | ||
+ | --stats | ||
+ | --show-rc | ||
+ | --compression lz4 \ | ||
+ | --exclude-caches | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | --exclude " | ||
+ | \ | ||
+ | ::' | ||
+ | ${HOME}/ | ||
+ | |||
+ | backup_exit=$? | ||
+ | |||
+ | info " | ||
+ | |||
+ | # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly | ||
+ | # archives of THIS machine. The ' | ||
+ | # limit prune' | ||
+ | # other machines' | ||
+ | |||
+ | borg prune \ | ||
+ | --list | ||
+ | --prefix ' | ||
+ | --show-rc | ||
+ | --keep-daily | ||
+ | --keep-weekly | ||
+ | --keep-monthly | ||
+ | --keep-yearly | ||
+ | |||
+ | prune_exit=$? | ||
+ | |||
+ | # use highest exit code as global exit code | ||
+ | global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) | ||
+ | |||
+ | if [ ${global_exit} -eq 1 ]; | ||
+ | then | ||
+ | info " | ||
+ | fi | ||
+ | |||
+ | if [ ${global_exit} -gt 1 ]; | ||
+ | then | ||
+ | info " | ||
+ | fi | ||
+ | |||
+ | exit ${global_exit} | ||
+ | </ | ||
+ | |||
+ | ==== Automatische Backups per systemd timer ==== | ||
+ | |||
+ | < | ||
+ | $ mkdir -p ~/borg/logs | ||
+ | </ | ||
+ | |||
+ | **~/ | ||
+ | < | ||
+ | [Unit] | ||
+ | Description=Borg Backup | ||
+ | Conflicts=shutdown.target | ||
+ | # | ||
+ | # | ||
+ | |||
+ | [Service] | ||
+ | Type=oneshot | ||
+ | ExecStart=%h/ | ||
+ | Restart=on-failure | ||
+ | RestartSec=30min | ||
+ | StandardOutput=append: | ||
+ | StandardError=append: | ||
+ | Nice=15 | ||
+ | IOSchedulingClass=best-effort | ||
+ | IOSchedulingPriority=7 | ||
+ | </ | ||
+ | |||
+ | **~/ | ||
+ | < | ||
+ | [Unit] | ||
+ | Description=Run Borg Backup daily and on boot | ||
+ | |||
+ | [Timer] | ||
+ | OnBootSec=15min | ||
+ | OnUnitActiveSec=1d | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=timers.target | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | $ systemctl --user enable borg-backup-billy.timer | ||
+ | $ systemctl --user start borg-backup-billy.timer | ||
+ | </ | ||
+ | |||
+ | (ToDo: war da noch was, um OnBootSec in systemd zu aktivieren? Evtl. " | ||
+ | |||
+ | Überprüfe, | ||
+ | |||
+ | < | ||
+ | $ systemctl --user list-timers | ||
+ | $ systemctl --user status borg-backup-billy.timer | ||
+ | $ systemctl --user status borg-backup-billy.service | ||
+ | </ | ||
+ | |||
+ | Überprüfe auch, ob in ~/ | ||
+ | |||
+ | ==== (Vor)Letzter Check: Backups überprüfen ==== | ||
+ | |||
+ | < | ||
+ | $ borg info ssh:// | ||
+ | $ borg list ssh:// | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | $ mkdir / | ||
+ | $ borgfs ssh:// | ||
+ | </ | ||
+ | |||
+ | Prüfe nun, ob du in / | ||
+ | |||
+ | Zu letzt wieder schließen mit: | ||
+ | |||
+ | < | ||
+ | $ umount / | ||
+ | </ | ||
+ | |||
+ | ==== Allerletzter Check: Backups mit ausgedruckten Schlüssel wiederherstellen ==== | ||
+ | |||
+ | ToDo |