goodie
parent
370a033a62
commit
622ceaa922
|
|
@ -5,7 +5,7 @@ function main() {
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
export GOPATH="$PWD/go"
|
export GOPATH="$PWD/restic-go"
|
||||||
|
|
||||||
if [ -z "${PASSWORD:-""}" ]; then
|
if [ -z "${PASSWORD:-""}" ]; then
|
||||||
read -sp "Password: " PASSWORD
|
read -sp "Password: " PASSWORD
|
||||||
|
|
@ -19,10 +19,9 @@ function main() {
|
||||||
local action="$1"
|
local action="$1"
|
||||||
shift
|
shift
|
||||||
case "$action" in
|
case "$action" in
|
||||||
clean ) clean_remote --prune "$@" ;;
|
clean ) clean_remote "$@" ;;
|
||||||
backup ) backup "$@" ;;
|
backup ) backup "$@" ;;
|
||||||
restore ) restore "$@" ;;
|
restore ) restore "$@" ;;
|
||||||
forget ) fatal "Refusing custom forget" ;;
|
|
||||||
* ) RESTIC "$action" "$@" ;;
|
* ) RESTIC "$action" "$@" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +33,7 @@ function install() {
|
||||||
if [ -e "$GOPATH/bin/$(uname)/$b" ]; then
|
if [ -e "$GOPATH/bin/$(uname)/$b" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
go get -u "github.com/$i"
|
go get -u "github.com/$i" || true
|
||||||
pushd "$GOPATH/src/github.com/$i"
|
pushd "$GOPATH/src/github.com/$i"
|
||||||
case "$i" in
|
case "$i" in
|
||||||
restic* )
|
restic* )
|
||||||
|
|
@ -55,7 +54,7 @@ function configure() {
|
||||||
if [ ! -e "$PWD/config/rclone" ]; then
|
if [ ! -e "$PWD/config/rclone" ]; then
|
||||||
configure_rclone
|
configure_rclone
|
||||||
fi
|
fi
|
||||||
if ! RESTIC snapshots; then
|
if [ ! -e "$PWD/config/restic" ]; then
|
||||||
configure_restic
|
configure_restic
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -76,18 +75,25 @@ function configure_restic() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function backup() {
|
function backup() {
|
||||||
|
local args=()
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
local real="$(realpath "$arg")"
|
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)"
|
log "Cowardly skipping $arg ($real) for not being under \$HOME ($HOME)"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
log "BACKUP $real"
|
args+=("$real")
|
||||||
|
done
|
||||||
|
local extraTags=" "
|
||||||
|
if [ -n "${TAGS:-""}" ]; then
|
||||||
|
extraTags="--tag $TAGS"
|
||||||
|
fi
|
||||||
|
log "BACKUP ${args[@]}"
|
||||||
RESTIC backup \
|
RESTIC backup \
|
||||||
-e "**.sw*" \
|
-e "**.sw*" \
|
||||||
--tag "${real#$HOME/}" \
|
--tag "${real#$HOME/}" \
|
||||||
"$real"
|
$extraTags \
|
||||||
done
|
"${args[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function restore() {
|
function restore() {
|
||||||
|
|
@ -95,7 +101,7 @@ function restore() {
|
||||||
if [ -e "$arg" ] || [ -d "$arg" ]; then
|
if [ -e "$arg" ] || [ -d "$arg" ]; then
|
||||||
arg="$(realpath "$arg")"
|
arg="$(realpath "$arg")"
|
||||||
fi
|
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 id="$(echo "$latest" | awk '{print $1}')"
|
||||||
local path="$(echo "$latest" | awk '{print $5}')"
|
local path="$(echo "$latest" | awk '{print $5}')"
|
||||||
local rpath="$(echo "$latest" | awk '{print $6}')"
|
local rpath="$(echo "$latest" | awk '{print $6}')"
|
||||||
|
|
@ -110,11 +116,11 @@ function restore() {
|
||||||
fi
|
fi
|
||||||
mv "$HOME/$path-restore" "$HOME/$path"
|
mv "$HOME/$path-restore" "$HOME/$path"
|
||||||
done
|
done
|
||||||
clean_remote --prune
|
clean_remote
|
||||||
}
|
}
|
||||||
|
|
||||||
function 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
|
RESTIC check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +133,7 @@ function RESTIC() {
|
||||||
$GOPATH/bin/$(uname)/restic \
|
$GOPATH/bin/$(uname)/restic \
|
||||||
-r rclone:remote:cloudly/restic-plain/backup \
|
-r rclone:remote:cloudly/restic-plain/backup \
|
||||||
-o rclone.program=$GOPATH/bin/$(uname)/rclone \
|
-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
|
#-r rclone:remote-enc:backup
|
||||||
|
|
@ -143,5 +149,8 @@ function fatal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$0" == "${BASH_SOURCE[0]}" ]; then
|
if [ "$0" == "${BASH_SOURCE[0]}" ]; then
|
||||||
|
SECONDS=0
|
||||||
|
log "Start"
|
||||||
main "$@"
|
main "$@"
|
||||||
|
log "Stop ($?): $(python3 -c "print(int(10*$SECONDS/60)/10.0, 'minutes')")"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue