Update Scripts/borg.sh
This commit is contained in:
+18
-18
@@ -8,23 +8,23 @@ run_borgbackup () {
|
||||
|
||||
# Error-Funktion mit Gotify-Benachrichtigung
|
||||
notify-error () {
|
||||
sh /home/arne/.scripts/gotify.sh "Borg Backup Desktop" "Borg-Backup hatte einen Fehler."
|
||||
sh /home/$user/.scripts/gotify.sh "Borg Backup Desktop" "Borg-Backup hatte einen Fehler."
|
||||
}
|
||||
|
||||
# Erstelle Lock-File
|
||||
# https://www.putorius.net/lock-files-bash-scripts.html
|
||||
exec 100>"/home/arne/.borg/borg.lock" || exit 1
|
||||
exec 100>"/home/$user/.borg/borg.lock" || exit 1
|
||||
flock -n 100 || exit 1
|
||||
trap 'rm -f /home/arne/.borg/borg.lock' EXIT
|
||||
trap 'rm -f /home/$user/.borg/borg.lock' EXIT
|
||||
|
||||
# Desktop-Benachrichtigung, dass das Backup startet
|
||||
sudo -u arne DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
|
||||
sudo -u $user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
|
||||
notify-send -t 5000 'BorgBackup' 'Backup started..' && \
|
||||
sudo -u '#1000' XDG_RUNTIME_DIR=/run/user/1000 \
|
||||
paplay /usr/share/sounds/ocean/stereo/dialog-information.oga
|
||||
|
||||
# Verzeichnis für die Logdatei festlegen
|
||||
log="/home/arne/.borg/logs/$(date +%Y-%m-%d_%H:%M).log"
|
||||
log="/home/$user/.borg/logs/$(date +%Y-%m-%d_%H:%M).log"
|
||||
|
||||
# Adresse des Repositories festlegen
|
||||
repo="<Hier Repository einfügen>"
|
||||
@@ -40,14 +40,14 @@ run_borgbackup () {
|
||||
# https://borgbackup.readthedocs.io/en/stable/usage/create.html
|
||||
if nice -n 19 ionice -c 3 borg create -v --stats -C auto,zstd \
|
||||
${repo}::'{now:%Y-%m-%d_%H:%M}' \
|
||||
/home/arne/Daten/Bilder \
|
||||
/home/arne/Daten/Backups \
|
||||
/home/arne/Daten/Dokumente \
|
||||
/home/arne/Daten/Videos \
|
||||
/home/arne/Daten/VMs; then
|
||||
/home/$user/Daten/Bilder \
|
||||
/home/$user/Daten/Backups \
|
||||
/home/$user/Daten/Dokumente \
|
||||
/home/$user/Daten/Videos \
|
||||
/home/$user/Daten/VMs; then
|
||||
|
||||
# Desktop-Benachrichtigung, dass das Backup beendet ist
|
||||
sudo -u arne DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
|
||||
sudo -u $user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
|
||||
notify-send -t 5000 'BorgBackup' 'Backup finished. Start Pruning..'
|
||||
|
||||
# Zeitstempel für die Logdatei (Start)
|
||||
@@ -62,19 +62,19 @@ run_borgbackup () {
|
||||
echo && echo "Finished pruning: $(date)"
|
||||
|
||||
# Desktop-Benachrichtigung, dass die Bereinigung beendet ist
|
||||
sudo -u arne DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
|
||||
sudo -u $user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
|
||||
notify-send -t 5000 'BorgBackup' 'Pruning finished.'
|
||||
|
||||
# Logdateien löschen, die älter sind als 30 Tage
|
||||
command -v rmtrash >/dev/null || echo "rmtrash ist nicht installiert."
|
||||
/usr/bin/find /home/arne/.borg/logs/* -mtime +30 -exec sudo -u arne env XDG_RUNTIME_DIR="/run/user/$(id -u arne)" \
|
||||
/usr/bin/find /home/$user/.borg/logs/* -mtime +30 -exec sudo -u $user env XDG_RUNTIME_DIR="/run/user/$(id -u $user)" \
|
||||
/usr/bin/rmtrash -rf {} \;
|
||||
|
||||
# Lösche alte temporäre Datei (Wozu nochmal?)
|
||||
#find /home/arne/.borg/ -maxdepth 1 -type f ! -name "*.lock" ! -name "*.sh" ! -name "*last-run-$(date +%Y-%m-%d)*" -exec rm {} +
|
||||
#find /home/$user/.borg/ -maxdepth 1 -type f ! -name "*.lock" ! -name "*.sh" ! -name "*last-run-$(date +%Y-%m-%d)*" -exec rm {} +
|
||||
|
||||
# Lege temporäre Datei an, damit Borg nur einmal täglich läuft
|
||||
touch "/home/arne/.borg/last-run-$(date +%Y-%m-%d)"
|
||||
touch "/home/$user/.borg/last-run-$(date +%Y-%m-%d)"
|
||||
else
|
||||
notify-error && exit 1
|
||||
fi
|
||||
@@ -83,10 +83,10 @@ run_borgbackup () {
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -f "/home/arne/.borg/borg.lock" ]]; then
|
||||
if [[ -f "/home/$user/.borg/borg.lock" ]]; then
|
||||
echo "Backup läuft gerade! Beende.."
|
||||
exit 0
|
||||
elif [[ -f "/home/arne/.borg/last-run-$(date +%Y-%m-%d)" ]]; then
|
||||
elif [[ -f "/home/$user/.borg/last-run-$(date +%Y-%m-%d)" ]]; then
|
||||
echo "Backup lief heute schon. Beende.."
|
||||
exit 0
|
||||
elif pgrep -x "cs2" > /dev/null; then
|
||||
@@ -100,5 +100,5 @@ fi
|
||||
# Führe Funktion aus und verhindere Ruhezustand etc.
|
||||
# https://www.freedesktop.org/software/systemd/man/latest/systemd-inhibit.html
|
||||
if systemd-inhibit bash -c "$(declare -f run_borgbackup); run_borgbackup"; then
|
||||
sh /home/arne/.scripts/gotify.sh "Borg Backup Desktop" "Backup erfolgreich fertig gestellt.."
|
||||
sh /home/$user/.scripts/gotify.sh "Borg Backup Desktop" "Backup erfolgreich fertig gestellt.."
|
||||
fi
|
||||
Reference in New Issue
Block a user