UI printing fix
This commit is contained in:
+13
-6
@@ -163,8 +163,8 @@ fi
|
||||
|
||||
# Reads `zfs send -P -v` output on stdin and redraws a 3-line block on fd 4.
|
||||
send_progress() {
|
||||
local idx="$1" count="$2" name="$3" prior_w="$4" cur_w="$5" total_w="$6"
|
||||
awk -F'\t' -v idx="$idx" -v count="$count" -v name="$name" \
|
||||
local idx="$1" count="$2" name="$3" prior_w="$4" cur_w="$5" total_w="$6" fresh="$7"
|
||||
awk -F'\t' -v idx="$idx" -v count="$count" -v name="$name" -v fresh="$fresh" \
|
||||
-v prior_w="$prior_w" -v cur_w="$cur_w" -v total_w="$total_w" '
|
||||
function human(b, u, i) {
|
||||
split("B KB MB GB TB PB", u, " "); i = 1
|
||||
@@ -187,7 +187,7 @@ send_progress() {
|
||||
printf "\033[2K Dataset %s %3d%% %s / %s %s/s%s\n", bar(pct), pct, human(b), human(est), human(rate), eta
|
||||
printf "\033[2K Overall %s %3d%%\n", bar(op), op
|
||||
}
|
||||
BEGIN { printf "\n\n\n" }
|
||||
BEGIN { if (fresh == 1) printf "\n\n\n" }
|
||||
$1 == "size" { est = $2 + 0; render(); next }
|
||||
$1 == "full" || $1 == "incremental" { next }
|
||||
$1 ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/ {
|
||||
@@ -202,9 +202,12 @@ send_progress() {
|
||||
|
||||
prior_weight=0
|
||||
index_now=0
|
||||
BLOCK_DRAWN=0
|
||||
FAILED=()
|
||||
SKIPPED=()
|
||||
|
||||
trap 'printf "\nInterrupted.\n" >&2; exit 130' INT TERM
|
||||
|
||||
remote_dataset_exists() {
|
||||
ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" \
|
||||
"sudo -n zfs list -H -o name -t filesystem '$1' >/dev/null 2>&1"
|
||||
@@ -219,13 +222,13 @@ for filesystem in "${FILESYSTEMS[@]}"; do
|
||||
|
||||
# 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"
|
||||
$UI || 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"
|
||||
$UI || printf 'Transferring %s to %s:%s\n' "$filesystem" "$REMOTE_HOST" "$destination"
|
||||
run zfs snapshot "$snapshot"
|
||||
|
||||
if $DRY_RUN; then
|
||||
@@ -234,6 +237,7 @@ for filesystem in "${FILESYSTEMS[@]}"; do
|
||||
printf '\n' >&2
|
||||
else
|
||||
if remote_snapshot_exists "$remote_snapshot"; then
|
||||
BLOCK_DRAWN=0
|
||||
remove_remote_snapshot "$remote_snapshot"
|
||||
fi
|
||||
if $UI; then
|
||||
@@ -242,10 +246,13 @@ for filesystem in "${FILESYSTEMS[@]}"; do
|
||||
{
|
||||
zfs send -p -P -v "$snapshot" 2>&1 1>&3 3>&- \
|
||||
| send_progress "$index_now" "${#FILESYSTEMS[@]}" "$filesystem" \
|
||||
"$prior_weight" "${WEIGHT[$filesystem]:-0}" "$TOTAL_WEIGHT"
|
||||
"$prior_weight" "${WEIGHT[$filesystem]:-0}" "$TOTAL_WEIGHT" \
|
||||
"$((1 - BLOCK_DRAWN))"
|
||||
} 3>&1 | ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" "sudo -n zfs receive -u '$destination'" 2>"$ssh_err" \
|
||||
|| send_status=$?
|
||||
BLOCK_DRAWN=1
|
||||
if ((send_status != 0)); then
|
||||
BLOCK_DRAWN=0
|
||||
printf '\nTransfer of %s failed (exit %d):\n' "$filesystem" "$send_status" >&2
|
||||
cat "$ssh_err" >&2
|
||||
rm -f "$ssh_err"
|
||||
|
||||
Reference in New Issue
Block a user