From be06067cd71678e65dafc03ad2ee4710d19458f9 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Tue, 7 Dec 2021 20:13:22 -0500 Subject: Fixed issue caused by static path to archive location by replacing onsite with location variable. Added monitoring of return codes from archives for warnings and errors. Added notifications on start and finish. Notify user with different messages based on return codes. --- .local/bin/backups/assimilate | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to '.local/bin/backups/assimilate') diff --git a/.local/bin/backups/assimilate b/.local/bin/backups/assimilate index ba31baa..dea18d3 100755 --- a/.local/bin/backups/assimilate +++ b/.local/bin/backups/assimilate @@ -19,6 +19,19 @@ LOG="$HOME/.config/borg/log" # by the same means. This allows custom password store locations to work with this script. export BORG_PASSCOMMAND="sudo $SUDO_OPTS -u $USER pass Borg-Backup/$(hostname)-$LOCATION" +# Create variables and function to monitor exit status +WARNING=0 +ERROR=0 +check_rc() { + rc=$1 + [ $1 -eq 1 ] && WARNING=1 + [ $1 -eq 2 ] && ERROR=1 +} + +# Start backup +echo -e "\n$LOCATION $(date)\n" >> $LOG +notify-send "beginning $LOCATION backup" + # Backup root partition sudo $SUDO_OPTS borg create $CREATE_OPTS \ --exclude '/dev/*' \ @@ -27,16 +40,31 @@ sudo $SUDO_OPTS borg create $CREATE_OPTS \ --exclude '/tmp/*' \ --exclude '/mnt/*' \ --exclude '/media/*' \ - "/mnt/onsite-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG + "/mnt/$LOCATION-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG +check_rc $? # Backup boot parition sudo $SUDO_OPTS borg create $CREATE_OPTS \ - "/mnt/onsite-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG + "/mnt/$LOCATION-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG +check_rc $? # Backup home partition sudo $SUDO_OPTS borg create $CREATE_OPTS \ - "/mnt/onsite-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG + "/mnt/$LOCATION-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG +check_rc $? # Backup var partition sudo $SUDO_OPTS borg create $CREATE_OPTS \ - "/mnt/onsite-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG + "/mnt/$LOCATION-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG +check_rc $? + +# Send notifications based on return codes of archives + +[ $WARNING -eq 1 ] && notify-send "One or more archives produced a warning" \ + "Please check the log at $LOG" + +[ $ERROR -eq 1 ] && notify-send -u critical \ + "One or more archives produced an error and was unable to complete" \ + "Please check the log at $LOG" + +[ $WARNING -eq 0 -a $ERROR -eq 0 ] && notify-send "$LOCATION backup complete" -- cgit v1.2.3