summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2021-11-28 23:13:19 -0500
committerSam Chudnick <sam@chudnick.com>2021-11-28 23:13:19 -0500
commit5c9df935636c6b5610a0d1f2bf3ed8dfcd10c856 (patch)
tree8e55a2de0a3b7338ad92ffe5ae59b6012397e715
parenta337727e0577b43ae03bfc94a84f50c09a320d13 (diff)
Combined borg-onsite and borg-offsite scripts into a single script that takes an argument to specify the location. Reorganized script to use variables to reduce redundant strings. Added automated retrieval of repository password via pass. Removed --list from borg create options and redirect output to log file.
-rwxr-xr-x.local/bin/backups/assimilate42
-rwxr-xr-x.local/bin/backups/borg-offsite25
-rwxr-xr-x.local/bin/backups/borg-onsite25
3 files changed, 42 insertions, 50 deletions
diff --git a/.local/bin/backups/assimilate b/.local/bin/backups/assimilate
new file mode 100755
index 0000000..0137650
--- /dev/null
+++ b/.local/bin/backups/assimilate
@@ -0,0 +1,42 @@
1#!/bin/sh
2# Full system backup with sudo 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)-onsite"
21
22# Backup root partition
23sudo $SUDO_OPTS borg create $CREATE_OPTS \
24 --exclude '/dev/*' \
25 --exclude '/proc/*' \
26 --exclude '/sys/*' \
27 --exclude '/tmp/*' \
28 --exclude '/mnt/*' \
29 --exclude '/media/*' \
30 "/mnt/onsite-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG
31
32# Backup boot parition
33sudo $SUDO_OPTS borg create $CREATE_OPTS \
34 "/mnt/onsite-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG
35
36# Backup home partition
37sudo $SUDO_OPTS borg create $CREATE_OPTS \
38 "/mnt/onsite-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG
39
40# Backup var partition
41sudo $SUDO_OPTS borg create $CREATE_OPTS \
42 "/mnt/onsite-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG
diff --git a/.local/bin/backups/borg-offsite b/.local/bin/backups/borg-offsite
deleted file mode 100755
index dfc9c01..0000000
--- a/.local/bin/backups/borg-offsite
+++ /dev/null
@@ -1,25 +0,0 @@
1#!/bin/sh
2# Full system backup with Borg
3
4# Backup root partition
5sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
6 --exclude '/dev/*' \
7 --exclude '/proc/*' \
8 --exclude '/sys/*' \
9 --exclude '/tmp/*' \
10 --exclude '/mnt/*' \
11 --exclude '/media/*' \
12 "/mnt/offsite-backup/titan::root-{now:%Y-%m-%d}" /
13
14# Backup boot parition
15sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
16 "/mnt/offsite-backup/titan::boot-{now:%Y-%m-%d}" /boot
17
18# Backup home partition
19sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
20 "/mnt/offsite-backup/titan::home-{now:%Y-%m-%d}" /home
21
22# Backup var partition
23sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
24 "/mnt/offsite-backup/titan::var-{now:%Y-%m-%d}" /var
25
diff --git a/.local/bin/backups/borg-onsite b/.local/bin/backups/borg-onsite
deleted file mode 100755
index 658c425..0000000
--- a/.local/bin/backups/borg-onsite
+++ /dev/null
@@ -1,25 +0,0 @@
1#!/bin/sh
2# Full system backup with Borg
3
4# Backup root partition
5sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
6 --exclude '/dev/*' \
7 --exclude '/proc/*' \
8 --exclude '/sys/*' \
9 --exclude '/tmp/*' \
10 --exclude '/mnt/*' \
11 --exclude '/media/*' \
12 "/mnt/onsite-backup/titan::root-{now:%Y-%m-%d}" /
13
14# Backup boot parition
15sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
16 "/mnt/onsite-backup/titan::boot-{now:%Y-%m-%d}" /boot
17
18# Backup home partition
19sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
20 "/mnt/onsite-backup/titan::home-{now:%Y-%m-%d}" /home
21
22# Backup var partition
23sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \
24 "/mnt/onsite-backup/titan::var-{now:%Y-%m-%d}" /var
25