summaryrefslogtreecommitdiff
path: root/.local/bin/backups/assimilate
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 /.local/bin/backups/assimilate
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.
Diffstat (limited to '.local/bin/backups/assimilate')
-rwxr-xr-x.local/bin/backups/assimilate42
1 files changed, 42 insertions, 0 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