From 7e674b205ff7a6bb5e685229a75f01117ffd13f8 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 4 Sep 2024 23:09:04 +0000 Subject: [PATCH] rsync-net: add a script to help with restoring backups --- .../services/rsync-net/sane-restore-rsync-net | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 hosts/modules/services/rsync-net/sane-restore-rsync-net diff --git a/hosts/modules/services/rsync-net/sane-restore-rsync-net b/hosts/modules/services/rsync-net/sane-restore-rsync-net new file mode 100755 index 000000000..8624f52a8 --- /dev/null +++ b/hosts/modules/services/rsync-net/sane-restore-rsync-net @@ -0,0 +1,27 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p bash -p nettools -p openssh -p rsync -p sane-scripts.vpn -p sanebox + +# rsync password auth doesn't work with rsync.net. +# ssh keyfile auth *does* work, so i use that. +# for setup, see: +# - requires my pubkey to be copied to .ssh/authorized_keys on the remote. + +set -xe + +# secret should include RN_USER +source /run/secrets/rsync-net-env +RN_ID=/run/secrets/rsync-net-id_ed25519 + +test -n "$RN_USER" && test -f "$RN_ID" + +#vvv one or both may be empty, to `ls` the remote +srcdir="$1" +destdir="$2" + +RN_ROOT="$RN_USER@$RN_USER.rsync.net" + +if [ -z "$destdir" ]; then + ssh -i "$RN_ID" "$RN_ROOT" ls "$srcdir" +else + rsync -e "ssh -i $RN_ID" -rlptgov "$RN_ROOT:$srcdir" "$destdir" +fi