zsc-sync.sh: make resumed transfer a function

This commit is contained in:
Alice Gaudon 2021-03-08 12:21:09 +01:00
parent 9e16259e52
commit f4bc6336f2
1 changed files with 19 additions and 16 deletions

View File

@ -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