-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_backup.sh
executable file
·97 lines (75 loc) · 2.38 KB
/
check_backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#
# Copyright 2009-2017 Martin Scharm
#
# This file is part of bf-monitoring.
# <https://binfalse.de/software/nagios/>
# <https://github.com/binfalse/monitoring>
#
# bf-monitoring is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# bf-monitoring is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# bf-monitoring If not, see <http://www.gnu.org/licenses/>.
#
###################################
#
# Check if there are pending Backups
# written by Martin Scharm
# see http://binfalse.de
#
# tested with v8.60
#
###################################
source /usr/lib/nagios/plugins/utils.sh
#############
# ARGUMENTS:
#############
# maximum number of stored backups, if this value is exceeded we'll warn
MAX=${1}
#############
# CONFIG:
#############
# please take care of paths!!
# where are backups located
BACKUPDIR=/var/backups/sysbackups
# error log file
ERRLOG=${BACKUPDIR}/backup.err
################################################################################
# thats it... don't change anything below unless you know what you're doing... #
################################################################################
PENDING=$(/bin/ls ${BACKUPDIR} | /bin/grep snapshot | /usr/bin/wc -l)
ERRORS=0
crit=""
warn=""
if [ -f ${ERRLOG} ]
then
ERRORS=$(/bin/cat ${ERRLOG} | /bin/grep -v "tar: Removing leading" | /usr/bin/wc -l)
else
warn="${warn} error log not present. path correct?"
fi
if [ ${MAX} -lt ${PENDING} ]; then
crit="${crit} please download and clean up!"
fi
if [ ${ERRORS} -gt 0 ]
then
crit="${crit} please deal with errors!"
fi
if [ -n "${crit}" ]
then
echo "${PENDING} backups pending... ${ERRORS} errors! ${crit} ${warn}"
exit ${STATE_CRITICAL}
fi
if [ -n "${warn}" ]
then
echo "${PENDING} backups pending... ${ERRORS} errors! ${crit} ${warn}"
exit ${STATE_WARNING}
fi
echo "${PENDING} backups pending... ${ERRORS} errors. that's ok..."
exit ${STATE_OK}