From c69f79ef287c1cba077cf74d87a6ce59b20724d5 Mon Sep 17 00:00:00 2001 From: Tero Huttunen Date: Fri, 2 Oct 2026 13:22:45 +0300 Subject: [PATCH] UI exit fixes --- README.md | 2 +- zfs-move-over-ssh.sh | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c239b1..be5d416 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ On a terminal (not with `--dry-run`), each filesystem shows a live progress bloc ``` The overall bar is weighted by each filesystem's logical size. Output that is -not a terminal falls back to plain output. +not a terminal falls back to plain output. Pass `--no-ui` to force plain output. Use a non-standard SSH key or port when needed: diff --git a/zfs-move-over-ssh.sh b/zfs-move-over-ssh.sh index 0bc177d..35a77f8 100644 --- a/zfs-move-over-ssh.sh +++ b/zfs-move-over-ssh.sh @@ -20,6 +20,7 @@ Options: -i, --identity-file FILE SSH private key to use. -p, --ssh-port PORT SSH port to use. --destroy-source-snapshots Destroy each local migration snapshot after its successful receive. + --no-ui Disable the live progress display; print plain output. -h, --help Show this help. SSH must use key or agent authentication; password prompts are disabled. The @@ -35,6 +36,7 @@ die() { DRY_RUN=false DESTROY_SOURCE_SNAPSHOTS=false +NO_UI=false SSH_OPTIONS=(-o BatchMode=yes) while (($#)); do @@ -55,6 +57,9 @@ while (($#)); do --destroy-source-snapshots) DESTROY_SOURCE_SNAPSHOTS=true ;; + --no-ui) + NO_UI=true + ;; -h|--help) usage exit 0 @@ -136,7 +141,7 @@ mapfile -t FILESYSTEMS < <(zfs list -H -o name -t filesystem -r "$SOURCE_POOL") # Progress UI needs a terminal and a real transfer. UI=false -if ! $DRY_RUN && [[ -t 1 ]]; then +if ! $DRY_RUN && ! $NO_UI && [[ -t 1 ]]; then UI=true exec 4>&1 fi @@ -217,11 +222,21 @@ for filesystem in "${FILESYSTEMS[@]}"; do 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'" + } 3>&1 | ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -uF '$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" + 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'"