From d8c7616eb067df6cf1fcfea4de36ad297fbdea06 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 25 Nov 2021 13:18:57 +0100 Subject: [PATCH] bin: add extensive borg integration --- .local/bin/scripts/barg | 6 ++++-- .local/bin/scripts/bog | 13 +++++++++++++ .zprofile | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 .local/bin/scripts/bog diff --git a/.local/bin/scripts/barg b/.local/bin/scripts/barg index 5c94eb6..1e6e7ed 100755 --- a/.local/bin/scripts/barg +++ b/.local/bin/scripts/barg @@ -1,11 +1,13 @@ #!/bin/sh # Backup root filesystem with borg case "$1" in + (-n) run="arg-test"; shift;; (-*) name="${1#-}"; shift;; (*) test $# -gt 0 || cd /;; esac -name="/mnt/backup/borg::$(test -n "$name" && echo "$name" || cat /etc/hostname)-${1:-system}-$(date -u +"%y%m%d")" +name="::$(test -n "$name" && echo "$name" || cat /etc/hostname)_${1:-system}_$(date -u +"%y%m%d")" echo "Backing up as $name" -sudo borg create --progress --stats \ +sudo --preserve-env=BORG_REPO ${run:-borg} create --progress --stats \ $(echo $DIRS_IGNORE_SAFE -x 'software-challenge/*/build' -x 'emacs/.local' | sed 's|-x \([^ ]\+\)|-e "sh:**/\1"|g') \ "$name" $(test $# -eq 0 && echo etc home root || test $# -eq 1 && echo $1) "${@:2}" +sudo chown -R $USER:$USER "$BORG_REPO" diff --git a/.local/bin/scripts/bog b/.local/bin/scripts/bog new file mode 100755 index 0000000..c8bbb8f --- /dev/null +++ b/.local/bin/scripts/bog @@ -0,0 +1,13 @@ +#!/bin/sh -e +# Simple backup with borg +test $# -eq 0 && borg list --format "{barchive:40} {time}{NL}" && exit 0 +test "$1" = "-n" && run=arg-test && shift +case "$1" in (*_) prefix=$1; shift;; esac +name="$(echo "$1" | + sed -e 's|/$||' \ + -e 's|20\([0-9]\{2\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\)|\1\2\3|' \ + -e 's|\([0-9]\{6\}\)[-_]\(.*\)|\2_\1|' \ + -e 's|\(\w\+Drive\)|cloud_\L\1|i')" +test $# -gt 1 && shift +${run:-borg} create --progress --stats "::$prefix$name" "$@" + diff --git a/.zprofile b/.zprofile index 9fc59ed..994545a 100644 --- a/.zprofile +++ b/.zprofile @@ -1,6 +1,9 @@ export DATA="$(test -d $HOME/daten && echo $HOME/daten || echo $HOME/data)" export MUSIC="$DATA/music" +export BORG_REPO="/mnt/backup/borg" +export BORG_PASSCOMMAND='pass services/borg/backup' + # xdg export XDG_DATA_HOME="$HOME/.local/share" export XDG_STATE_HOME="$HOME/.local/state"