-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_backup.sh
executable file
·41 lines (33 loc) · 1.51 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
#!/bin/bash
# Copyright (C) 2018 by Tomas Herceg <[email protected]>
# Released under GNU GPL 3 or later
# This script can be used as nagios/icinga check script
# we need this hack to properly handle spaces and symlinks.
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
source $SCRIPTPATH/config.sh
host=${1:-localhost}
time=${2:-1440}
last_snap=$(ls ${MOUNT_DIR}/${host}/.zfs/snapshot/ |tail -n 1)
running_rsyncs=$(ps aux|grep [r]sync | fgrep $host|wc -l)
used=$(zfs list -Hp -o used ${POOL}/${host})
used_h=$(zfs list -H -o used ${POOL}/${host})
test -f ${LOCK_DIR}/${host} && lock_file=1 || lock_file=0
rc=3
ret=""
if [[ $lock_file -eq 1 ]]; then
lock_age=$(expr `date +%s` - `stat -c %Y ${LOCK_DIR}/${host}`)
lock_age_h=$(expr $lock_age / 3600)
lock_age_t=$(expr $lock_age % 3600)
lock_age_m=$(expr $lock_age_t / 60)
lock_age_s=$(expr $lock_age_t % 60)
ret="lock file exists! lock_age: ${lock_age_h}h ${lock_age_m}m ${lock_age_s}s"
[[ $running_rsyncs -gt 0 ]] && rc=1 || rc=2
elif find ${MOUNT_DIR}/${host}/ -maxdepth 1 -type f -name .last_backup -mmin -${time} -printf "%p is newer than ${time} mins, last chage: %c" 2>/dev/null |grep -q 'newer'; then
rc=0
else
ret="newer backup than ${time} mins not found!"
rc=2
fi
ret="$ret last snap: ${last_snap}, lock file: ${lock_file}, running rsyncs: ${running_rsyncs}, used: ${used_h} | lock_file=${lock_file}; running_rsyncs=${running_rsyncs}; used=${used}B; "
[ $(basename "$0") == "check_backup.sh" ] && (echo $ret; exit $rc) || return $rc
# vim: noexpandtab tabstop=2 shiftwidth=2 nowrap