master
Bel LaPointe 2020-03-24 09:35:00 -06:00
parent 370a033a62
commit 622ceaa922
11 changed files with 24 additions and 15 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
2do Normal file → Executable file
View File

0
config/rclone Normal file → Executable file
View File

0
config/restic Normal file → Executable file
View File

0
go/pkg/linux_amd64/github.com/restic/restic.a Normal file → Executable file
View File

39
sync.sh Normal file → Executable file
View File

@ -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

0
testdata-old/b Normal file → Executable file
View File

0
testdata-old/c Normal file → Executable file
View File

0
testdata-old/d Normal file → Executable file
View File

0
testdata/b vendored Normal file → Executable file
View File

0
testdata/c vendored Normal file → Executable file
View File