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

backup status: check age of restic backups when not using ssh

parent 70055581
No related branches found
No related tags found
1 merge request!7backup status: check age of restic backups when not using ssh
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
......@@ -33,6 +33,7 @@
# 2021-01-22 hahn show inactive backups in status page; colored lines by status
# 2021-11-12 hahn backup status: add handling for backup exitcode
# 2022-07-06 hahn backup status: show clear message on not started/ deleted backups
# 2024-03-22 hahn backup status: check age of restic backups when not using ssh
# ======================================================================
# ----------------------------------------------------------------------
......@@ -124,7 +125,7 @@
# get content of all logfiles
function _getAllLogs(){
zcat $sLogdir/*.gz ; cat $sLogfile
ls $sLogdir/*.gz >/dev/null 2>&1 && ( zcat $sLogdir/*.gz ; cat $sLogfile )
}
# get a list of all servers in the log
......@@ -184,7 +185,7 @@
test -f "$sTouchfile" && echo 1
test -f "$sTouchfile" || echo 0
}
# check if a backup for current server is running
# check if a backup for current server is inactive
# it returns 0 for no and 1 for yes
# global string sBackupClient FQDN of current server
# global string sBackupBasedir backup directory
......@@ -197,6 +198,14 @@
fi
}
# get age of a file in sec
# param string filename to test
#
function _getFileAge(){
echo $(($(date +%s) - $(date +%s -r "$1")))
}
# ------------------------------------------------------------
# slot handling
# ------------------------------------------------------------
......@@ -292,11 +301,68 @@
function PUBLIC_backupstatus(){
typeset -i local ierrors=0
local tbl="%s %-45s | %-20s | %-20s | %8s | %3s | %7s | %s \n"
local ierrors; typeset -i ierrors=0
local tbl
# _showConnectionCount
echo
if ! _getLoggedServers | grep -qc . ; then
iKeepBackups=180
local iAgeH; typeset -i iAgeH
local iAgeD; typeset -i iAgeD
local sAge
local mydir
local bIsInactive; typeset -i bIsInactive
local iCounter; typeset -i iCounter=0
echo "Age of Restic backup repositories"
for myresticsnapshotdir in $( ls -1trd ${sBackupBasedir}/*/*/snapshots )
do
iCounter=$iCounter+1
mydir=$( dirname "${myresticsnapshotdir}")
sBackupClient=$( basename ${mydir} )
iAgeH=$( _getFileAge "${myresticsnapshotdir}" )/60/60
iAgeD=iAgeH/24
bIsInactive=$( _isInactive )
sMore=
sStatus="$(color ok)."
test $bIsInactive -eq 1 && sStatus="$(color disabled)D"
sFile=${mydir}/inactive.txt
if [ "$bIsInactive" -eq "1" ]; then
typeset -i iAge=`_getFileAge "$sFile"`
typeset -i iDays=$iKeepBackups-$iAge/60/60/24
sMore=" - INFO: keeping it $iKeepBackups d .. $iDays d left."
if [ "$iDays" -lt 0 ]; then
sMore=" - DELETE: overdued $iDays d."
sStatus="$(color error)E"
ierrors=$ierrors+1
fi
elif [ $iAgeH -ge 24 ]; then
sStatus="$(color error)E"
ierrors=$ierrors+1
_showConnectionCount
fi
sAge="$iAgeH h"
if [ $iAgeH -gt 96 ]; then
sAge="$iAgeD d"
fi
printf "%2s %7s %s\n" "$sStatus" "$sAge" "${mydir}$sMore"
done
color reset
echo
echo "Legend"
echo ". OK | D disabled | E error"
echo
echo "total : $iCounter servers"
echo "errors: $ierrors"
echo
else
tbl="%s %-45s | %-20s | %-20s | %8s | %3s | %7s | %s \n"
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]" "size"
......@@ -355,6 +421,7 @@
echo "total : $( _getLoggedServers | wc -l ) servers"
echo "errors: $ierrors"
echo
fi
echo "rc=$ierrors"
exit $ierrors
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment