Dir handling fixes

This commit is contained in:
2026-10-02 13:36:42 +03:00
parent c69f79ef28
commit 746f634a90
2 changed files with 42 additions and 11 deletions
+34 -6
View File
@@ -196,50 +196,67 @@ send_progress() {
ls = s; lb = b; seen = 1; render(); next
}
{ printf "\033[3A\033[J%s\n\n\n\n", $0 }
END { if (est > 0) b = est; render() }
END { render() }
' >&4 3>&-
}
prior_weight=0
index_now=0
FAILED=()
SKIPPED=()
remote_dataset_exists() {
ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" \
"sudo -n zfs list -H -o name -t filesystem '$1' >/dev/null 2>&1"
}
printf 'Migration snapshot: %s\n' "$SNAPSHOT_NAME"
for filesystem in "${FILESYSTEMS[@]}"; do
destination="$(map_destination "$filesystem")"
snapshot="${filesystem}@${SNAPSHOT_NAME}"
remote_snapshot="${destination}@${SNAPSHOT_NAME}"
index_now=$((index_now + 1))
# Never touch datasets that already exist on the destination (no -F, no rollback).
if ! $DRY_RUN && remote_dataset_exists "$destination"; then
printf 'Skipping %s: %s already exists on %s\n' "$filesystem" "$destination" "$REMOTE_HOST"
SKIPPED+=("$filesystem")
prior_weight=$((prior_weight + ${WEIGHT[$filesystem]:-0}))
continue
fi
printf 'Transferring %s to %s:%s\n' "$filesystem" "$REMOTE_HOST" "$destination"
run zfs snapshot "$snapshot"
if $DRY_RUN; then
printf '+ zfs send -p %q | ssh' "$snapshot" >&2
printf ' %q' "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -uF '$destination'" >&2
printf ' %q' "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -u '$destination'" >&2
printf '\n' >&2
else
if remote_snapshot_exists "$remote_snapshot"; then
remove_remote_snapshot "$remote_snapshot"
fi
if $UI; then
index_now=$((index_now + 1))
ssh_err="$(mktemp)"
send_status=0
{
zfs send -p -P -v "$snapshot" 2>&1 1>&3 3>&- \
| send_progress "$index_now" "${#FILESYSTEMS[@]}" "$filesystem" \
"$prior_weight" "${WEIGHT[$filesystem]:-0}" "$TOTAL_WEIGHT"
} 3>&1 | ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -uF '$destination'" 2>"$ssh_err" \
} 3>&1 | ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -u '$destination'" 2>"$ssh_err" \
|| send_status=$?
if ((send_status != 0)); then
printf '\nTransfer of %s failed (exit %d):\n' "$filesystem" "$send_status" >&2
cat "$ssh_err" >&2
rm -f "$ssh_err"
die "send/receive failed for $filesystem; re-run with --no-ui for plain output"
FAILED+=("$filesystem")
prior_weight=$((prior_weight + ${WEIGHT[$filesystem]:-0}))
continue
fi
rm -f "$ssh_err"
prior_weight=$((prior_weight + ${WEIGHT[$filesystem]:-0}))
else
zfs send -p "$snapshot" | ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -uF '$destination'"
zfs send -p "$snapshot" | ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -u '$destination'"
fi
fi
@@ -248,4 +265,15 @@ for filesystem in "${FILESYSTEMS[@]}"; do
fi
done
if ((${#SKIPPED[@]} > 0)); then
printf 'Skipped %d filesystem(s) that already exist on the destination:\n' "${#SKIPPED[@]}"
printf ' %s\n' "${SKIPPED[@]}"
fi
if ((${#FAILED[@]} > 0)); then
printf 'Finished with %d failed filesystem(s):\n' "${#FAILED[@]}" >&2
printf ' %s\n' "${FAILED[@]}" >&2
exit 1
fi
printf 'Completed. Local source filesystems were not destroyed.\n'