-
Notifications
You must be signed in to change notification settings - Fork 23
/
check_backup.sh
executable file
·62 lines (54 loc) · 1.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
#!/usr/bin/env bash
#
# Quick and dirty script to check if backup failed, in log we trust.
#
# Usage: check_backup.sh [-l log]
# -l, --log LOG Path to backup log
# -h, --help Display this screen
#
# (c) 2014, Benjamin Dos Santos <[email protected]>
# https://github.com/bdossantos/nagios-plugins
#
while [[ -n "$1" ]]; do
case $1 in
-l | --log)
backup_log=$2
shift
;;
--help | -h)
sed -n '2,8p' "$0" | tr -d '#'
exit 3
;;
*)
echo "Unknown argument: $1"
exec "$0" --help
exit 3
;;
esac
shift
done
TODAY=$(date +"%Y/%m/%d")
YESTERDAY=$(date --date="yesterday" +"%Y/%m/%d")
if [[ -z $backup_log ]]; then
echo "CRITICAL - the path to backup log file is not defined"
exit 2
fi
if [[ ! -f $backup_log ]]; then
echo "CRITICAL - ${backup_log} does not exist !"
exit 2
fi
# Naive approch to check if backup job started today
if [[ -n "$(find "$backup_log" -type f -mtime +1 | head -n 1)" ]]; then
echo 'WARNING - The backup process seems to have not started today.'
exit 1
fi
if egrep "$TODAY|$YESTERDAY" "$backup_log" | grep -q -i 'error'; then
echo "CRITICAL - ${backup_log} contain error(s)"
exit 2
fi
if egrep "$TODAY|$YESTERDAY" "$backup_log" | grep -q -i 'warn'; then
echo "WARNING - ${backup_log} contain warning(s)"
exit 1
fi
echo "OK - ${backup_log} does not contain any error/warning"
exit 0