diff options
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/backups/assimilate | 36 |
1 files changed, 32 insertions, 4 deletions
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" | |||
19 | # by the same means. This allows custom password store locations to work with this script. | 19 | # by the same means. This allows custom password store locations to work with this script. |
20 | export BORG_PASSCOMMAND="sudo $SUDO_OPTS -u $USER pass Borg-Backup/$(hostname)-$LOCATION" | 20 | export BORG_PASSCOMMAND="sudo $SUDO_OPTS -u $USER pass Borg-Backup/$(hostname)-$LOCATION" |
21 | 21 | ||
22 | # Create variables and function to monitor exit status | ||
23 | WARNING=0 | ||
24 | ERROR=0 | ||
25 | check_rc() { | ||
26 | rc=$1 | ||
27 | [ $1 -eq 1 ] && WARNING=1 | ||
28 | [ $1 -eq 2 ] && ERROR=1 | ||
29 | } | ||
30 | |||
31 | # Start backup | ||
32 | echo -e "\n$LOCATION $(date)\n" >> $LOG | ||
33 | notify-send "beginning $LOCATION backup" | ||
34 | |||
22 | # Backup root partition | 35 | # Backup root partition |
23 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | 36 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ |
24 | --exclude '/dev/*' \ | 37 | --exclude '/dev/*' \ |
@@ -27,16 +40,31 @@ sudo $SUDO_OPTS borg create $CREATE_OPTS \ | |||
27 | --exclude '/tmp/*' \ | 40 | --exclude '/tmp/*' \ |
28 | --exclude '/mnt/*' \ | 41 | --exclude '/mnt/*' \ |
29 | --exclude '/media/*' \ | 42 | --exclude '/media/*' \ |
30 | "/mnt/onsite-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG | 43 | "/mnt/$LOCATION-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG |
44 | check_rc $? | ||
31 | 45 | ||
32 | # Backup boot parition | 46 | # Backup boot parition |
33 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | 47 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ |
34 | "/mnt/onsite-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG | 48 | "/mnt/$LOCATION-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG |
49 | check_rc $? | ||
35 | 50 | ||
36 | # Backup home partition | 51 | # Backup home partition |
37 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | 52 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ |
38 | "/mnt/onsite-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG | 53 | "/mnt/$LOCATION-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG |
54 | check_rc $? | ||
39 | 55 | ||
40 | # Backup var partition | 56 | # Backup var partition |
41 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | 57 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ |
42 | "/mnt/onsite-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG | 58 | "/mnt/$LOCATION-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG |
59 | check_rc $? | ||
60 | |||
61 | # Send notifications based on return codes of archives | ||
62 | |||
63 | [ $WARNING -eq 1 ] && notify-send "One or more archives produced a warning" \ | ||
64 | "Please check the log at $LOG" | ||
65 | |||
66 | [ $ERROR -eq 1 ] && notify-send -u critical \ | ||
67 | "One or more archives produced an error and was unable to complete" \ | ||
68 | "Please check the log at $LOG" | ||
69 | |||
70 | [ $WARNING -eq 0 -a $ERROR -eq 0 ] && notify-send "$LOCATION backup complete" | ||