diff --git a/storage_helper.sh b/storage_helper.sh index dc1e71d18189d01ce0068f59517a59b722156098..a0f853fc8c36b97f90f47504727986a7d9201461 100755 --- a/storage_helper.sh +++ b/storage_helper.sh @@ -22,6 +22,8 @@ # # ---------------------------------------------------------------------- # 2019-11-01 hahn write more clear log messages +# 2021-06-xx hahn added setactive + setinactive +# 2021-06-16 hahn added backupstatus # ====================================================================== # ---------------------------------------------------------------------- @@ -37,17 +39,13 @@ # value is set in _showConnectionCount iConnections=0 + # max age of last backup in h + iMaxbackupAge=36 # ---------------------------------------------------------------------- # FUNCTIONS # ---------------------------------------------------------------------- - # add a line into logfile - # param string message (date will be added as prefix) - function _addLog(){ - # echo `date` $* >>${sLogDir}${sLogfile} - echo `date "+%Y-%m-%d %H:%M:%S"` $* >>${sLogfile} - } # ------------------------------------------------------------ # color text @@ -98,6 +96,42 @@ fi } + # ------------------------------------------------------------ + # logging + # ------------------------------------------------------------ + # add a line into logfile + # param string message (date will be added as prefix) + function _addLog(){ + # echo `date` $* >>${sLogDir}${sLogfile} + echo `date "+%Y-%m-%d %H:%M:%S"` $* >>${sLogfile} + } + + # get content of all logfiles + function _getAllLogs(){ + zcat $sLogdir/*.gz ; cat $sLogfile + } + + # get a list of all servers in the log + function _getLoggedServers(){ + _getAllLogs | cut -f 2 -d '[' | cut -f 1 -d ']' | sort -u + } + + # get timestamp of last backup start of a given server - see _getLoggedServers + # param string servername as fqdn + function _getLastBackupstart(){ + local _srv=$1 + _getAllLogs | sort | grep "\[$_srv\]" | grep ACCEPTED | tail -1 | cut -f -2 -d " " + } + + # get timestamp of last backup end of a given server - see _getLoggedServers + # param string servername as fqdn + function _getLastBackupend(){ + local _srv=$1 + _getAllLogs | sort | grep "\[$_srv\]" | grep REMOVED | tail -1 | cut -f -2 -d " " + } + # ------------------------------------------------------------ + # slot handling + # ------------------------------------------------------------ # show current connction count function _showConnectionCount(){ @@ -109,6 +143,7 @@ echo STATUS: $iConnections existing connection\(s\). Allowed maximum is $sMax. } + # helper: get filename for backup client connection function getConnFilename(){ # sBackupClient=$1 @@ -174,6 +209,43 @@ # ---------------------------------------------------------------------- + function PUBLIC_backupstatus(){ + typeset -i local ierrors=0 + local tbl="%-45s | %-20s | %-20s | %-12s | %-10s \n" + printf "$tbl" "server" "start" "end" "duration [s]" "age [h]" + echo "--------------------------------------------------------------------------------------------------------------" + for myserver in $( _getLoggedServers ) + do + # get data + local tstart="$( _getLastBackupstart $myserver )" + local tend="$( _getLastBackupend $myserver )" + typeset -i local istart=$( date +%s -d "$tstart" ) + typeset -i local iend=$( date +%s -d "$tend" ) + typeset -i local iduration=$iend-$istart + typeset -i local iage=$( date +%s )-$iend + typeset -i local iagehours=$iage/60/60 + + # check values + local statusAge=$(color ok) + if [ $iagehours -gt $iMaxbackupAge ]; then + statusAge=$(color error) + ierrors=$ierrors+1 + fi + + local sduration=$iduration + test $iduration -lt 0 && sduration="RUNNING" + + # output + printf "$tbl" $myserver "$tstart" "${tend}" "${sduration}" "${iagehours}" + done + echo + echo "total : $( _getLoggedServers ) servers" + echo "errors: $ierrors" + echo + echo "rc=$ierrors" + exit $ierrors + } + function PUBLIC_setactive(){ echo --- list of inactive backup repositories _listRepodirs | grep '\(inactive\)' @@ -338,8 +410,6 @@ mkdir -p "$sConncectionDir" || exit 1 fi - - color head echo echo "---------- :: STORAGE :: `hostname` :: ----------" @@ -354,6 +424,9 @@ echo SYNTAX: echo "`basename $0` [function]" echo + echo " backupstatus" + echo " show all servers and their backup times" + echo echo " register | unregister [hostname]" echo " add/ remove slot for a backup client" echo