zsc-sync.sh: don't mount remote fs, don't interrupt on errors

This commit is contained in:
Alice Gaudon 2021-04-06 10:27:28 +02:00
parent 7ed6a15ec3
commit e0af0c4021

View File

@ -46,7 +46,7 @@ resume_transfer() {
RESUME_TOKEN=$(echo -e "$resume_tokens" | grep -P "^$remote_dataset\t.*\$" | cut -d$'\t' -f2)
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
zfs send -v -t "$RESUME_TOKEN" | ssh $REMOTE zfs receive -Fu -s "$remote_dataset" || return 1
echo "Resumed transfer finished."
update_remote_state
return 0
@ -120,12 +120,16 @@ handle_dataset() {
if [ $RECURSIVE = true ] ; then
recu="-R"
fi
zfs send -v -p $recu $incr "$DATASET@$TO_SNAPSHOT" | ssh $REMOTE zfs receive -F -s "$TARGET_REMOTE_DATASET" || return 1
zfs send -v -p $recu $incr "$DATASET@$TO_SNAPSHOT" | ssh $REMOTE zfs receive -Fu -s "$TARGET_REMOTE_DATASET" || return 1
echo
echo "Done"
echo
else
echo "No snapshot to sync"
fi
return 0
}
init_subdataset() {
@ -149,7 +153,7 @@ init_subdataset() {
fi
echo "[$DATASET@$LOCAL_SNAPSHOT -> $TARGET_REMOTE_DATASET]"
zfs send -v -p "$DATASET@$LOCAL_SNAPSHOT" | ssh $REMOTE zfs receive -F -s "$TARGET_REMOTE_DATASET" || return 1
zfs send -v -p "$DATASET@$LOCAL_SNAPSHOT" | ssh $REMOTE zfs receive -Fu -s "$TARGET_REMOTE_DATASET" || return 1
echo
echo "--- Done"
@ -158,17 +162,21 @@ init_subdataset() {
echo
echo "--- Subdataset $TARGET_REMOTE_DATASET is out of date compared to parent dataset. Syncing first..."
handle_dataset "$DATASET" false "" "$TARGET_REMOTE_DATASET" || exit 1
handle_dataset "$DATASET" false "" "$TARGET_REMOTE_DATASET" || return 1
echo
echo "--- Done"
echo
fi
return 0
}
update_remote_state
HAD_ERROR=0
for line in $(cat "$ZSC_CONFIG") ; do
IFS=: read dataset recursive d w m y prefix <<< "$line"
echo
@ -206,14 +214,30 @@ for line in $(cat "$ZSC_CONFIG") ; do
echo "Subdatasets: ${SUBDATASETS[@]}"
echo
for p in "${SUBDATASETS[@]}"; do
init_subdataset $p $dataset "$latest_synchronized_snapshot" || exit 1
init_subdataset $p $dataset "$latest_synchronized_snapshot"
r=$?
if [ ! $r ]; then
echo "Error while initing subdataset $p, continuing"
if [ $HAD_ERROR ]; then
HAD_ERROR=$r
fi
fi
done
echo
echo "----------"
echo
update_remote_state
fi
handle_dataset $dataset $recursive $prefix || exit 1
handle_dataset $dataset $recursive $prefix
r=$?
if [ ! $r ]; then
echo "Error while initing subdataset $p, continuing"
if [ $HAD_ERROR ]; then
HAD_ERROR=$r
fi
fi
echo
echo "----------------------------------------------------------------------"
@ -224,3 +248,5 @@ done
### UNLOCK ###
echo "Unlocking $0"
lockfile-remove "$0"
exit $HAD_ERROR