Skip to content
Snippets Groups Projects
Commit a57259d6 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

store backup status in status files ... do not grep frpom logs

parent a277fb26
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
# sConncectionDir="${sBackupBasedir}/_active" # sConncectionDir="${sBackupBasedir}/_active"
sConncectionDir="${sSelfdir}/_active_connections" sConncectionDir="${sSelfdir}/_active_connections"
# where to store last backup status
sStatusDir="${sSelfdir}/_last_backup"
# log # log
sLogdir="${sSelfdir}/log" sLogdir="${sSelfdir}/log"
sLogfile="$sLogdir/connections.log" sLogfile="$sLogdir/connections.log"
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# 2019-11-01 hahn write more clear log messages # 2019-11-01 hahn write more clear log messages
# 2021-06-xx hahn added setactive + setinactive # 2021-06-xx hahn added setactive + setinactive
# 2021-06-16 hahn added backupstatus # 2021-06-16 hahn added backupstatus
# 2021-06-18 hahn store backup status in status files ... do not grep frpom logs
# ====================================================================== # ======================================================================
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -119,16 +120,33 @@ ...@@ -119,16 +120,33 @@
# get timestamp of last backup start of a given server - see _getLoggedServers # get timestamp of last backup start of a given server - see _getLoggedServers
# param string servername as fqdn # param string servername as fqdn
function _getLastBackupstart(){ function _getLastBackupstart(){
local _srv=$1 test -r "${sStatusDir}/${sBackupClient}_start" && stat -c %Y "${sStatusDir}/${sBackupClient}_start"
_getAllLogs | sort | grep "\[$_srv\]" | grep ACCEPTED | tail -1 | cut -f -2 -d " " #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 # get timestamp of last backup end of a given server - see _getLoggedServers
# param string servername as fqdn # param string servername as fqdn
function _getLastBackupend(){ function _getLastBackupend(){
local _srv=$1 test -r "${sStatusDir}/${sBackupClient}_end" && stat -c %Y "${sStatusDir}/${sBackupClient}_end"
_getAllLogs | sort | grep "\[$_srv\]" | grep REMOVED | tail -1 | cut -f -2 -d " " # local _srv=$1
# _getAllLogs | sort | grep "\[$_srv\]" | grep REMOVED | tail -1 | cut -f -2 -d " "
} }
function _getLastBackupstatus(){
if [ -f "${sStatusDir}/${sBackupClient}_end" ]; then
cat "${sStatusDir}/${sBackupClient}_end"
else
echo "-1"
fi
}
function _isRunning(){
sTouchfile=`getConnFilename $sBackupClient`
test -f "$sTouchfile" && echo 1
test -f "$sTouchfile" || echo 0
}
# ------------------------------------------------------------ # ------------------------------------------------------------
# slot handling # slot handling
# ------------------------------------------------------------ # ------------------------------------------------------------
...@@ -153,7 +171,6 @@ ...@@ -153,7 +171,6 @@
# allow a slot for a new connection # allow a slot for a new connection
# see PUBLIC_register # see PUBLIC_register
function addConnection(){ function addConnection(){
# sBackupClient=$1
sTouchfile=`getConnFilename $sBackupClient` sTouchfile=`getConnFilename $sBackupClient`
if [ -f "$sTouchfile" ]; then if [ -f "$sTouchfile" ]; then
echo INFO: server [$sBackupClient] has a slot already echo INFO: server [$sBackupClient] has a slot already
...@@ -166,11 +183,12 @@ ...@@ -166,11 +183,12 @@
# remove slot of a connection # remove slot of a connection
# see PUBLIC_unregister # see PUBLIC_unregister
# param int backup status
function freeConnection(){ function freeConnection(){
# sBackupClient=$1
sTouchfile=`getConnFilename $sBackupClient` sTouchfile=`getConnFilename $sBackupClient`
if [ -f "$sTouchfile" ]; then if [ -f "$sTouchfile" ]; then
rm -f "$sTouchfile" mv "$sTouchfile" "$sStatusDir/${sBackupClient}_start"
echo $1 > "$sStatusDir/${sBackupClient}_end"
else else
echo INFO: server [$sBackupClient] had no reserved slot echo INFO: server [$sBackupClient] had no reserved slot
_addLog "IGNORE freeing the connection - [$sBackupClient] had no reserved slot" _addLog "IGNORE freeing the connection - [$sBackupClient] had no reserved slot"
...@@ -211,32 +229,43 @@ ...@@ -211,32 +229,43 @@
function PUBLIC_backupstatus(){ function PUBLIC_backupstatus(){
typeset -i local ierrors=0 typeset -i local ierrors=0
local tbl="%-45s | %-20s | %-20s | %-12s | %-10s \n" local tbl="%-45s | %-20s | %-20s | %8s | %3s | %5s \n"
printf "$tbl" "server" "start" "end" "duration [s]" "age [h]"
_showConnectionCount
echo "This table shows the time and duration [s] of the last backup for each server."
echo
printf "$tbl" " server" "start" "end" "duration" "rc" "age [h]"
echo "-------------------------------------------------------------------------------------------------------------------" echo "-------------------------------------------------------------------------------------------------------------------"
for myserver in $( _getLoggedServers ) for myserver in $( _getLoggedServers )
do do
# get data # get data
local tstart="$( _getLastBackupstart $myserver )" setBackupclient $myserver
local tend="$( _getLastBackupend $myserver )" typeset -i local istart="$( _getLastBackupstart )"
typeset -i local istart=$( date +%s -d "$tstart" ) typeset -i local iend="$( _getLastBackupend )"
typeset -i local iend=$( date +%s -d "$tend" )
typeset -i local bIsRunning=$( _isRunning )
typeset -i local iLastStatus=$( _getLastBackupstatus )
local tstart=$( date +"%Y-%m-%d %H:%M:%S" -d @${istart} )
local tend=$( date +"%Y-%m-%d %H:%M:%S" -d @${iend} )
typeset -i local iduration=$iend-$istart typeset -i local iduration=$iend-$istart
typeset -i local iage=$( date +%s )-$iend typeset -i local iage=$( date +%s )-$iend
typeset -i local iagehours=$iage/60/60 typeset -i local iagehours=$iage/60/60
# check values # check values
local statusAge=$(color ok)
if [ $iagehours -gt $iMaxbackupAge ]; then if [ $iagehours -gt $iMaxbackupAge ]; then
statusAge=$(color error)
ierrors=$ierrors+1 ierrors=$ierrors+1
fi fi
local sduration=$iduration local sduration=$iduration
test $iduration -lt 0 && sduration="RUNNING" test $iduration -lt 0 && sduration="RUNNING"
sStatusRun="."
test $iend -eq 0 && sStatusRun="?"
test $bIsRunning -eq 1 && sStatusRun="R"
# output # output
printf "$tbl" $myserver "$tstart" "${tend}" "${sduration}" "${statusAge}${iagehours}$(color reset)" printf "$tbl" "$sStatusRun $myserver" "${tstart}" "${tend}" "${sduration}" "$iLastStatus" "${iagehours}"
done done
echo echo
echo "total : $( _getLoggedServers | wc -l ) servers" echo "total : $( _getLoggedServers | wc -l ) servers"
...@@ -289,6 +318,7 @@ ...@@ -289,6 +318,7 @@
} }
# register a hostname to start backups # register a hostname to start backups
# param string FQDN
function PUBLIC_register(){ function PUBLIC_register(){
setBackupclient $1 setBackupclient $1
echo "REGISTER $1" echo "REGISTER $1"
...@@ -317,11 +347,14 @@ ...@@ -317,11 +347,14 @@
} }
# unregister a backup slot # unregister a backup slot
# param string FQDN
# param int optional: return code of the backup run
function PUBLIC_unregister(){ function PUBLIC_unregister(){
typeset -i local _status=$2
setBackupclient $1 setBackupclient $1
echo "UNREGISTER $1" echo "UNREGISTER $1"
echo echo
freeConnection freeConnection $_status
_addLog "REMOVED slot for [$sBackupClient]" _addLog "REMOVED slot for [$sBackupClient]"
_showConnectionCount _showConnectionCount
exit 0 exit 0
...@@ -409,6 +442,9 @@ ...@@ -409,6 +442,9 @@
if [ ! -d "$sConncectionDir" ]; then if [ ! -d "$sConncectionDir" ]; then
mkdir -p "$sConncectionDir" || exit 1 mkdir -p "$sConncectionDir" || exit 1
fi fi
if [ ! -d "$sStatusDir" ]; then
mkdir -p "$sStatusDir" || exit 1
fi
color head color head
echo echo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment