Skip to content

Commit

Permalink
Release scripts and verification progress
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocorti committed Apr 20, 2021
1 parent 4161431 commit f4fc394
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 80 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2021-04-20 Matteo Corti <[email protected]>

* tmstatus.sh: Verifying progress

2021-02-16 Matteo Corti <[email protected]>

* tmstatus.sh: Better phase naminge
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* 2021-04-20, Version 1.3.0
* Show the progress of the verification step
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

(c) Matteo Corti, 2018
(c) Matteo Corti, 2018-2021

# tmstatus.sh

Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show the progress of the verification step
13 changes: 13 additions & 0 deletions publish_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

VERSION=$( grep VERSION tmstatus.sh | sed 's/.*=//' )

echo "Version ${VERSION}"
echo 'Did you update the RELEASE_NOTES.md? '
read -r ANSWER
if [ "x${ANSWER}" = "xy" ] ; then

make &&
gh release create "v${VERSION}" --title "tmstatus.sh-${VERSION}" --notes-file RELEASE_NOTES.md "tmstatus.sh-${VERSION}.tar.gz" "tmstatus.sh-${VERSION}.tar.bz2"

fi
165 changes: 86 additions & 79 deletions tmstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
#
# A simple script to summarise the Time Machine backup status
#
# Copyright (c) 2021 Matteo Corti <[email protected]>
# Copyright (c) 2018-2021 Matteo Corti <[email protected]>
#
# This module is free software; you can redistribute it and/or modify it
# under the terms of the Apache Licese v2
# See the LICENSE file for details.
#

# shellcheck disable=SC2034
VERSION=1.2.4
VERSION=1.3.0

format_size(){
while read -r B ; do
[ "${B}" -lt 1024 ] && echo "${B}" B && break
KB=$(((B+512)/1024))
[ "${KB}" -lt 1024 ] && echo "${KB}" KB && break
MB=$(((KB+512)/1024))
[ "${MB}" -lt 1024 ] && echo "${MB}" MB && break
GB=$(((MB+512)/1024))
[ "${GB}" -lt 1024 ] && echo "${GB}" GB && break
echo $(((GB+512)/1024)) TB
[ "${B}" -lt 1024 ] && echo "${B}" B && break
KB=$(((B+512)/1024))
[ "${KB}" -lt 1024 ] && echo "${KB}" KB && break
MB=$(((KB+512)/1024))
[ "${MB}" -lt 1024 ] && echo "${MB}" MB && break
GB=$(((MB+512)/1024))
[ "${GB}" -lt 1024 ] && echo "${GB}" GB && break
echo $(((GB+512)/1024)) TB
done
}

Expand All @@ -39,19 +39,19 @@ days_since(){
days=$(( seconds / 60 / 60 / 24 ))

echo "${days}"

}

format_days_ago() {

days=$1

if [ "${days}" -eq 0 ] ; then
echo 'less than one day ago'
echo 'less than one day ago'
elif [ "${days}" -eq 1 ] ; then
echo "${days} day ago"
echo "${days} day ago"
else
echo "${days} days ago"
echo "${days} days ago"
fi

}
Expand All @@ -67,16 +67,16 @@ format_timespan(){
seconds=$((input_in_seconds%60))

if [ "${days}" -gt 0 ]; then
[ "${days}" = 1 ] && printf "%d day " "${days}" || printf "%d days " "${days}"
[ "${days}" = 1 ] && printf "%d day " "${days}" || printf "%d days " "${days}"
fi
if [ "${hours}" -gt 0 ]; then
[ "${hours}" = 1 ] && printf "%d hour " "${hours}" || printf "%d hours " "${hours}"
[ "${hours}" = 1 ] && printf "%d hour " "${hours}" || printf "%d hours " "${hours}"
fi
if [ "${minutes}" -gt 0 ]; then
[ "${minutes}" = 1 ] && printf "%d minute " "${minutes}" || printf "%d minutes " "${minutes}"
[ "${minutes}" = 1 ] && printf "%d minute " "${minutes}" || printf "%d minutes " "${minutes}"
fi
if [ "${seconds}" -gt 0 ]; then
[ "${seconds}" = 1 ] && printf "%d second" "${seconds}" || printf "%d seconds" "${seconds}"
[ "${seconds}" = 1 ] && printf "%d second" "${seconds}" || printf "%d seconds" "${seconds}"
fi

}
Expand All @@ -89,11 +89,11 @@ printf "Backups %s\\n\\n" "$(hostname)"
if tmutil listbackups 2>&1 | grep -q 'No machine directory found for host.' ; then

if tmutil status 2>&1 | grep -q 'HealthCheckFsck' ; then

printf 'Time Machine: no information available (performing backup verification)\n'

else

printf 'Time Machine (offline):\n'
printf 'Oldest:\t\toffline\n'
printf 'Last:\t\toffline\n'
Expand All @@ -104,7 +104,7 @@ if tmutil listbackups 2>&1 | grep -q 'No machine directory found for host.' ; th
elif tmutil listbackups 2>&1 | grep -q 'No backups found for host.' ; then

printf 'Time Machine: no backups found\n'

else

tm_mount_point=$( tmutil destinationinfo | grep '^Mount\ Point' | sed 's/.*:\ //' )
Expand All @@ -118,17 +118,17 @@ else

latestbackup="$( tmutil latestbackup )"
if echo "${latestbackup}" | grep -q '[0-9]' ; then
# a date was returned (should implement a better test)
days=$( days_since "$( tmutil latestbackup | sed 's/.*\///' )" )
backup_date=$( tmutil latestbackup | sed 's/.*\///' | sed 's/-\([^\-]*\)$/\ \1/' | sed 's/\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/\1:\2:\3/')
printf 'Last:\t\t%s (%s)\n' "${backup_date}" "$( format_days_ago "${days}" )"
# a date was returned (should implement a better test)
days=$( days_since "$( tmutil latestbackup | sed 's/.*\///' )" )
backup_date=$( tmutil latestbackup | sed 's/.*\///' | sed 's/-\([^\-]*\)$/\ \1/' | sed 's/\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/\1:\2:\3/')
printf 'Last:\t\t%s (%s)\n' "${backup_date}" "$( format_days_ago "${days}" )"
else
printf 'Last:\t\t%s\n' "${latestbackup}"
printf 'Last:\t\t%s\n' "${latestbackup}"
fi

number=$( tmutil listbackups | wc -l | sed 's/\ //g' )
printf 'Number:\t\t%s\n' "${number}"

fi

echo
Expand Down Expand Up @@ -160,34 +160,34 @@ fi
status=$(tmutil status);

if echo "${status}" | grep -q 'BackupPhase' ; then

phase=$( echo "${status}" | grep BackupPhase | sed 's/.*\ =\ //' | sed 's/;.*//' )

case "${phase}" in
'ThinningPostBackup')
phase='Finished: thinning backups'
;;
'ThinningPreBackup')
phase='Starting: thinning backups'
;;
'DeletingOldBackups')
phase='Deleting old backups'
;;
'MountingBackupVol')
phase='Mounting backup volume'
;;
'FindingChanges')
phase='Finding changes'
;;
'SizingChanges')
phase='Sizing changes'
;;
'ThinningPostBackup')
phase='Finished: thinning backups'
;;
'ThinningPreBackup')
phase='Starting: thinning backups'
;;
'DeletingOldBackups')
phase='Deleting old backups'
;;
'MountingBackupVol')
phase='Mounting backup volume'
;;
'FindingChanges')
phase='Finding changes'
;;
'SizingChanges')
phase='Sizing changes'
;;
'HealthCheckFsck')
phase='Verifying backup'
;;
'PreparingSourceVolumes')
phase='Preparing source volumes'
;;
'PreparingSourceVolumes')
phase='Preparing source volumes'
;;
'MountingBackupVolForHealthCheck')
phase='Preparing verification'
;;
Expand All @@ -200,34 +200,33 @@ if echo "${status}" | grep -q 'BackupPhase' ; then
echo;

if echo "${status}" | grep -q Remaining ; then

secs=$(echo "${status}" | grep Remaining | sed 's/.*\ =\ //' | sed 's/;.*//');

# sometimes the remaining time is negative (?)
if ! echo "${secs}" | grep -q '^"-' ; then

now=$(date +'%s')
end=$(( now + secs ))
end_formatted=$( date -j -f '%s' "${end}" +'%Y-%m-%d %H:%M' )
duration=$( format_timespan "${secs}" )

if [ "$(date -j -f '%s' "${end}" +'%Y-%m-%d')" != "$(date +'%Y-%m-%d')" ] ; then
end_formatted=$( date -j -f '%s' "${end}" +'%Y-%m-%d %H:%M' )
else
end_formatted=$( date -j -f '%s' "${end}" +'%H:%M' )
fi

if [ "${secs}" -eq 0 ] ; then
printf 'Time remaining:\tunknown (finishing)\n'
else
printf 'Time remaining:\t%s (finish by %s)\n' "${duration}" "${end_formatted}"
fi


fi

secs=$(echo "${status}" | grep Remaining | sed 's/.*\ =\ //' | sed 's/;.*//');

# sometimes the remaining time is negative (?)
if ! echo "${secs}" | grep -q '^"-' ; then

now=$(date +'%s')
end=$(( now + secs ))
end_formatted=$( date -j -f '%s' "${end}" +'%Y-%m-%d %H:%M' )
duration=$( format_timespan "${secs}" )

if [ "$(date -j -f '%s' "${end}" +'%Y-%m-%d')" != "$(date +'%Y-%m-%d')" ] ; then
end_formatted=$( date -j -f '%s' "${end}" +'%Y-%m-%d %H:%M' )
else
end_formatted=$( date -j -f '%s' "${end}" +'%H:%M' )
fi

if [ "${secs}" -eq 0 ] ; then
printf 'Time remaining:\tunknown (finishing)\n'
else
printf 'Time remaining:\t%s (finish by %s)\n' "${duration}" "${end_formatted}"
fi

fi

fi

else

printf 'Status:\t\tStopped\n'
Expand All @@ -236,9 +235,9 @@ fi

if echo "${status}" | grep '_raw_Percent' | grep -q -v '[0-9]e-' ; then
if echo "${status}" | grep -q '_raw_Percent" = 1;' ; then
percent='100%'
percent='100%'
else
percent=$(echo "${status}" | grep '_raw_Percent" = "0' | sed 's/.*[.]//' | sed 's/\([0-9][0-9]\)\([0-9]\).*/\1.\2%/' | sed 's/^0//')
percent=$(echo "${status}" | grep '_raw_Percent" = "0' | sed 's/.*[.]//' | sed 's/\([0-9][0-9]\)\([0-9]\).*/\1.\2%/' | sed 's/^0//')
fi
printf 'Percent:\t%s\n' "${percent}";
fi
Expand All @@ -248,7 +247,15 @@ if echo "${status}" | grep -q 'totalBytes' ; then
size=$(echo "${status}" | grep 'bytes\ \=' | sed 's/.*bytes\ \=\ //' | sed 's/;.*//' | format_size)
printf 'Size:\t\t%s of %s\n' "${size}" "${total_size}";
fi


# Print verifying status
if echo "${status}" | grep -q -F HealthCheckFsck ; then
if echo "${status}" | grep -q -F 'Percent = "0' ; then
percent=$( echo "${status}" | grep 'Percent = ' | sed 's/.*Percent\ =\ \"0\.//' | sed 's/\".*//' )
printf 'Percent:\t%s%%\n' "${percent}";
fi
fi

echo

date
Expand Down

0 comments on commit f4fc394

Please sign in to comment.