This commit is contained in:
2026-03-02 19:30:31 +01:00
parent c8b21cb41c
commit 7accc13053
3 changed files with 75 additions and 179 deletions

View File

@@ -1,164 +0,0 @@
#!/usr/bin/env bash
#####!/bin/bash
########### Initialisierung ##############
#### https://docs.hetzner.com/de/robot/storage-box/backup-space-ssh-keys/
## Führe auf dem Clienten die folgenden Befehle aus:
# ssh-keygen
# cat ~/.ssh/id_rsa.pub | ssh -p23 u338XXX@u338XXX.your-storagebox.de install-ssh-key
###### Hier deine Daten einfügen #########
export BORG_PASSPHRASE="%ci5pKqWvXj!iBm9khAR@Z2ohJ2inMMht8ZNsU*"
BACKUP_USER="u358899"
REPOSITORY_DIR="paperless"
##########################################
LOG_DIR="/paperless/backuplogs"
LOG="$LOG_DIR/backup_storage.log"
echo "MOIN!" >> /paperless/test.log
if [ ! -d "$LOG_DIR" ]; then
mkdir -p "$LOG_DIR"
fi
full_path=$(realpath $0)
dir_path=$(dirname $full_path)
echo $dir_path
## Hinweis: Für die Verwendung mit einem Backup-Account muss
## 'your-storagebox.de' in 'your-backup.de' geändert werden.
REPOSITORY="ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}"
## Zeitstempel-Variable setzen
TIMESTAMP=$(date +'%Y-%m-%d_%H:%M')
##
## Ausgabe in Logdatei schreiben
##
exec > >(tee -i ${LOG})
exec 2>&1
start_time=$(date +'%Y-%m-%d %H:%M:%S')
echo "###### Backup gestartet: $start_time ######"
## Überprüfen, ob eine spezielle Aktion durchgeführt werden soll
BACKUP_SUFFIX=""
case "$1" in
NEW_INIT)
echo "Überprüfe, ob das Verzeichnis backups/${REPOSITORY_DIR} existiert..."
ssh -p23 ${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de "[ -d backups/${REPOSITORY_DIR} ] || mkdir -p backups/${REPOSITORY_DIR}"
echo "Das Repository wird komplett gelöscht und neu angelegt..."
borg delete --force --stats $REPOSITORY
borg init --encryption=repokey $REPOSITORY
BACKUP_SUFFIX="_NEW_INIT"
;;
INIT)
echo "Überprüfe, ob das Verzeichnis backups/${REPOSITORY_DIR} existiert..."
ssh -p23 ${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de "[ -d backups/${REPOSITORY_DIR} ] || mkdir -p backups/${REPOSITORY_DIR}"
echo "Überprüfe, ob das Repository existiert..."
if borg info $REPOSITORY > /dev/null 2>&1; then
echo "Das Repository existiert bereits. Vorgang wird abgebrochen."
exit 1
else
echo "Das Repository wird neu angelegt..."
borg init --encryption=repokey $REPOSITORY
fi
BACKUP_SUFFIX="_INIT"
;;
?)
echo -e "\n######################################"
echo -e "Verwendung des Backup-Skripts:"
echo -e "######################################"
echo -e "Ohne Parameter:"
echo -e " Führt ein reguläres Backup durch und hängt an den Backup-Namen das aktuelle Datum und die Uhrzeit."
echo -e "\nParameter:"
echo -e " NEW_INIT - Löscht das Repository komplett und legt es neu an."
echo -e " INIT - Legt das Repository neu an, wenn es nicht bereits existiert."
echo -e " ? - Zeigt diese Hilfemeldung an und bricht das Skript ab."
echo -e "\nBeispiele:"
echo -e " ./backup_script.sh"
echo -e " ./backup_script.sh NEW_INIT"
echo -e " ./backup_script.sh INIT"
echo -e " ./backup_script.sh ?"
echo -e "\nBackups auflisten mit:"
echo -e " borg list ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}\n"
echo -e "Rücksichern einzelner Verzeichnisse mit:"
echo -e " cd /mytmp # Wechseln Sie in ein Testverzeichnis, um das Backup zu testen."
echo -e " borg extract ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}::${TIMESTAMP}${BACKUP_SUFFIX} etc var lib lib64 sbin usr bin"
echo -e "######################################\n"
echo -e "Komplette Rücksicherung mit:"
echo -e "cd / # Wechseln Sie in das Root-Verzeichnis, um das gesamte System wiederherzustellen."
echo -e "borg extract ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}::${TIMESTAMP}${BACKUP_SUFFIX}"
echo -e "######################################\n"
echo -e "Auf den Backup-Server verbinden:"
echo -e "ssh -p23 ${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de"
echo -e "Verzeichnisinhalt anzeigen:"
echo -e "ls backups/${REPOSITORY_DIR}"
echo -e "Verzeichnis der aktuellen Backups löschen:"
echo -e "rm -rf backups/${REPOSITORY_DIR}"
echo -e "######################################\n"
exit 0
;;
esac
## Überprüfen, ob ein zusätzlicher Parameter übergeben wurde
if [ -n "$1" ] && [ "$1" != "INIT" ] && [ "$1" != "NEW_INIT" ]; then
BACKUP_SUFFIX="_$1"
fi
##
## Zu sichernde Verzeichnisse
##
# Hier werden alle Verzeichnisse im Root-Verzeichnis gesichert, außer den ausgeschlossenen Verzeichnissen
DIRS_TO_BACKUP=(
"/paperless/paperless-ngx/export"
)
##
## Dateien ins Repository übertragen
##
echo "Übertrage Dateien ..."
borg create -v --stats \
$REPOSITORY::"${TIMESTAMP}${BACKUP_SUFFIX}" \
"${DIRS_TO_BACKUP[@]}" # \
end_time=$(date +'%Y-%m-%d %H:%M:%S')
duration=$(date -u -d @$(( $(date -d "$end_time" +%s) - $(date -d "$start_time" +%s) )) +%H:%M:%S)
echo "###### Backup beendet: $end_time ######"
echo "Time (start): $start_time"
echo "Time (end): $end_time"
echo "Duration: $duration"
echo -e "\n######################################"
echo -e "Backups auflisten mit:"
echo -e "borg list ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}\n"
echo -e "Rücksichern einzelner Verzeichnisse mit:"
echo -e "cd /mytmp # Wechseln Sie in ein Testverzeichnis, um das Backup zu testen."
echo -e "borg extract ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}::${TIMESTAMP}${BACKUP_SUFFIX} etc var lib lib64 sbin usr bin"
echo -e "######################################\n"
echo -e "Komplette Rücksicherung mit:"
echo -e "borg extract ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR}::${TIMESTAMP}${BACKUP_SUFFIX}"
echo -e "######################################\n"
echo -e "Auf den Backup-Server verbinden:"
echo -e "ssh -p23 ${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de"
echo -e "Verzeichnisinhalt anzeigen:"
echo -e "ls backups/${REPOSITORY_DIR}"
echo -e "Verzeichnis der aktuellen Backups löschen:"
echo
echo -e "rm -rf backups/${REPOSITORY_DIR}"
echo -e "######################################\n"
borg list ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${REPOSITORY_DIR} >> ${LOG}

View File

@@ -175,18 +175,3 @@ borg list ssh://${BACKUP_USER}@${BACKUP_USER}.your-storagebox.de:23/./backups/${
```
</details>
/paperless/backup_storage:
``` snippet
--8<-- "/docs/backup_restore/proxmox/paperless/backup_storage.sh"
```
[Location /paperless/backup_storage:](/docs/backup_restore/proxmox/paperless/backup_storage.sh)

View File

@@ -7,7 +7,82 @@
- Log: /root/pve-backup.log
- Skript: [Location: /root/backup-pve-configs.sh](./backup_pve_configs.sh)
<details>
<summary>Location: /root/backup-pve-configs.sh :</summary>
```
#!/bin/bash
BACKUP_DIR="/mnt/storagebox-nocrypt/pve-configs-backup"
TODAY=$(date +%T_%F)-pve-configs-backup
LOGFILE="pve-backup.log"
mkdir -p "$BACKUP_DIR/$TODAY"
FILES=(
"/root/"
"/etc/pve/"
"/etc/network/interfaces"
"/etc/hosts"
"/etc/resolv.conf"
"/etc/hostname"
"/etc/timezone"
"/etc/passwd"
"/etc/group"
"/etc/shadow"
"/root/.ssh/"
"/etc/vzdump.conf"
"/etc/ssh/sshd_config"
"/var/lib/pve-cluster/"
"/etc/ssh/"
"/etc/cron.d/"
"/etc/cron.daily/"
"/etc/cron.hourly/"
"/etc/cron.weekly/"
"/etc/cron.monthly/"
"/var/spool/cron/"
"/etc/fstab"
"/etc/default/"
"/etc/apt/sources.list"
"/etc/apt/sources.list.d/"
"/var/log/"
"/etc/systemd/"
"/etc/sysctl.conf"
"/etc/security/"
"/var/backups/"
"/etc/fail2ban/"
"/root/backup-pve-configs.sh"
)
EXCLUDE_DIRS=(
"/mnt/storagebox-crypt"
"/mnt/storagebox-nocrypt"
"/var/lib/vz/images/"
"/var/lib/lxc/"
"/var/lib/vz/private/"
"/var/lib/lxcfs/"
)
# rsync-Ausschlussparameter erstellen
EXCLUDE_PARAMS=()
for EXCLUDE in "${EXCLUDE_DIRS[@]}"; do
EXCLUDE_PARAMS+=(--exclude="$EXCLUDE")
done
for FILE in "${FILES[@]}"; do
if [ -e "$FILE" ]; then
echo "Kopiere $FILE..."
rsync -aL --relative --ignore-missing-args --safe-links "${EXCLUDE_PARAMS[@]}" "$FILE" "$BACKUP_DIR/$TODAY/" 2>/dev/null
else
echo "Warnung: $FILE existiert nicht und wird uebersprungen." >> ${LOGFILE}
fi
done
find "$BACKUP_DIR" -mindepth 1 -maxdepth 1 -type d -mtime +14 -exec rm -rf {} \;
echo "Backup fuer $TODAY abgeschlossen." >> ${LOGFILE}
```
</details>