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

use single status file; added backup size

parent a57259d6
No related branches found
No related tags found
No related merge requests found
...@@ -6,13 +6,17 @@ ...@@ -6,13 +6,17 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# #
# SYNTAX: # SYNTAX:
# storage_helper.sh PARAMETERS
#
# PARAMETERS:
#
# register [hostname] # register [hostname]
# init backup for hostname; backup client must interrupt/ repeat # init backup for hostname; backup client must interrupt/ repeat
# return code is <> 0 # return code is <> 0
# #
# unregister [hostname] # unregister [hostname] [statuscode]
# send info that a backup was done to delete the connection flag # send info that a backup was done to delete the connection flag
# for the given host # for the given host.
# #
# status # status
# show current connections # show current connections
...@@ -25,6 +29,7 @@ ...@@ -25,6 +29,7 @@
# 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 # 2021-06-18 hahn store backup status in status files ... do not grep frpom logs
# 2021-06-21 hahn use single status file; added backup size
# ====================================================================== # ======================================================================
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -43,6 +48,7 @@ ...@@ -43,6 +48,7 @@
# max age of last backup in h # max age of last backup in h
iMaxbackupAge=36 iMaxbackupAge=36
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -117,29 +123,48 @@ ...@@ -117,29 +123,48 @@
_getAllLogs | cut -f 2 -d '[' | cut -f 1 -d ']' | sort -u _getAllLogs | cut -f 2 -d '[' | cut -f 1 -d ']' | sort -u
} }
# get timestamp of last backup start of a given server - see _getLoggedServers # get timestamp of last backup start of a given server
# param string servername as fqdn # global string sBackupClient FQDN of current server
function _getLastBackupstart(){ function _getLastBackupstart(){
test -r "${sStatusDir}/${sBackupClient}_start" && stat -c %Y "${sStatusDir}/${sBackupClient}_start" #test -r "${sStatusDir}/${sBackupClient}_start" && stat -c %Y "${sStatusDir}/${sBackupClient}_start"
#echo $tsBackupStart
#local _srv=$1 #local _srv=$1
#_getAllLogs | sort | grep "\[$_srv\]" | grep ACCEPTED | tail -1 | cut -f -2 -d " " #_getAllLogs | sort | grep "\[$_srv\]" | grep ACCEPTED | tail -1 | cut -f -2 -d " "
test -r "$sStatusDir/${sBackupClient}" && . "$sStatusDir/${sBackupClient}"
echo $tsBackupStart
} }
# get timestamp of last backup end of a given server - see _getLoggedServers # get timestamp of last backup end of a given server
# param string servername as fqdn # global string sBackupClient FQDN of current server
function _getLastBackupend(){ function _getLastBackupend(){
test -r "${sStatusDir}/${sBackupClient}_end" && stat -c %Y "${sStatusDir}/${sBackupClient}_end" # test -r "${sStatusDir}/${sBackupClient}_end" && stat -c %Y "${sStatusDir}/${sBackupClient}_end"
# local _srv=$1 # local _srv=$1
# _getAllLogs | sort | grep "\[$_srv\]" | grep REMOVED | tail -1 | cut -f -2 -d " " # _getAllLogs | sort | grep "\[$_srv\]" | grep REMOVED | tail -1 | cut -f -2 -d " "
test -r "$sStatusDir/${sBackupClient}" && . "$sStatusDir/${sBackupClient}"
echo $tsBackupEnd
} }
# get status code of last backup from status file
# global string sBackupClient FQDN of current server
function _getLastBackupstatus(){ function _getLastBackupstatus(){
if [ -f "${sStatusDir}/${sBackupClient}_end" ]; then if [ -r "${sStatusDir}/${sBackupClient}" ]; then
cat "${sStatusDir}/${sBackupClient}_end" . "${sStatusDir}/${sBackupClient}"
echo $backupRc
else else
echo "-1" echo "-2"
fi fi
} }
# get size of backup data from status file
# global string sBackupClient FQDN of current server
function _getBackupsize(){
test -r "$sStatusDir/${sBackupClient}" && . "$sStatusDir/${sBackupClient}"
echo $size
}
# check if a backup for current server is running
# it returns 0 for no and 1 for yes
# global string sBackupClient FQDN of current server
function _isRunning(){ function _isRunning(){
sTouchfile=`getConnFilename $sBackupClient` sTouchfile=`getConnFilename $sBackupClient`
test -f "$sTouchfile" && echo 1 test -f "$sTouchfile" && echo 1
...@@ -177,6 +202,9 @@ ...@@ -177,6 +202,9 @@
_addLog "IGNORE request for a slot - [$sBackupClient] has a slot already" _addLog "IGNORE request for a slot - [$sBackupClient] has a slot already"
else else
touch "$sTouchfile" touch "$sTouchfile"
echo "client='$sBackupClient'" > "$sTouchfile"
echo "# $( date """+%Y-%m-%d %H:%M:%S""" )" >> "$sTouchfile"
echo "tsBackupStart=$( date +%s )" >> "$sTouchfile"
_addLog "REQUEST a slot for server [$sBackupClient]" _addLog "REQUEST a slot for server [$sBackupClient]"
fi fi
} }
...@@ -185,10 +213,15 @@ ...@@ -185,10 +213,15 @@
# see PUBLIC_unregister # see PUBLIC_unregister
# param int backup status # param int backup status
function freeConnection(){ function freeConnection(){
local _status=$1
test -z "$1" && _status=-1
sTouchfile=`getConnFilename $sBackupClient` sTouchfile=`getConnFilename $sBackupClient`
if [ -f "$sTouchfile" ]; then if [ -f "$sTouchfile" ]; then
mv "$sTouchfile" "$sStatusDir/${sBackupClient}_start" echo "# $( date """+%Y-%m-%d %H:%M:%S""" )" >> "$sTouchfile"
echo $1 > "$sStatusDir/${sBackupClient}_end" echo "tsBackupEnd=$( date +%s )" >> "$sTouchfile"
echo "backupRc=$_status" >> "$sTouchfile"
echo "size=$( du -hs ${sBackupBasedir}/*/$sBackupClient 2>/dev/null )" >> "$sTouchfile"
mv "$sTouchfile" "$sStatusDir/${sBackupClient}"
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"
...@@ -209,6 +242,11 @@ ...@@ -209,6 +242,11 @@
echo ERROR: no backup client was given echo ERROR: no backup client was given
exit 1 exit 1
fi fi
# read last backup status
typeset -i tsBackupStart=0
typeset -i tsBackupEnd=0
typeset -i backupRc=-2
# test -r "$sStatusDir/${sBackupClient}" && . "$sStatusDir/${sBackupClient}"
} }
function _listRepodirs(){ function _listRepodirs(){
...@@ -229,27 +267,28 @@ ...@@ -229,27 +267,28 @@
function PUBLIC_backupstatus(){ function PUBLIC_backupstatus(){
typeset -i local ierrors=0 typeset -i local ierrors=0
local tbl="%-45s | %-20s | %-20s | %8s | %3s | %5s \n" local tbl="%-45s | %-20s | %-20s | %8s | %3s | %7s | %s \n"
_showConnectionCount _showConnectionCount
echo
echo "This table shows the time and duration [s] of the last backup for each server." echo "This table shows the time and duration [s] of the last backup for each server."
echo echo
printf "$tbl" " server" "start" "end" "duration" "rc" "age [h]" printf "$tbl" " server" "start" "end" "duration" "rc" "age [h]" "size"
echo "-------------------------------------------------------------------------------------------------------------------" echo "-----------------------------------------------------------------------------------------------------------------------------"
for myserver in $( _getLoggedServers ) for myserver in $( _getLoggedServers )
do do
# get data # get data
setBackupclient $myserver setBackupclient $myserver
typeset -i local istart="$( _getLastBackupstart )" typeset -i local istart="$( _getLastBackupstart )"
typeset -i local iend="$( _getLastBackupend )" typeset -i local iend="$( _getLastBackupend )"
typeset -i local bIsRunning=$( _isRunning ) typeset -i local bIsRunning=$( _isRunning )
typeset -i local iLastStatus=$( _getLastBackupstatus ) typeset -i local iLastStatus=$( _getLastBackupstatus )
size=$( _getBackupsize )
local tstart=$( date +"%Y-%m-%d %H:%M:%S" -d @${istart} ) local tstart=$( date +"%Y-%m-%d %H:%M:%S" -d @${istart} )
local tend=$( date +"%Y-%m-%d %H:%M:%S" -d @${iend} ) 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
...@@ -261,11 +300,11 @@ ...@@ -261,11 +300,11 @@
test $iduration -lt 0 && sduration="RUNNING" test $iduration -lt 0 && sduration="RUNNING"
sStatusRun="." sStatusRun="."
test $iend -eq 0 && sStatusRun="?" test $iend -eq 0 && sStatusRun="?"
test $bIsRunning -eq 1 && sStatusRun="R" test $bIsRunning -eq 1 && sStatusRun="R"
# output # output
printf "$tbl" "$sStatusRun $myserver" "${tstart}" "${tend}" "${sduration}" "$iLastStatus" "${iagehours}" printf "$tbl" "$sStatusRun $myserver" "${tstart}" "${tend}" "${sduration}" "$iLastStatus" "${iagehours}" "$size"
done done
echo echo
echo "total : $( _getLoggedServers | wc -l ) servers" echo "total : $( _getLoggedServers | wc -l ) servers"
...@@ -300,9 +339,9 @@ ...@@ -300,9 +339,9 @@
echo -n "Repo to deactivate >" echo -n "Repo to deactivate >"
read inputdir read inputdir
if [ -d "$inputdir" -a ! -f "$inputdir/inactive.txt" ]; then if [ -d "$inputdir" -a ! -f "$inputdir/inactive.txt" ]; then
echo -n "Short message >" echo -n "Optional short message >"
read mymessage read mymessage
echo "$( date ) | $mymessage" >"$inputdir/inactive.txt" echo "$( date ) | $mymessage" > "$inputdir/inactive.txt"
ls -l "$inputdir/inactive.txt" ls -l "$inputdir/inactive.txt"
else else
echo SKIP [$inputdir] echo SKIP [$inputdir]
...@@ -463,8 +502,12 @@ ...@@ -463,8 +502,12 @@
echo " backupstatus" echo " backupstatus"
echo " show all servers and their backup times" echo " show all servers and their backup times"
echo echo
echo " register | unregister [hostname]" echo " register [hostname]"
echo " add/ remove slot for a backup client" echo " add a slot for a backup client"
echo
echo " unregister [hostname] [statuscode]"
echo " remove slot for a backup client."
echo " The statuscode is an integer of the return code."
echo echo
echo " setactive" echo " setactive"
echo " Reactivate an inctave backup repo." echo " Reactivate an inctave backup repo."
...@@ -477,7 +520,7 @@ ...@@ -477,7 +520,7 @@
echo " status" echo " status"
echo " show current reserved slots" echo " show current reserved slots"
echo echo
echo " usage [full|[filter to hostname]]" echo " usage [full|[filter to hostname]] - DEPRECATED"
echo " show used diskspace" echo " show used diskspace"
echo " you can set a string to show additionally details if these hosts" echo " you can set a string to show additionally details if these hosts"
echo " if you add \"full\" then details of all hosts will be shown" echo " if you add \"full\" then details of all hosts will be shown"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment