UI exit fixes

This commit is contained in:
2026-10-02 13:22:45 +03:00
parent cf246d1329
commit c69f79ef28
2 changed files with 18 additions and 3 deletions
+1 -1
View File
@@ -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:
+17 -2
View File
@@ -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'"