Skip to content

Commit

Permalink
Warn if --today is speficied and the time machine is offline
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocorti committed Mar 24, 2023
1 parent 7828139 commit b71bbb6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023-03-24 Matteo Corti <[email protected]>

* tmstatus.sh (status): Warn if --today is speficied and the time machine is offline

2023-03-20 Matteo Corti <[email protected]>

* tmstatus.sh (status): Number of backups today
Expand Down
41 changes: 26 additions & 15 deletions tmstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ EOF
printf 'Last:\t\toffline\n'
printf 'Number:\t\toffline\n'

OFFLINE=1

fi

elif echo "${LISTBACKUPS}" | grep -q 'No backups found for host.'; then
Expand Down Expand Up @@ -391,25 +393,34 @@ fi

if [ -n "${TODAY}" ] ; then

echo
if [ -z "${OFFLINE}" ] ; then

echo

TODAYS_DATE="$( date +"%Y-%m-%d" )"
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/' )

TODAYS_DATE="$( date +"%Y-%m-%d" )"
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/' )
# without the grep ':' there is always one line (empty)
NUMBER_OF_TODAYS_BACKUPS=$( echo "${TODAYS_BACKUPS}" | grep -c ':' | sed 's/[ ]//g' )

# without the grep ':' there is always one line (empty)
NUMBER_OF_TODAYS_BACKUPS=$( echo "${TODAYS_BACKUPS}" | grep -c ':' | sed 's/[ ]//g' )

if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 0 ] ; then
echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE})"
else
if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 1 ] ; then
echo "${NUMBER_OF_TODAYS_BACKUPS} backup today (${TODAYS_DATE}) at"
else
echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE}) at"
fi
echo "${TODAYS_BACKUPS}" | sed 's/^/ * /'
fi

if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 0 ] ; then
echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE})"
else
if [ "${NUMBER_OF_TODAYS_BACKUPS}" -eq 1 ] ; then
echo "${NUMBER_OF_TODAYS_BACKUPS} backup today (${TODAYS_DATE}) at"
else
echo "${NUMBER_OF_TODAYS_BACKUPS} backups today (${TODAYS_DATE}) at"
fi
echo "${TODAYS_BACKUPS}" | sed 's/^/ * /'
fi
else

echo
echo "Time Machine offline: cannot list todays' backups"

fi

fi

Expand Down

0 comments on commit b71bbb6

Please sign in to comment.