summaryrefslogtreecommitdiff
path: root/.local/bin/backups/assimilate
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/backups/assimilate')
-rwxr-xr-x.local/bin/backups/assimilate60
1 files changed, 0 insertions, 60 deletions
diff --git a/.local/bin/backups/assimilate b/.local/bin/backups/assimilate
deleted file mode 100755
index fd6ed7f..0000000
--- a/.local/bin/backups/assimilate
+++ /dev/null
@@ -1,60 +0,0 @@
1#!/bin/sh
2# Full system backup with borg
3
4# Validate argument - should either be onsite or offsite to specify location
5ERRMSG="error: please specify either onsite or offsite"
6[ $# -ne 1 ] && echo $ERRMSG && exit 1
7[ "$1" != "onsite" -a "$1" != "offsite" ] && echo $ERRMSG && exit 1
8
9# Set variables
10LOCATION="$1"
11SUDO_OPTS="--preserve-env=BORG_PASSCOMMAND,PASSWORD_STORE_DIR"
12CREATE_OPTS="--warning --stats --show-rc --exclude-caches --one-file-system"
13LOG="$HOME/.config/borg/log"
14
15# Hack to get repository passphrase from pass
16# The passcommand will be invoked as root, so use sudo to run it as the user calling the script
17# who owns the password store. The environmental variable PASSWORD_STORE_DIR is passed through
18# SUDO_OPTS to the borg commands, and then passed to this command from the borg command
19# by the same means. This allows custom password store locations to work with this script.
20export BORG_PASSCOMMAND="sudo $SUDO_OPTS -u $USER pass Borg-Backup/$(hostname)-$LOCATION"
21
22# Create variables and function to monitor exit status
23WARNING=0
24ERROR=0
25check_rc() {
26 rc=$1
27 [ $1 -eq 1 ] && WARNING=1
28 [ $1 -eq 2 ] && ERROR=1
29}
30
31# Start backup
32echo -e "\n$LOCATION $(date)\n" >> $LOG
33notify-send "beginning $LOCATION backup"
34
35# Backup root partition
36sudo $SUDO_OPTS borg create $CREATE_OPTS \
37 --exclude '/dev/*' \
38 --exclude '/proc/*' \
39 --exclude '/sys/*' \
40 --exclude '/tmp/*' \
41 --exclude '/mnt/*' \
42 --exclude '/media/*' \
43 "/mnt/$LOCATION-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG
44check_rc $?
45
46# Backup boot parition
47sudo $SUDO_OPTS borg create $CREATE_OPTS \
48 "/mnt/$LOCATION-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG
49check_rc $?
50
51# Send notifications based on return codes of archives
52
53[ $WARNING -eq 1 ] && notify-send "One or more archives produced a warning" \
54 "Please check the log at $LOG"
55
56[ $ERROR -eq 1 ] && notify-send -u critical \
57 "One or more archives produced an error and was unable to complete" \
58 "Please check the log at $LOG"
59
60[ $WARNING -eq 0 -a $ERROR -eq 0 ] && notify-send "$LOCATION backup complete"