diff options
Diffstat (limited to '.local/bin/backups/assimilate')
| -rwxr-xr-x | .local/bin/backups/assimilate | 42 |
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 | ||
| 5 | ERRMSG="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 | ||
| 10 | LOCATION="$1" | ||
| 11 | SUDO_OPTS="--preserve-env=BORG_PASSCOMMAND,PASSWORD_STORE_DIR" | ||
| 12 | CREATE_OPTS="--warning --stats --show-rc --exclude-caches --one-file-system" | ||
| 13 | LOG="$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. | ||
| 20 | export BORG_PASSCOMMAND="sudo $SUDO_OPTS -u $USER pass Borg-Backup/$(hostname)-onsite" | ||
| 21 | |||
| 22 | # Backup root partition | ||
| 23 | sudo $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 | ||
| 33 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | ||
| 34 | "/mnt/onsite-backup/$(hostname)::boot-{now:%Y-%m-%d}" /boot 2>>$LOG | ||
| 35 | |||
| 36 | # Backup home partition | ||
| 37 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | ||
| 38 | "/mnt/onsite-backup/$(hostname)::home-{now:%Y-%m-%d}" /home 2>>$LOG | ||
| 39 | |||
| 40 | # Backup var partition | ||
| 41 | sudo $SUDO_OPTS borg create $CREATE_OPTS \ | ||
| 42 | "/mnt/onsite-backup/$(hostname)::var-{now:%Y-%m-%d}" /var 2>>$LOG | ||
