From fd2eaba6ce8b867012b6b0c9b6c235080e1f216d Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 7 Mar 2018 11:16:25 +0100 Subject: [PATCH] Format time deltas in a readable way instead of in seconds --- .../backup_server/postgres-make-base-backups.erb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/postgres/templates/backup_server/postgres-make-base-backups.erb b/modules/postgres/templates/backup_server/postgres-make-base-backups.erb index 18046bbb9..c60a541b9 100755 --- a/modules/postgres/templates/backup_server/postgres-make-base-backups.erb +++ b/modules/postgres/templates/backup_server/postgres-make-base-backups.erb @@ -55,6 +55,14 @@ log() { [ "$verbose" -gt 0 ] && echo "$*" logger -p daemon.info -t "$SELF" "$*" } +format_timedelta() { + local secs="$1"; shift + if [ "$secs" -ge 86400 ]; then + printf '%dd %02d:%02d:%02d\n' $(($secs/3600/24)) $(($secs/3600%24)) $(($secs/60%60)) $(($secs%60)) + else + printf '%02d:%02d:%02d\n' $(($secs/3600)) $(($secs/60%60)) $(($secs%60)) + fi +} if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then @@ -104,7 +112,7 @@ while read host port username cluster version; do delta=$(( now - mtime )) if [ "$delta" -lt "$MIN_WAIT" ]; then runme=0 - log "Skipping $host:$port $version/$cluster because last attempt was only ${delta}s ago." + log "Skipping $host:$port $version/$cluster because last attempt was only $(format_timedelta "${delta}") ago." else if ! [ -e "$flagfilesuccess" ]; then runme=1 @@ -114,10 +122,10 @@ while read host port username cluster version; do delta=$(( now - mtime )) if [ "$delta" -lt "$MIN_WAIT_SUCCESS" ]; then runme=0 - log "Skipping $host:$port $version/$cluster because last success was only ${delta}s ago." + log "Skipping $host:$port $version/$cluster because last success was only $(format_timedelta "${delta}") ago." elif [ "$delta" -gt "$MAX_WAIT_SUCCESS" ]; then runme=1 - log "Planning to run $host:$port $version/$cluster because last success was ${delta}s ago." + log "Planning to run $host:$port $version/$cluster because last success was $(format_timedelta "${delta}") ago." else # get a "randomish" but stable value for this backup run val=$(echo "$MYHOSTNAME-$host-$port-$mtime" | sha256sum | head -c 8) -- 2.20.1