Skip to content
Snippets Groups Projects
check_clientbackup 3.80 KiB
#!/bin/bash
# ======================================================================
#
# NAGIOS CLIENT CHECK :: check client backup
#
# ----------------------------------------------------------------------
# 2016-12-09  v1.0  first lines
# 2016-12-23  v1.1  added readable exitcode from shared functions file
# 2020-03-05  v1.2  <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-04-04  v1.3  <axel.hahn@iml.unibe.ch> set status unknown if never executed
# 2022-02-17  v1.4  <axel.hahn@iml.unibe.ch> no tmpfile; show more output to see backed up dirs
# 2022-03-07  v1.5  <axel.hahn@iml.unibe.ch> update scan for results in transfer
# 2022-03-18  v1.6  <axel.hahn@iml.unibe.ch> show dumped databases
# 2022-03-21  v1.7  <axel.hahn@iml.unibe.ch> show databases infos for couchdb2 too
# 2022-03-23  v1.8  <axel.hahn@iml.unibe.ch> FIX: exit with error if backup error occured
# 2022-08-10  v1.9  <axel.hahn@iml.unibe.ch> FIX: mask the dot in .log
# 2022-10-21  v1.10 <axel.hahn@unibe.ch>     remove grep: warning: stray \ before white space
#                                            show last backup, prune, verify
# 2023-06-22  v1.11  <axel.hahn@unibe.ch>    add help and param support; add parameter for install directory
# 2023-07-27  v1.12  <axel.hahn@unibe.ch>    add docs url of IML backup
# 2023-09-01  v1.13  <axel.hahn@unibe.ch>    add changecounters and performancedata
# ======================================================================

. $( dirname $0 )/inc_pluginfunctions

export self_APPVERSION=1.13

sInstalldir=/opt/imlbackup/client/

# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------

function showHelp(){
    local _self; _self=$(basename $0)
    cat <<EOF
$( ph.showImlHelpHeader )

Show status of IML backup.
See https://os-docs.iml.unibe.ch/iml-backup/

It returns with state UNKNOWN if no backup has been performed yet.
It switches to ERROR an error occured during backup process.

SYNTAX:
$_self [-d DIRECTORY]

OPTIONS:
    -h or --help   show this help.
    -d or --dir    set installation dir of iml backup to find its check skript
                   default: /opt/imlbackup/client/

EXAMPLE:
$_self -d /home/backup/imlbackup
                   set a custom directory und run the backup check

EOF
}

# --- check param -h
while [[ "$#" -gt 0 ]]; do case $1 in
    -h|--help)      showHelp; exit 0;;
    -d|--dir)       sInstalldir=$2; shift ;shift;;
    *) echo "ERROR: Unknown parameter: $1"; showHelp; exit 1;
esac; done

sChecker=$sInstalldir/check_clientbackup.sh

if [ ! -x $sChecker ]; then
  ph.abort "$sChecker not found - maybe clientbackup is not installed here. Use param -d to set the install directory."
fi

result=$( $sChecker )
rc=$?

# remove ascii colors
result=${result//\[[0-9]m/ }
result=${result//\[[0-9][0-9]m/ }

if [ $rc -eq 0 ]; then
  ph.setStatus "ok"
else
  if echo "$result" | grep "Backup was never executed" 2>/dev/null  
  then
    ph.setStatus "unknown"
  else
    ph.setStatus "critical"
  fi
fi

ph.status
echo "$result" | grep -F "MONITORINFO:" | cut -f 2- -d ':'
echo

# show lines __DB__ of backed up databases and skip al database types
# that do not have a line "__DB__[type] backup"
for dbtype in $( echo "$result" | grep -o '__DB__[a-z][a-z0-9]*' | sort -u )
do
        echo "$result" | grep "$dbtype backup" >/dev/null \
                && echo --- local dumps "${dbtype//__DB__/}" \
                && echo "$result" | grep "$dbtype" | grep -v "\.log" \
                && echo
done

echo "--- transfer:"
echo "$result" | grep "__[A-Z][A-Z]*__ " | grep -v "__PERFDATA__"
echo
echo "$result" | grep "__COUNTERS__"
echo
echo "$result" | grep "__LAST__"
echo
echo "$result" | grep "__PERFDATA__" | cut -f 2- -d " "

ph.exit

# ----------------------------------------------------------------------