From: Sven Hoexter Date: Fri, 7 May 2021 07:12:29 +0000 (+0200) Subject: move historic hetzner backup scripts X-Git-Url: https://git.sven.stormbind.net/?a=commitdiff_plain;h=2cf03307fed0f8e3bb9adde634361751be051bc7;p=sven%2Fscripts.git move historic hetzner backup scripts --- diff --git a/hetzner/hetznerbackup.sh b/hetzner/hetznerbackup.sh deleted file mode 100755 index e7bae64..0000000 --- a/hetzner/hetznerbackup.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -### Halt on errors -set -e - -### Debug -#set -x - -### General settings -export PASSPHRASE=s -export FTP_PASSWORD=s -FTP_USER=u -FTP_HOST=h -LOCKFILE="/var/lock/backup/hetznerbackup" - -## Backup job for the dom0 main -job_main() { - echo "Backing up main/etc" - duplicity $BMODE /etc ftp://$FTP_USER@$FTP_HOST/main/etc - duplicity remove-all-but-n-full 5 --force ftp://$FTP_USER@$FTP_HOST/main/etc -} - -### Backup job for the domU void -job_void() { - ### mount all domU partitions - mount -o ro /dev/vg0/void-root /mnt/backup/void-root - mount -o ro /dev/vg0/void-home /mnt/backup/void-home - mount -o ro /dev/vg0/void-var /mnt/backup/void-var - - if [ -e /mnt/backup/void-var/lib/automysqlbackup/backupdone ]; then - MYSQLOK="--include /mnt/backup/void-var/lib/automysqlbackup/backupdone" - else - echo "WARNING: It seems that the last mysql backup in the domU void is still runing" - echo "Skipping mysql backup - please re-schedule" - fi - - echo "Backing up void" - duplicity $BMODE \ - --exclude /mnt/backup/void-home/tcm \ - --include /mnt/backup/void-root/etc \ - --include /mnt/backup/void-home \ - $MYSQLOK \ - --exclude /mnt/backup \ - /mnt/backup ftp://$FTP_USER@$FTP_HOST/void/ - duplicity remove-all-but-n-full 5 --force ftp://$FTP_USER@$FTP_HOST/void/ - - - ### umount all domU partitions - umount /mnt/backup/void-root /mnt/backup/void-home /mnt/backup/void-var -} - -### check for other runing instances of this script -if [ -e $LOCKFILE ]; then - echo "Lockfile $LOCKFILE found - aborting" - echo "This is a typical result of a failed backup run, please contact your admin" - exit 5 -else - touch $LOCKFILE -fi - -### Set the duplicity backup mode we would like to use -if [[ $(LANG=C; date +%A) =~ Sunday ]]; then - echo "Runing in full mode" - BMODE="full" -else - echo "Runing in incr mode" - BMODE="incr" -fi - -### Start the backup jobs -job_main -job_void - -### remove the lockfile -rm $LOCKFILE diff --git a/hetzner/hetznerbackupv2.sh b/hetzner/hetznerbackupv2.sh deleted file mode 100755 index 8361077..0000000 --- a/hetzner/hetznerbackupv2.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/bash - -### Do not inherit the following variables -# Safety net just in case some calls this -# script in a bogus way. -unset $dry - -### Debug -#set -x -#set dry="--dry-run" - -### General settings -export PASSPHRASE=s -export FTP_PASSWORD=s -FTP_USER=uxxx -FTP_HOST=uxxx.your-backup.de -PROTO=ssh -GOPTS="--num-retries 15" -ROOTMAIL="root@localhost" -LOCKDIR="/var/lock/backup" -LOCKFILE="$LOCKDIR/hetznerbackup" -LOGFILE="/var/log/hetznerbackup.log" -SESSIONLOG=$(mktemp /var/tmp/hetznerbackup.XXXXXXXXX) -ERRSTAT=0 - -## Backup job for main -job_main() { - echo "" >> $SESSIONLOG - echo "Backing up main `date`" >> $SESSIONLOG - echo "" >> $SESSIONLOG - - echo "Going for /etc" >> $SESSIONLOG - duplicity $BMODE $dry $GOPTS /etc $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1 - - echo "Going for /home" >> $SESSIONLOG - duplicity $BMODE $dry $GOPTS /home $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1 - - echo "Going for /var/www" >> $SESSIONLOG - duplicity $BMODE $dry $GOPTS /var/www $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1 - - echo "Going for /var/lib/tomcat6" >> $SESSIONLOG - duplicity $BMODE $dry $GOPTS /var/lib/tomcat6 $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1 - - echo "Going for /var/lib/automysqlbackup" >> $SESSIONLOG - if [ -e /var/lib/automysqlbackup/backupdone ]; then - duplicity $BMODE $dry $GOPTS /var/lib/automysqlbackup $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1 - duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1 - else - echo "WARNING: It seems that the last mysql backup is still runing" >> $SESSIONLOG - echo "Skipping mysql backup - please re-schedule" >> $SESSIONLOG - ERSSTAT=10 - fi - - echo "" >> $SESSIONLOG -} - -# Append the session log to the main logfile and remove log and lock -cleanup() { - ENDDATE=$(date) - if [ $ERRSTAT -eq 0 ]; then - echo "Backup finished successfully $ENDDATE" >> $SESSIONLOG - else - echo "ERROR Backup FAILED $ENDDATE with ERRSTAT $ERRSTAT" >> $SESSIONLOG - cat $SESSIONLOG|mail -s "ERROR Backup FAILED $ENDDATE with ERRSTAT $ERRSTAT" $ROOTMAIL - fi - cat $SESSIONLOG >> $LOGFILE - rm $SESSIONLOG $LOCKFILE -} - -### check for other runing instances of this script -if [ -e $LOCKFILE ]; then - echo "Lockfile $LOCKFILE found - aborting" - echo "This is a typical result of a failed backup run, please contact your admin" - exit 5 -else - if [ ! -d $LOCKDIR ]; then - mkdir -m 700 $LOCKDIR - fi - touch $LOCKFILE -fi - -### Set the duplicity backup mode we would like to use -if [[ $(LANG=C; date +%A) =~ Sunday ]]; then - echo "Runing in full mode" >> $SESSIONLOG - BMODE="full" -else - echo "Runing in incr mode" >> $SESSIONLOG - BMODE="incr" -fi - -### Start the backup jobs -job_main -### Cleanup and reporting -cleanup -exit $ERRSTAT diff --git a/stormbind/hetznerbackup.sh b/stormbind/hetznerbackup.sh new file mode 100755 index 0000000..e7bae64 --- /dev/null +++ b/stormbind/hetznerbackup.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +### Halt on errors +set -e + +### Debug +#set -x + +### General settings +export PASSPHRASE=s +export FTP_PASSWORD=s +FTP_USER=u +FTP_HOST=h +LOCKFILE="/var/lock/backup/hetznerbackup" + +## Backup job for the dom0 main +job_main() { + echo "Backing up main/etc" + duplicity $BMODE /etc ftp://$FTP_USER@$FTP_HOST/main/etc + duplicity remove-all-but-n-full 5 --force ftp://$FTP_USER@$FTP_HOST/main/etc +} + +### Backup job for the domU void +job_void() { + ### mount all domU partitions + mount -o ro /dev/vg0/void-root /mnt/backup/void-root + mount -o ro /dev/vg0/void-home /mnt/backup/void-home + mount -o ro /dev/vg0/void-var /mnt/backup/void-var + + if [ -e /mnt/backup/void-var/lib/automysqlbackup/backupdone ]; then + MYSQLOK="--include /mnt/backup/void-var/lib/automysqlbackup/backupdone" + else + echo "WARNING: It seems that the last mysql backup in the domU void is still runing" + echo "Skipping mysql backup - please re-schedule" + fi + + echo "Backing up void" + duplicity $BMODE \ + --exclude /mnt/backup/void-home/tcm \ + --include /mnt/backup/void-root/etc \ + --include /mnt/backup/void-home \ + $MYSQLOK \ + --exclude /mnt/backup \ + /mnt/backup ftp://$FTP_USER@$FTP_HOST/void/ + duplicity remove-all-but-n-full 5 --force ftp://$FTP_USER@$FTP_HOST/void/ + + + ### umount all domU partitions + umount /mnt/backup/void-root /mnt/backup/void-home /mnt/backup/void-var +} + +### check for other runing instances of this script +if [ -e $LOCKFILE ]; then + echo "Lockfile $LOCKFILE found - aborting" + echo "This is a typical result of a failed backup run, please contact your admin" + exit 5 +else + touch $LOCKFILE +fi + +### Set the duplicity backup mode we would like to use +if [[ $(LANG=C; date +%A) =~ Sunday ]]; then + echo "Runing in full mode" + BMODE="full" +else + echo "Runing in incr mode" + BMODE="incr" +fi + +### Start the backup jobs +job_main +job_void + +### remove the lockfile +rm $LOCKFILE diff --git a/stormbind/hetznerbackupv2.sh b/stormbind/hetznerbackupv2.sh new file mode 100755 index 0000000..8361077 --- /dev/null +++ b/stormbind/hetznerbackupv2.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +### Do not inherit the following variables +# Safety net just in case some calls this +# script in a bogus way. +unset $dry + +### Debug +#set -x +#set dry="--dry-run" + +### General settings +export PASSPHRASE=s +export FTP_PASSWORD=s +FTP_USER=uxxx +FTP_HOST=uxxx.your-backup.de +PROTO=ssh +GOPTS="--num-retries 15" +ROOTMAIL="root@localhost" +LOCKDIR="/var/lock/backup" +LOCKFILE="$LOCKDIR/hetznerbackup" +LOGFILE="/var/log/hetznerbackup.log" +SESSIONLOG=$(mktemp /var/tmp/hetznerbackup.XXXXXXXXX) +ERRSTAT=0 + +## Backup job for main +job_main() { + echo "" >> $SESSIONLOG + echo "Backing up main `date`" >> $SESSIONLOG + echo "" >> $SESSIONLOG + + echo "Going for /etc" >> $SESSIONLOG + duplicity $BMODE $dry $GOPTS /etc $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/etc >> $SESSIONLOG 2>&1 || ERRSTAT=1 + + echo "Going for /home" >> $SESSIONLOG + duplicity $BMODE $dry $GOPTS /home $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/home >> $SESSIONLOG 2>&1 || ERRSTAT=1 + + echo "Going for /var/www" >> $SESSIONLOG + duplicity $BMODE $dry $GOPTS /var/www $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/var/www >> $SESSIONLOG 2>&1 || ERRSTAT=1 + + echo "Going for /var/lib/tomcat6" >> $SESSIONLOG + duplicity $BMODE $dry $GOPTS /var/lib/tomcat6 $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/tomcat6 >> $SESSIONLOG 2>&1 || ERRSTAT=1 + + echo "Going for /var/lib/automysqlbackup" >> $SESSIONLOG + if [ -e /var/lib/automysqlbackup/backupdone ]; then + duplicity $BMODE $dry $GOPTS /var/lib/automysqlbackup $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity remove-all-but-n-full 5 --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1 + duplicity cleanup --extra-clean --force $dry $GOPTS $PROTO://$FTP_USER@$FTP_HOST/main/automysqlbackup >> $SESSIONLOG 2>&1 || ERRSTAT=1 + else + echo "WARNING: It seems that the last mysql backup is still runing" >> $SESSIONLOG + echo "Skipping mysql backup - please re-schedule" >> $SESSIONLOG + ERSSTAT=10 + fi + + echo "" >> $SESSIONLOG +} + +# Append the session log to the main logfile and remove log and lock +cleanup() { + ENDDATE=$(date) + if [ $ERRSTAT -eq 0 ]; then + echo "Backup finished successfully $ENDDATE" >> $SESSIONLOG + else + echo "ERROR Backup FAILED $ENDDATE with ERRSTAT $ERRSTAT" >> $SESSIONLOG + cat $SESSIONLOG|mail -s "ERROR Backup FAILED $ENDDATE with ERRSTAT $ERRSTAT" $ROOTMAIL + fi + cat $SESSIONLOG >> $LOGFILE + rm $SESSIONLOG $LOCKFILE +} + +### check for other runing instances of this script +if [ -e $LOCKFILE ]; then + echo "Lockfile $LOCKFILE found - aborting" + echo "This is a typical result of a failed backup run, please contact your admin" + exit 5 +else + if [ ! -d $LOCKDIR ]; then + mkdir -m 700 $LOCKDIR + fi + touch $LOCKFILE +fi + +### Set the duplicity backup mode we would like to use +if [[ $(LANG=C; date +%A) =~ Sunday ]]; then + echo "Runing in full mode" >> $SESSIONLOG + BMODE="full" +else + echo "Runing in incr mode" >> $SESSIONLOG + BMODE="incr" +fi + +### Start the backup jobs +job_main +### Cleanup and reporting +cleanup +exit $ERRSTAT