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 @@
# sConncectionDir="${sBackupBasedir}/_active"
sConncectionDir="${sSelfdir}/_active_connections"
# where to store last backup status
sStatusDir="${sSelfdir}/_last_backup"
# log
sLogdir="${sSelfdir}/log"
sLogfile="$sLogdir/connections.log"
......
......@@ -24,6 +24,7 @@
# 2019-11-01 hahn write more clear log messages
# 2021-06-xx hahn added setactive + setinactive
# 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 @@
# 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 " "
test -r "${sStatusDir}/${sBackupClient}_start" && stat -c %Y "${sStatusDir}/${sBackupClient}_start"
#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 " "
test -r "${sStatusDir}/${sBackupClient}_end" && stat -c %Y "${sStatusDir}/${sBackupClient}_end"
# 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
# ------------------------------------------------------------
......@@ -153,7 +171,6 @@
# allow a slot for a new connection
# see PUBLIC_register
function addConnection(){
# sBackupClient=$1
sTouchfile=`getConnFilename $sBackupClient`
if [ -f "$sTouchfile" ]; then
echo INFO: server [$sBackupClient] has a slot already
......@@ -166,11 +183,12 @@
# remove slot of a connection
# see PUBLIC_unregister
# param int backup status
function freeConnection(){
# sBackupClient=$1
sTouchfile=`getConnFilename $sBackupClient`
if [ -f "$sTouchfile" ]; then
rm -f "$sTouchfile"
mv "$sTouchfile" "$sStatusDir/${sBackupClient}_start"
echo $1 > "$sStatusDir/${sBackupClient}_end"
else
echo INFO: server [$sBackupClient] had no reserved slot
_addLog "IGNORE freeing the connection - [$sBackupClient] had no reserved slot"
......@@ -211,32 +229,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]"
local tbl="%-45s | %-20s | %-20s | %8s | %3s | %5s \n"
_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 "-------------------------------------------------------------------------------------------------------------------"
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" )
setBackupclient $myserver
typeset -i local istart="$( _getLastBackupstart )"
typeset -i local iend="$( _getLastBackupend )"
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 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"
sStatusRun="."
test $iend -eq 0 && sStatusRun="?"
test $bIsRunning -eq 1 && sStatusRun="R"
# output
printf "$tbl" $myserver "$tstart" "${tend}" "${sduration}" "${statusAge}${iagehours}$(color reset)"
printf "$tbl" "$sStatusRun $myserver" "${tstart}" "${tend}" "${sduration}" "$iLastStatus" "${iagehours}"
done
echo
echo "total : $( _getLoggedServers | wc -l ) servers"
......@@ -289,6 +318,7 @@
}
# register a hostname to start backups
# param string FQDN
function PUBLIC_register(){
setBackupclient $1
echo "REGISTER $1"
......@@ -317,11 +347,14 @@
}
# unregister a backup slot
# param string FQDN
# param int optional: return code of the backup run
function PUBLIC_unregister(){
typeset -i local _status=$2
setBackupclient $1
echo "UNREGISTER $1"
echo
freeConnection
freeConnection $_status
_addLog "REMOVED slot for [$sBackupClient]"
_showConnectionCount
exit 0
......@@ -409,6 +442,9 @@
if [ ! -d "$sConncectionDir" ]; then
mkdir -p "$sConncectionDir" || exit 1
fi
if [ ! -d "$sStatusDir" ]; then
mkdir -p "$sStatusDir" || exit 1
fi
color head
echo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment