From 792a9ce358b078d4f97da8536bb37d31087943b0 Mon Sep 17 00:00:00 2001 From: Matteo Corti Date: Mon, 17 Jul 2023 14:38:23 +0200 Subject: [PATCH] Show the copied size for today's backups --- ChangeLog | 4 ++++ NEWS.md | 2 ++ RELEASE_NOTES.md | 2 +- VERSION | 2 +- tmstatus.sh | 26 +++++++++++++++++++------- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c95bed..f66675e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2023-07-17 Matteo Corti + + * tmstatus.sh: show the size of todays backups + 2023-07-10 Matteo Corti * tmstatus.sh: Fixed the time difference by the last local backup diff --git a/NEWS.md b/NEWS.md index 1c5d4b1..c03a791 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +* 2023-07-17. Version 1.16.0 + * Show the size of todays backups * 2023-07-07, Versiom 1.15.0 * Show information for all the disks (```--all``` option) * 2023-06-27, Version 1.14.0 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7a24212..0a62cd6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1 +1 @@ -Show information for all the disks (```--all``` option) +Show the size of todays backups diff --git a/VERSION b/VERSION index 141f2e8..15b989e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.15.0 +1.16.0 diff --git a/tmstatus.sh b/tmstatus.sh index 404b3a5..2a55b7d 100755 --- a/tmstatus.sh +++ b/tmstatus.sh @@ -12,7 +12,7 @@ # # shellcheck disable=SC2034 -VERSION=1.15.0 +VERSION=1.16.0 export LC_ALL=C @@ -309,7 +309,7 @@ EOF printf ' Local oldest:\t%s (%s)\n' "${BACKUP_DATE}" "${DAYS_AGO}" - DATE="$(echo "${LOCALSNAPSHOTDATES}" | tail -n 1 )" + DATE="$(echo "${LOCALSNAPSHOTDATES}" | tail -n 1)" days="$(days_since "${DATE}")" DAYS_AGO="$(format_days_ago "${days}")" BACKUP_DATE="$(echo "${LOCALSNAPSHOTDATES}" | tail -n 1 | sed 's/.*\///' | sed 's/-\([^\-]*\)$/\ \1/' | sed 's/\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/\1:\2:\3/')" @@ -332,8 +332,8 @@ if [ -n "${SHOWLOG}" ] || [ -n "${SHOW_SPEED}" ] || [ -n "${PROGRESS}" ]; then printf "Reading the logs..." - # per default TM runs each hour: check the last 60 minutes - LOG_LAST='--last 60m' + # check the last day for today's backups sizes + LOG_LAST='--last 3600m' # shellcheck disable=SC2086 LOG_ENTRIES=$(log show ${LOG_LAST} --color none --predicate 'subsystem == "com.apple.TimeMachine"' --info) @@ -538,19 +538,31 @@ if [ -n "${TODAY}" ]; then TODAYS_DATE="$(date +"%Y-%m-%d")" - if tmutil destinationinfo | grep -q '^Mount Point' ; then + if tmutil destinationinfo | grep -q '^Mount Point'; then echo fi - + tmutil destinationinfo | grep '^Mount Point' | sed -e 's/.*: //' | while read -r tm_mount_point; do LISTBACKUPS=$(tmutil listbackups -d "${tm_mount_point}" 2>&1) TODAYS_BACKUPS=$(echo "${LISTBACKUPS}" | grep "${TODAYS_DATE}" | sed -e 's/.*\///' -e 's/\.backup//' -e 's/.*\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)$/\1:\2/') + if [ -n "${LOG_ENTRIES}" ]; then + + # Information on backup size: https://eclecticlight.co/2021/04/09/time-machine-to-apfs-how-efficient-are-backups/ + for b in ${TODAYS_BACKUPS}; do + # the log entry could also be a minute before. It is not accurate but we remove the last digit (could always be wrong if ending with 0 but better than nothing) + b_short=$(echo "${b}" | sed 's/[0-9]$//') + b_size=$(echo "${LOG_ENTRIES}" | grep -A 10 "${TODAYS_DATE} ${b_short}" | grep -A 10 'Finished copying from' | grep 'Files Copied' | sed -e 's/.*p: //' -e 's/).*//') + TODAYS_BACKUPS=$(echo "${TODAYS_BACKUPS}" | sed "s/${b}/${b} (${b_size})/") + done + + fi + # without the grep ':' there is always one line (empty) NUMBER_OF_TODAYS_BACKUPS=$(echo "${TODAYS_BACKUPS}" | grep -c ':' | sed 's/[ ]//g') - TODAYS_BACKUPS=$( echo "${TODAYS_BACKUPS}" | tr '\n' ',' | sed 's/,/, /g' | sed 's/, $//' ) + TODAYS_BACKUPS=$(echo "${TODAYS_BACKUPS}" | tr '\n' ',' | sed 's/,/, /g' | sed 's/, $//') if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 0 ]; then echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE}) on \"${tm_mount_point}\""