at least it does backups

master
bel 2019-06-22 11:55:17 -06:00
commit 8898826916
3 changed files with 122 additions and 0 deletions

12
config/rclone Normal file
View File

@ -0,0 +1,12 @@
[remote]
type = drive
token = {"access_token":"ya29.GlsvBx0P-xi5MILSKADEHrrHNnOIExq4WopaWsjhZDdFj6xDkJ5NsLLxnJPpYDytHBtMVg5N3Z5pfE9ad0MLD5rTpmPvPScWeML_ZPj321LT-4YZGI5BVFUb7DpU","token_type":"Bearer","refresh_token":"1/w4bWtZbYRdrx6QxezVGkwYO19UAwDCrbnB9QngotBig","expiry":"2019-06-22T12:07:42.879544991-06:00"}
[remote-enc]
type = crypt
remote = remote:cloudly/restic
filename_encryption = obfuscate
directory_name_encryption = true
password = 7goajHzgKv3SI2mamNivoqUJfHlIw1gu
password2 = 34ofTPjOpG6pVPwox8Fjaw

0
config/restic Normal file
View File

110
sync.sh Normal file
View File

@ -0,0 +1,110 @@
#! /bin/bash
function main() {
set -e
set -u
cd "$(dirname "${BASH_SOURCE[0]}")"
export GOPATH=$PWD/go
if [ -z "${PASSWORD:-""}" ]; then
read -sp "Password: " PASSWORD
echo ""
fi
install
configure
local action="$1"
shift
case "$action" in
backup ) backup "$@" ;;
* ) RESTIC "$action" "$@" ;;
esac
}
function install() {
for i in ncw/rclone restic/restic; do
local b="${i##*/}"
if [ -e $GOPATH/bin/$b ]; then
continue
fi
go get -u github.com/$i
pushd $GOPATH/src/github.com/$i
case "$i" in
restic* )
go run build.go
mv ./restic $GOPATH/bin
;;
* )
go install
;;
esac
popd
done
}
function configure() {
mkdir -p $PWD/config
if [ ! -e $PWD/config/rclone ]; then
configure_rclone
fi
if [ ! -e $PWD/config/restic ]; then
configure_restic
fi
}
function configure_rclone() {
RCLONE config create remote drive
#RCLONE config create remote-enc crypt \
# remote remote:cloudly/restic \
# filename_encryption obfuscate \
# directory_name_encryption true \
# password $PASSWORD \
# password2 ""
}
function configure_restic() {
RESTIC init
touch $PWD/config/restic
}
function backup() {
for arg in "$@"; do
local real="$(realpath "$arg")"
echo BACKUP $real
RESTIC backup \
-e "**.sw*" \
$real
RESTIC forget --keep-last 20
done
}
function RCLONE() {
$GOPATH/bin/rclone --config=$PWD/config/rclone --ask-password=false "$@"
}
function RESTIC() {
RESTIC_PASSWORD=$PASSWORD \
$GOPATH/bin/restic \
-r rclone:remote:cloudly/restic-plain/backup \
-o rclone.program=$GOPATH/bin/rclone \
-o rclone.args="serve restic --stdio --b2-hard-delete --drive-use-trash=false --config $PWD/config/rclone --bwlimit 20M --ask-password=false" \
"$@"
#-r rclone:remote-enc:backup
}
function log() {
echo "$(date +%H:%M:%S): $@" >&2
}
function fatal() {
log "$@"
exit 1
}
if [ "$0" == "${BASH_SOURCE[0]}" ]; then
main "$@"
fi