zsc-sync.sh: make resumed transfer a function
This commit is contained in:
parent
9e16259e52
commit
f4bc6336f2
35
zsc-sync.sh
35
zsc-sync.sh
@ -26,6 +26,23 @@ if ! lockfile-create -p -r 2 "zsc"; then
|
|||||||
fi
|
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() {
|
handle_dataset() {
|
||||||
DATASET=$1
|
DATASET=$1
|
||||||
RECURSIVE=$2
|
RECURSIVE=$2
|
||||||
@ -49,14 +66,7 @@ handle_dataset() {
|
|||||||
echo -e
|
echo -e
|
||||||
|
|
||||||
|
|
||||||
### Resume existing transfer ###
|
resume_transfer "$TARGET_REMOTE_DATASET" || return 0
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
### Sync existing snapshots ###
|
### Sync existing snapshots ###
|
||||||
@ -115,14 +125,7 @@ init_subdataset() {
|
|||||||
REMOTE_DATASETS=($(ssh $REMOTE zfs list -H -o name -s creation -r $REMOTE_ROOT_DATASET))
|
REMOTE_DATASETS=($(ssh $REMOTE zfs list -H -o name -s creation -r $REMOTE_ROOT_DATASET))
|
||||||
|
|
||||||
|
|
||||||
### Resume existing transfer ###
|
resume_transfer "$TARGET_REMOTE_DATASET" || return 0
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
found=false
|
found=false
|
||||||
|
Loading…
Reference in New Issue
Block a user