From 5c9df935636c6b5610a0d1f2bf3ed8dfcd10c856 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 28 Nov 2021 23:13:19 -0500 Subject: 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. --- .local/bin/backups/assimilate | 42 +++++++++++++++++++++++++++++++++++++++++ .local/bin/backups/borg-offsite | 25 ------------------------ .local/bin/backups/borg-onsite | 25 ------------------------ 3 files changed, 42 insertions(+), 50 deletions(-) create mode 100755 .local/bin/backups/assimilate delete mode 100755 .local/bin/backups/borg-offsite delete mode 100755 .local/bin/backups/borg-onsite 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 @@ +#!/bin/sh +# Full system backup with sudo borg + +# Validate argument - should either be onsite or offsite to specify location +ERRMSG="error: please specify either onsite or offsite" +[ $# -ne 1 ] && echo $ERRMSG && exit 1 +[ "$1" != "onsite" -a "$1" != "offsite" ] && echo $ERRMSG && exit 1 + +# Set variables +LOCATION="$1" +SUDO_OPTS="--preserve-env=BORG_PASSCOMMAND,PASSWORD_STORE_DIR" +CREATE_OPTS="--warning --stats --show-rc --exclude-caches --one-file-system" +LOG="$HOME/.config/borg/log" + +# Hack to get repository passphrase from pass +# The passcommand will be invoked as root, so use sudo to run it as the user calling the script +# who owns the password store. The environmental variable PASSWORD_STORE_DIR is passed through +# SUDO_OPTS to the borg commands, and then passed to this command from the borg command +# 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)-onsite" + +# Backup root partition +sudo $SUDO_OPTS borg create $CREATE_OPTS \ + --exclude '/dev/*' \ + --exclude '/proc/*' \ + --exclude '/sys/*' \ + --exclude '/tmp/*' \ + --exclude '/mnt/*' \ + --exclude '/media/*' \ + "/mnt/onsite-backup/$(hostname)::root-{now:%Y-%m-%d}" / 2>>$LOG + +# Backup boot parition +sudo $SUDO_OPTS borg create $CREATE_OPTS \ + "/mnt/onsite-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG + +# Backup home partition +sudo $SUDO_OPTS borg create $CREATE_OPTS \ + "/mnt/onsite-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG + +# Backup var partition +sudo $SUDO_OPTS borg create $CREATE_OPTS \ + "/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 @@ -#!/bin/sh -# Full system backup with Borg - -# Backup root partition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - --exclude '/dev/*' \ - --exclude '/proc/*' \ - --exclude '/sys/*' \ - --exclude '/tmp/*' \ - --exclude '/mnt/*' \ - --exclude '/media/*' \ - "/mnt/offsite-backup/titan::root-{now:%Y-%m-%d}" / - -# Backup boot parition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - "/mnt/offsite-backup/titan::boot-{now:%Y-%m-%d}" /boot - -# Backup home partition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - "/mnt/offsite-backup/titan::home-{now:%Y-%m-%d}" /home - -# Backup var partition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - "/mnt/offsite-backup/titan::var-{now:%Y-%m-%d}" /var - 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 @@ -#!/bin/sh -# Full system backup with Borg - -# Backup root partition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - --exclude '/dev/*' \ - --exclude '/proc/*' \ - --exclude '/sys/*' \ - --exclude '/tmp/*' \ - --exclude '/mnt/*' \ - --exclude '/media/*' \ - "/mnt/onsite-backup/titan::root-{now:%Y-%m-%d}" / - -# Backup boot parition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - "/mnt/onsite-backup/titan::boot-{now:%Y-%m-%d}" /boot - -# Backup home partition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - "/mnt/onsite-backup/titan::home-{now:%Y-%m-%d}" /home - -# Backup var partition -sudo borg create --verbose --list --stats --show-rc --exclude-caches --one-file-system \ - "/mnt/onsite-backup/titan::var-{now:%Y-%m-%d}" /var - -- cgit v1.2.3