Skip to content

Commit b8776cc

Browse files
committed
If the logs are read, display the backup speed
1 parent 0f17550 commit b8776cc

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-05-02 Matteo Corti <[email protected]>
2+
3+
* tmstatus.sh: if the logs are read, display the backup speed
4+
15
2023-04-02 Matteo Corti <[email protected]>
26

37
* tmstatus.sh: filter out spurious df errors

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* 2023-05-02, Version 1.12.0
2+
* If the logs are read, display the backup speed
13
* 2023-03-30, Version 1.11.0
24
* Displays the progress by the phase 'finding changes'
35
* Displays the number of backups today

RELEASE_NOTES.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* Displays the progress by the phase 'finding changes'
2-
* Displays the number of backups today
1+
If the logs are read, display the backup speed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.0
1+
1.12.0

tmstatus.sh

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313

1414
# shellcheck disable=SC2034
15-
VERSION=1.11.0
15+
VERSION=1.12.0
1616

1717
export LC_ALL=C
1818

@@ -271,6 +271,14 @@ fi
271271
##############################################################################
272272
# Current status
273273

274+
# we read the log file early
275+
if [ -n "${SHOWLOG}" ]; then
276+
277+
# per default TM runs each hour: check the last 60 minutes
278+
LOG_ENTRIES=$( log show --predicate 'subsystem == "com.apple.TimeMachine"' --info )
279+
280+
fi
281+
274282
status=$(tmutil status)
275283

276284
if echo "${status}" | grep -q 'BackupPhase'; then
@@ -371,27 +379,67 @@ else
371379

372380
fi
373381

382+
if [ -n "${LOG_ENTRIES}" ] ; then
383+
384+
SPEED=$(
385+
echo "${LOG_ENTRIES}" |
386+
grep 'Progress: ' |
387+
tail -n 1 |
388+
sed 's/.*done, //'
389+
)
390+
391+
392+
PERC_PER_SECOND=$( echo "${SPEED}" | sed 's/%\/s.*//' )
393+
PERC_PER_MINUTE=$( echo "scale=2;${PERC_PER_SECOND}*60" | bc )
394+
if [ -n "${PERC_PER_MINUTE}" ] ; then
395+
if echo "${PERC_PER_MINUTE}" | grep -q '^[.]' ; then
396+
PERC_PER_MINUTE=" (0${PERC_PER_MINUTE} %/min)"
397+
else
398+
PERC_PER_MINUTE=$( echo "${PERC_PER_MINUTE}" | sed 's/[.].*//' )
399+
PERC_PER_MINUTE=" (${PERC_PER_MINUTE} %/min)"
400+
fi
401+
fi
374402

403+
DATA_SPEED=$(
404+
echo "${SPEED}" |
405+
sed -e 's/.*%\/s, //' -e 's/,[ 0-9.]*items.*//'
406+
)
407+
if [ -n "${DATA_SPEED}" ] ; then
408+
DATA_SPEED=" (${DATA_SPEED})"
409+
fi
410+
411+
ITEM_SPEED=$(
412+
echo "${SPEED}" |
413+
sed 's/.*MB\/s, //'
414+
)
415+
416+
fi
375417

376418
if echo "${status}" | grep '_raw_Percent' | grep -q -v '[0-9]e-'; then
377419
if echo "${status}" | grep -q '_raw_Percent" = 1;'; then
378420
percent='100%'
379421
else
380422
percent=$(echo "${status}" | grep '_raw_Percent" = "0' | sed 's/.*[.]//' | sed 's/\([0-9][0-9]\)\([0-9]\).*/\1.\2%/' | sed 's/^0//')
381423
fi
382-
printf 'Percent:\t%s\n' "${percent}"
424+
printf 'Percent:\t%s%s\n' "${percent}" "${PERC_PER_MINUTE}"
383425

384426
raw_percent=$(echo "${status}" | grep '_raw_Percent' | sed 's/.*\ =\ "//' | sed 's/".*//')
385427

386428
if echo "${status}" | grep -q 'bytes'; then
387429
size=$(echo "${status}" | grep 'bytes\ \=' | sed 's/.*bytes\ \=\ //' | sed 's/;.*//')
388430
copied_size=$(echo "${size} / ${raw_percent}" | bc | format_size)
389431
size=$(echo "${size}" | format_size)
390-
printf 'Size:\t\t%s of %s\n' "${size}" "${copied_size}"
432+
printf 'Size:\t\t%s of %s%s\n' "${size}" "${copied_size}" "${DATA_SPEED}"
391433
fi
392434

393435
fi
394436

437+
if [ -n "${ITEM_SPEED}" ] ; then
438+
439+
printf 'Speed:\t\t%s\n' "${ITEM_SPEED}"
440+
441+
fi
442+
395443
# Print verifying status
396444
if echo "${status}" | grep -q -F HealthCheckFsck; then
397445
if echo "${status}" | grep -q -F 'Percent = "0'; then
@@ -444,8 +492,8 @@ if [ -n "${SHOWLOG}" ]; then
444492
SEQ=$(seq 1 "${WIDTH}")
445493

446494
# per default TM runs each hour: check the last 60 minutes
447-
ENTRIES=$(
448-
log show --predicate 'subsystem == "com.apple.TimeMachine"' --info |
495+
LOG_ENTRIES=$(
496+
echo "${LOG_ENTRIES}" |
449497
grep --line-buffered \
450498
--invert \
451499
--regexp '^Timestamp' \
@@ -496,13 +544,13 @@ if [ -n "${SHOWLOG}" ]; then
496544
tail -n "${SHOWLOG}"
497545
)
498546

499-
if [ -n "${ENTRIES}" ]; then
547+
if [ -n "${LOG_ENTRIES}" ]; then
500548

501549
# shellcheck disable=SC2086
502550
printf '%.s-' ${SEQ}
503551
echo
504552

505-
echo "${ENTRIES}"
553+
echo "${LOG_ENTRIES}"
506554

507555
# shellcheck disable=SC2086
508556
printf '%.s-' ${SEQ}

0 commit comments

Comments
 (0)