From f4bc6336f2477e4ac670333a00393748214aac17 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 8 Mar 2021 12:21:09 +0100 Subject: [PATCH] zsc-sync.sh: make resumed transfer a function --- zsc-sync.sh | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/zsc-sync.sh b/zsc-sync.sh index e5d9286..4db1609 100755 --- a/zsc-sync.sh +++ b/zsc-sync.sh @@ -26,6 +26,23 @@ if ! lockfile-create -p -r 2 "zsc"; then fi +### Resume existing transfer ### +# Returns 0 if no action was performed, 1 if a transfer was resumed and finished successfully, -1 if there was an error during resumed transfer +resume_transfer() { + remote_dataset=$1 + + RESUME_TOKEN=$(ssh $REMOTE zfs get -H -p receive_resume_token -o value "$remote_dataset") + if [ "$RESUME_TOKEN" != "" ] && [ "$RESUME_TOKEN" != "-" ]; then + echo "Resuming interrupted transfer..." + zfs send -v -t "$RESUME_TOKEN" | ssh $REMOTE zfs receive -F -s "$remote_dataset" || return -1 + echo "Resumed transfer finished." + return 1 + fi + + return 0 +} + + handle_dataset() { DATASET=$1 RECURSIVE=$2 @@ -49,14 +66,7 @@ handle_dataset() { echo -e - ### Resume existing transfer ### - RESUME_TOKEN=$(ssh $REMOTE zfs get -H -p receive_resume_token -o value "$TARGET_REMOTE_DATASET") - if [ "$RESUME_TOKEN" != "" ] && [ "$RESUME_TOKEN" != "-" ]; then - echo "Resuming interrupted transfer..." - zfs send -v -t "$RESUME_TOKEN" | ssh $REMOTE zfs receive -F -s "$TARGET_REMOTE_DATASET" || return 1 - echo "Resumed transfer finished." - return 0 - fi + resume_transfer "$TARGET_REMOTE_DATASET" || return 0 ### Sync existing snapshots ### @@ -115,14 +125,7 @@ init_subdataset() { REMOTE_DATASETS=($(ssh $REMOTE zfs list -H -o name -s creation -r $REMOTE_ROOT_DATASET)) - ### Resume existing transfer ### - RESUME_TOKEN=$(ssh $REMOTE zfs get -H -p receive_resume_token -o value "$TARGET_REMOTE_DATASET") - if [ "$RESUME_TOKEN" != "" ] && [ "$RESUME_TOKEN" != "-" ]; then - echo "Resuming interrupted transfer..." - zfs send -v -t "$RESUME_TOKEN" | ssh $REMOTE zfs receive -F -s "$TARGET_REMOTE_DATASET" || return 1 - echo "Resumed transfer finished." - return 0 - fi + resume_transfer "$TARGET_REMOTE_DATASET" || return 0 found=false