2020-08-18 11:57:53 +02:00
#!/bin/bash
2021-03-07 19:40:32 +01:00
{ { file_header | default ( ) } }
2021-01-05 17:41:18 +01:00
2022-02-09 10:06:37 +01:00
# source functions
if [ [ -f "/usr/local/bin/functions.sh" ] ] ; then
source /usr/local/bin/functions.sh
else
echo "[ERROR] Could not find: /usr/local/bin/functions.sh"
exit 3
fi
# set lock
## call function
## lock gets set and released if the script terminates
set_lock
2021-01-05 17:41:18 +01:00
abbruch_restic = 0 # set counter for error
2022-02-09 10:06:37 +01:00
sudo mount -t cifs -o credentials = "/etc/restic/smb_password.txt" ,vers= 3.0,uid= $UID { { restic_repository } } { { restic_mount } } # mount share
2021-01-05 17:41:18 +01:00
mount_return_value = $? # schreib Exit Code in Variable
if ( [ " $mount_return_value " -ne 0 ] ) ; then
{
echo "--------------------------------------------------" # Trenner logfile
2021-01-10 16:10:24 +01:00
echo $( date +%d.%m.%Y-%T) # Datum für logfile
2021-01-05 17:41:18 +01:00
echo "mount error"
} >> /var/log/restic.log 2>& 1;
tail --lines= 5 "/var/log/restic.log" | mail -s " Backup-Error - restic - $HOSTNAME " { { empfaenger_mail } }
exit 1
else
{
echo "--------------------------------------------------" # Trenner logfile
2021-01-10 16:10:24 +01:00
echo $( date +%d.%m.%Y-%T) # Datum für logfile
2021-01-05 17:41:18 +01:00
echo "mount successful"
} >> /var/log/restic.log 2>& 1;
2020-12-18 22:07:03 +01:00
fi
2021-01-05 17:41:18 +01:00
2021-02-23 12:35:07 +01:00
while [ [ " $abbruch_restic " -le { { restic_anzahl_versuche_backup } } ] ] # Schleife für Abbruchbedingung; um die eckigen Klammern(Befehl "test") muss immer ein leerzeichen sein
2021-01-05 17:41:18 +01:00
do
{ # ist keine Subshell sondern Grouping; https://askubuntu.com/questions/662190/write-the-output-of-multiple-sequential-commands-to-a-text-file
echo "--------------------------------------------------" # Trenner logfile
2021-01-10 16:10:24 +01:00
echo $( date +%d.%m.%Y-%T) # Datum für logfile
2021-01-05 17:58:59 +01:00
restic -r { { restic_mount } } --password-file /etc/restic/password.txt backup --exclude-file /etc/restic/exclude.txt { { restic_folders_to_backup } } # execute Backup
2021-01-05 17:41:18 +01:00
restic_return_value = $? # schreib Exit Code in Variable
if ( [ [ " $restic_return_value " -eq 0 ] ] ) ; # Prüfung ob restic erfolgreich war(setze Abbruchbedingung), wenn nicht warte 1min und zähle die Abbruchbedingung hoch
then
abbruch_restic = 99
else
sleep { { restic_wartezeit } }
abbruch_restic = $(( " $abbruch_restic " + 1 ))
fi
2021-03-13 13:47:01 +01:00
echo $( date +%d.%m.%Y-%T) # Datum für logfile
2021-01-05 17:41:18 +01:00
} >> /var/log/restic.log 2>& 1; # leite die komplette Ausgabe in logfile um
done
2022-02-09 10:06:37 +01:00
sudo umount { { restic_mount } } >> /var/log/restic.log 2>& 1; # unmount
2021-01-05 17:41:18 +01:00
if ( [ [ " $restic_return_value " -ne 0 ] ] ) ; then # sende eMail wenn Restic Fehler ungleich 0, also Fehler; #https://stackoverflow.com/a/45817972
tail --lines= 50 "/var/log/restic.log" | mail -s " Backup-Error - restic - $HOSTNAME " { { empfaenger_mail } } # schreibe die letzten 50 Zeilen aus dem Logfile in den Body der Mail
fi