diff options
Diffstat (limited to 'arch-system/borgbackup')
-rwxr-xr-x | arch-system/borgbackup | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/arch-system/borgbackup b/arch-system/borgbackup index e16eec3..c813fcc 100755 --- a/arch-system/borgbackup +++ b/arch-system/borgbackup @@ -2,39 +2,28 @@ set -o errexit -o errtrace -BORG_HOST="12390@ch-s012.rsync.net" -export BORG_REPO="$BORG_HOST:repos/$(hostname)" -export BORG_PASSPHRASE="$(< ~/.borg_secret)" -export BORG_RSH="ssh -o IdentitiesOnly=yes -o ConnectionAttempts=20 \ - -o ServerAliveInterval=30 -i ~/.ssh/borg_key" +source /etc/borg_env.sh + +export BORG_RSH="$BORG_RSH -o ConnectionAttempts=20 -o ServerAliveInterval=30" export LC_COLLATE=C -SNAPSHOT_TARGET="/.snapshots/home-$(date "+%Y-%m-%dT%H:%M:%S")" +SNAPSHOT_TARGET="/.snapshots/$SNAPSHOT_PREFIX-$(date "+%Y-%m-%dT%H:%M:%S")" cleanup() { cd / sudo -n /usr/bin/backup-sudo cleanup } -notify_user() { - if ! [ -t 1 ]; then - notify-send "$@" - fi -} - handle_failure() { notify_user -u critical "Backup failed!" echo "Backup failed!" >&2 - cleanup exit 2 } trap cleanup EXIT trap handle_failure INT TERM ERR -cleanup - backup() { # borg's caching of 'known' files is really dumb - it takes the full # canonical path to check if it has already seen a file. This means that the @@ -47,16 +36,18 @@ backup() { fi cd /backup + + BACKUP_TARGET="$SNAPSHOT_PREFIX"-"$(date -r . "+%Y-%m-%dT%H:%M:%S")" borg create --stats $borg_progress \ - --exclude-from ~/.borg_exclude \ + --patterns-from ~/.borg_pattern \ --timestamp . \ --show-rc \ - ::"$(basename "$1")" . && rc=$? || rc=$? + ::"$BACKUP_TARGET" . && rc=$? || rc=$? if [ $rc -eq 1 ]; then # borg defines return code 1 as warning, usually permission stuff notify_user "Warning: borgbackup returned 1. Check logs" elif [ $rc -gt 1 ]; then - borg list | grep -q "$(basename "$1")" || handle_failure + borg list --short | grep -q "$BACKUP_TARGET" || false fi cleanup @@ -64,21 +55,20 @@ backup() { } if [ ! -d "$SNAPSHOT_TARGET" ]; then - sudo -n backup-sudo snapshot "$SNAPSHOT_TARGET" + sudo -n backup-sudo snapshot "$SNAPSHOT_TARGET" "$SNAPSHOT_MOUNTPOINT" fi +cleanup + $BORG_RSH "$BORG_HOST" -f -N || rc=$? if [ ${rc-0} -eq 255 ]; then notify_user "Backup: upload skipped" echo "SSH server not reachable, skipping upload" >&2 exit 0 elif [ ${rc-0} -ne 0 ]; then - handle_failure + false fi -# break locks in case the previous run was interrupted -borg break-lock - for d in /.snapshots/*/ ; do echo "Now working on: $d" backup "$d" @@ -87,6 +77,7 @@ done echo "Pruning repository." borg prune --show-rc --list \ + --keep-last 20 \ --keep-hourly 72 \ --keep-daily 7 \ --keep-weekly 4 \ |