From 622ceaa922015ab473e81a64fcbedbb1fe6e6535 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Tue, 24 Mar 2020 09:35:00 -0600 Subject: [PATCH] goodie --- .gitignore | 0 2do | 0 config/rclone | 0 config/restic | 0 go/pkg/linux_amd64/github.com/restic/restic.a | Bin sync.sh | 39 +++++++++++------- testdata-old/b | 0 testdata-old/c | 0 testdata-old/d | 0 testdata/b | 0 testdata/c | 0 11 files changed, 24 insertions(+), 15 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 2do mode change 100644 => 100755 config/rclone mode change 100644 => 100755 config/restic mode change 100644 => 100755 go/pkg/linux_amd64/github.com/restic/restic.a mode change 100644 => 100755 sync.sh mode change 100644 => 100755 testdata-old/b mode change 100644 => 100755 testdata-old/c mode change 100644 => 100755 testdata-old/d mode change 100644 => 100755 testdata/b mode change 100644 => 100755 testdata/c diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/2do b/2do old mode 100644 new mode 100755 diff --git a/config/rclone b/config/rclone old mode 100644 new mode 100755 diff --git a/config/restic b/config/restic old mode 100644 new mode 100755 diff --git a/go/pkg/linux_amd64/github.com/restic/restic.a b/go/pkg/linux_amd64/github.com/restic/restic.a old mode 100644 new mode 100755 diff --git a/sync.sh b/sync.sh old mode 100644 new mode 100755 index fa3ab34..89e892d --- a/sync.sh +++ b/sync.sh @@ -5,7 +5,7 @@ function main() { set -u cd "$(dirname "${BASH_SOURCE[0]}")" - export GOPATH="$PWD/go" + export GOPATH="$PWD/restic-go" if [ -z "${PASSWORD:-""}" ]; then read -sp "Password: " PASSWORD @@ -19,10 +19,9 @@ function main() { local action="$1" shift case "$action" in - clean ) clean_remote --prune "$@" ;; + clean ) clean_remote "$@" ;; backup ) backup "$@" ;; restore ) restore "$@" ;; - forget ) fatal "Refusing custom forget" ;; * ) RESTIC "$action" "$@" ;; esac } @@ -34,7 +33,7 @@ function install() { if [ -e "$GOPATH/bin/$(uname)/$b" ]; then continue fi - go get -u "github.com/$i" + go get -u "github.com/$i" || true pushd "$GOPATH/src/github.com/$i" case "$i" in restic* ) @@ -55,7 +54,7 @@ function configure() { if [ ! -e "$PWD/config/rclone" ]; then configure_rclone fi - if ! RESTIC snapshots; then + if [ ! -e "$PWD/config/restic" ]; then configure_restic fi } @@ -76,18 +75,25 @@ function configure_restic() { } function backup() { + local args=() for arg in "$@"; do local real="$(realpath "$arg")" - if [ "$real" == "${real#$HOME/}" ]; then + if [ "$real" == "${real#$HOME}" ]; then log "Cowardly skipping $arg ($real) for not being under \$HOME ($HOME)" continue fi - log "BACKUP $real" - RESTIC backup \ - -e "**.sw*" \ - --tag "${real#$HOME/}" \ - "$real" + args+=("$real") done + local extraTags=" " + if [ -n "${TAGS:-""}" ]; then + extraTags="--tag $TAGS" + fi + log "BACKUP ${args[@]}" + RESTIC backup \ + -e "**.sw*" \ + --tag "${real#$HOME/}" \ + $extraTags \ + "${args[@]}" } function restore() { @@ -95,7 +101,7 @@ function restore() { if [ -e "$arg" ] || [ -d "$arg" ]; then arg="$(realpath "$arg")" fi - local latest="$(RESTIC snapshots --last | sort -k 2 | grep '20[0-9][0-9].[0-9][0-9].[0-9][0-9]' | tail -n 1)" + local latest="$(RESTIC snapshots --last --tag "${arg#$HOME/}" | sort -k 2 | grep '20[0-9][0-9].[0-9][0-9].[0-9][0-9]' | tail -n 1)" local id="$(echo "$latest" | awk '{print $1}')" local path="$(echo "$latest" | awk '{print $5}')" local rpath="$(echo "$latest" | awk '{print $6}')" @@ -110,11 +116,11 @@ function restore() { fi mv "$HOME/$path-restore" "$HOME/$path" done - clean_remote --prune + clean_remote } function clean_remote() { - RESTIC forget --keep-last 2 --group-by host,tags "$@" + RESTIC forget --prune --cleanup-cache --keep-last 2 --group-by host,tags "$@" RESTIC check } @@ -127,7 +133,7 @@ function RESTIC() { $GOPATH/bin/$(uname)/restic \ -r rclone:remote:cloudly/restic-plain/backup \ -o rclone.program=$GOPATH/bin/$(uname)/rclone \ - -o rclone.args="serve restic --stdio --b2-hard-delete --drive-use-trash=false --config $PWD/config/rclone --bwlimit 6M --ask-password=false" \ + -o rclone.args="serve restic --stdio --b2-hard-delete --drive-use-trash=false --config $PWD/config/rclone --bwlimit 26M --ask-password=false" \ "$@" #-r rclone:remote-enc:backup @@ -143,5 +149,8 @@ function fatal() { } if [ "$0" == "${BASH_SOURCE[0]}" ]; then + SECONDS=0 + log "Start" main "$@" + log "Stop ($?): $(python3 -c "print(int(10*$SECONDS/60)/10.0, 'minutes')")" fi diff --git a/testdata-old/b b/testdata-old/b old mode 100644 new mode 100755 diff --git a/testdata-old/c b/testdata-old/c old mode 100644 new mode 100755 diff --git a/testdata-old/d b/testdata-old/d old mode 100644 new mode 100755 diff --git a/testdata/b b/testdata/b old mode 100644 new mode 100755 diff --git a/testdata/c b/testdata/c old mode 100644 new mode 100755