Update backup.sh

This commit is contained in:
Foxly IT Blog 2021-09-02 14:53:19 +02:00 committed by GitHub
parent f376d0cc66
commit 0cca6c3990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,12 +35,10 @@ then
exit 1 exit 1
fi fi
# Nextcloud Maintenance aktivieren # Nextcloud Maintenance
echo "\n###### Aktiviere Wartungsmodus: ${currentDateReadable} ######\n" echo "\n###### Aktiviere Wartungsmodus: ${currentDateReadable} ######\n"
sudo -u $user php$phpversion $clpLocation$domain/occ maintenance:mode --on sudo -u $user php$phpversion $clpLocation$domain/occ maintenance:mode --on
# Hier koennen auch explezite Datenbanken angegeben werden
echo "\n###### Datenbank Backups ######\n" echo "\n###### Datenbank Backups ######\n"
clpctl db:backup --databases=$databases clpctl db:backup --databases=$databases
echo "\n###### Datenbank Backups erstellt! ######\n" echo "\n###### Datenbank Backups erstellt! ######\n"
@ -48,7 +46,6 @@ echo "\n###### Datenbank Backups erstellt! ######\n"
export BORG_REPO=$backupRepo export BORG_REPO=$backupRepo
# Euer Passwort muss hier hinterlegt werden.
export BORG_PASSPHRASE=$backupPassword export BORG_PASSPHRASE=$backupPassword
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
@ -56,7 +53,9 @@ trap 'echo $( date ) Backup unterbrochen >&2; exit 2' INT TERM
info "Start backup" info "Start backup"
# Hier wird das Backup erstellt, passt das so an wie Ihr das gerne haben möchtet
# Here the backup is created, adjust this as you would like to have it
borg create \ borg create \
--stats \ --stats \
--compression lz4 \ --compression lz4 \
@ -66,7 +65,7 @@ borg create \
backup_exit=$? backup_exit=$?
# Nextcloud Maintenance deaktivieren # Nextcloud Maintenance
echo "\n###### Deaktiviere Wartungsmodus ######\n" echo "\n###### Deaktiviere Wartungsmodus ######\n"
sudo -u $user php$phpversion $clpLocation$domain/occ maintenance:mode --off sudo -u $user php$phpversion $clpLocation$domain/occ maintenance:mode --off
@ -75,7 +74,7 @@ echo "Storage space usage of the backups:\n"
df -h ${backupRepo} df -h ${backupRepo}
info "Loeschen von alten Backups" info "Loeschen von alten Backups"
# Automatisches löschen von alten Backups # Automatically delete old backups
borg prune \ borg prune \
--prefix '{hostname}-' \ --prefix '{hostname}-' \
--keep-daily 7 \ --keep-daily 7 \
@ -84,7 +83,7 @@ borg prune \
prune_exit=$? prune_exit=$?
# Informationen ob das Backup geklappt hat. # Information whether the backup worked.
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
if [ ${global_exit} -eq 0 ]; then if [ ${global_exit} -eq 0 ]; then