Add more graph

This commit is contained in:
2026-10-02 11:42:03 +03:00
parent 604f0abfb0
commit b955356d7a
3 changed files with 129 additions and 81 deletions
+50 -2
View File
@@ -79,11 +79,59 @@ run_rsync() {
mkdir -p "$dst" mkdir -p "$dst"
local -a excludes=() local -a excludes=()
mapfile -t excludes < <(rsync_exclude_args) mapfile -t excludes < <(rsync_exclude_args)
local -a flags=(-aAXH --partial --info=progress2 "${excludes[@]}") local -a flags=(-aAXH --partial "${excludes[@]}")
[ -n "$ssh_cmd" ] && flags+=(-e "$ssh_cmd") [ -n "$ssh_cmd" ] && flags+=(-e "$ssh_cmd")
[ "$DRY_RUN" -eq 1 ] && flags+=(--dry-run) [ "$DRY_RUN" -eq 1 ] && flags+=(--dry-run)
log "rsync: $src -> $dst" log "rsync: $src -> $dst"
rsync "${flags[@]}" "$src" "$dst" 2>&1 | tee -a "$logfile"
# Plain output when not on a terminal, parallel jobs share the screen, or dry-run.
if [ ! -t 1 ] || [ "$JOBS" -gt 1 ] || [ "$DRY_RUN" -eq 1 ]; then
rsync "${flags[@]}" --info=progress2 "$src" "$dst" 2>&1 | tee -a "$logfile"
return
fi
log "scanning $src ..."
local total_bytes
total_bytes="$(rsync "${flags[@]}" --dry-run --stats "$src" "$dst" 2>/dev/null \
| awk -F': ' '/^Total transferred file size/{gsub(/[^0-9]/,"",$2); print $2}')"
total_bytes="${total_bytes:-0}"
rsync "${flags[@]}" --progress "$src" "$dst" 2>&1 | progress_ui "$total_bytes" "$logfile"
}
# Reads rsync --progress output; draws current-file bar, total bar and the rolling filename.
progress_ui() {
local total="$1" logfile="$2" cols
cols="$(tput cols 2>/dev/null || echo 80)"
awk -v total="$total" -v logf="$logfile" -v cols="$cols" '
function human(b, u, i) {
split("B KB MB GB TB", u, " "); i = 1
while (b >= 1024 && i < 5) { b /= 1024; i++ }
return sprintf("%.1f%s", b, u[i])
}
function bar(p, w, n, s, i) {
if (p > 100) p = 100
n = int(p * w / 100); s = ""
for (i = 0; i < w; i++) s = s (i < n ? "#" : "-")
return "[" s "]"
}
function render( tp, shown) {
tp = (total > 0) ? (done + curb) * 100 / total : 0
shown = substr(name, 1, cols - 4)
printf "\033[3A\r\033[2K File %s %3d%% %s\n", bar(cp, 30), cp, rate
printf "\033[2K Total %s %3d%% %s / %s, %d files\n", bar(tp, 30), tp, human(done + curb), human(total), files
printf "\033[2K > %s\n", shown
}
BEGIN { RS = "[\r\n]"; printf "\n\n\n" }
/^[ \t]+[0-9,]+[ \t]+[0-9]+%/ {
b = $1; gsub(",", "", b); curb = b + 0; cp = $2 + 0; rate = $3
if (cp >= 100 && !counted) { done += curb; counted = 1; curb = 0 }
render(); next
}
/^(sending|building|receiving|sent |total size|created)/ || $0 == "" { next }
{ name = $0; print name >> logf; counted = 0; curb = 0; cp = 0; files++; render() }
END { if (total > 0) { done = total; curb = 0 } cp = 100; render() }
'
} }
# ---------- SSH method ---------- # ---------- SSH method ----------