UI exit fixes
This commit is contained in:
+17
-2
@@ -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'"
|
||||
|
||||
Reference in New Issue
Block a user