Needs some prune but pretty gud

master
Bel LaPointe 2019-06-25 09:30:57 -06:00
parent 98fcfc2bcb
commit 1e7a7da7ac
8 changed files with 39 additions and 6 deletions

3
2do Normal file
View File

@ -0,0 +1,3 @@
TODO
- pull command to get LATEST from any source, pull, extract to TARGET dir

View File

@ -1,4 +1,4 @@
[remote] [remote]
type = drive type = drive
token = {"access_token":"ya29.GlwxB54qvp3VZajUzFQSzVFTmHKAFLGlIVoQ504ZDFlC2GXbhQry3Wb8IvTZEGSPCrC5o8PO9yHQxZ5szPeAomkpu5zyT5o242Ae0VxZTwYAdhcK2a4OHN1eVib6VQ","token_type":"Bearer","refresh_token":"1/bCag1YzbcbjLgZEpfLZzku9l293RiEzHdVNnkdIHRSo","expiry":"2019-06-24T12:09:45.976252-06:00"} token = {"access_token":"ya29.GlwyB7bPoazIlbMVi1vXm6yQNZkU0W9PzO4xDYfkW6hICI05RtBHOyU4AychW6r9ucxdfPUIPTh8cdFt__dy_DzEqWJh9x1JuDNeafWVqZa6lgpoqptOPk_gOKo-NQ","token_type":"Bearer","refresh_token":"1/bCag1YzbcbjLgZEpfLZzku9l293RiEzHdVNnkdIHRSo","expiry":"2019-06-25T10:05:04.667776-06:00"}

35
sync.sh
View File

@ -20,6 +20,7 @@ function main() {
shift shift
case "$action" in case "$action" in
backup ) backup "$@" ;; backup ) backup "$@" ;;
restore ) restore "$@" ;;
* ) RESTIC "$action" "$@" ;; * ) RESTIC "$action" "$@" ;;
esac esac
} }
@ -34,7 +35,7 @@ function install() {
go get -u github.com/$i go get -u github.com/$i
pushd $GOPATH/src/github.com/$i pushd $GOPATH/src/github.com/$i
case "$i" in case "$i" in
restic* ) restic* )
go run build.go go run build.go
mv ./$b $GOPATH/bin/$(uname)/$b mv ./$b $GOPATH/bin/$(uname)/$b
;; ;;
@ -52,7 +53,7 @@ function configure() {
if [ ! -e $PWD/config/rclone ]; then if [ ! -e $PWD/config/rclone ]; then
configure_rclone configure_rclone
fi fi
if [ ! -e $PWD/config/restic ]; then if ! RESTIC snapshots; then
configure_restic configure_restic
fi fi
} }
@ -75,11 +76,35 @@ function configure_restic() {
function backup() { function backup() {
for arg in "$@"; do for arg in "$@"; do
local real="$(realpath "$arg")" local real="$(realpath "$arg")"
if [ "$real" == "${read#$HOME/}" ]; then
log "Cowardly skipping $arg ($real) for not being under \$HOME ($HOME)"
continue
fi
echo BACKUP $real echo BACKUP $real
RESTIC backup \ RESTIC backup \
-e "**.sw*" \ -e "**.sw*" \
$real --tag "${real#$HOME/}" \
RESTIC forget --keep-last 20 $real
RESTIC forget --keep-last 2 --group-by host,tags #--prune
done
}
function restore() {
for arg in "$@"; do
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 id="$(echo "$latest" | awk '{print $1}')"
local path="$(echo "$latest" | awk '{print $5}')"
echo restore $id as $HOME/$path as $HOME/$path-restore
rm -rf $HOME/$path-{dump,restore} 2> /dev/null || true
mkdir -p $HOME/$path-dump
RESTIC restore $id --target $HOME/$path-dump
mv $HOME/$path-dump/${HOME#/}/$path $HOME/$path-restore
rm -rf $HOME/$path-{dump,old}
mv $HOME/$path $HOME/$path-old
mv $HOME/$path-restore $HOME/$path
done done
} }
@ -95,7 +120,7 @@ function RESTIC() {
-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 6M --ask-password=false" \
"$@" "$@"
#-r rclone:remote-enc:backup #-r rclone:remote-enc:backup
} }
function log() { function log() {

1
testdata-old/b Normal file
View File

@ -0,0 +1 @@
a

1
testdata-old/c Normal file
View File

@ -0,0 +1 @@
b

1
testdata-old/d Normal file
View File

@ -0,0 +1 @@
a

1
testdata/b vendored Normal file
View File

@ -0,0 +1 @@
a

1
testdata/c vendored Normal file
View File

@ -0,0 +1 @@
b