]>
Commit | Line | Data |
---|---|---|
171d8e1a IB |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -euo pipefail | |
4 | ||
5 | source $SECRETS_PATH | |
6 | export HOME=$(mktemp -d) | |
7 | ||
8 | trap "rm -rf $HOME" EXIT | |
9 | folder=$1 | |
10 | ||
11 | parse_date() { | |
12 | d=$1 | |
13 | echo $d | sed -e "s/^\(....\)\(..\)\(..\)T\(..\)\(..\)\(..\)/\1-\2-\3T\4:\5:\6/" | |
14 | } | |
15 | ||
16 | output=$(duplicity collection-status --log-fd 2 "$BASE_URL$folder" 2>&1 > /dev/null) | |
17 | ||
18 | output=$(echo "$output" | grep -v "^\.") | |
19 | ||
546864bc IB |
20 | last_full=$(parse_date "$(echo "$output" | grep "^ full " | cut -d' ' -f3 | sort | tail -n1)") |
21 | last_bkp=$(parse_date "$(echo "$output" | grep -E "^ (full|inc) " | cut -d' ' -f3 | sort | tail -n1)") | |
171d8e1a IB |
22 | orphaned_sets=$(echo "$output" | grep "^orphaned-sets-num" | cut -d' ' -f2) |
23 | incomplete_sets=$(echo "$output" | grep "^incomplete-sets-num" | cut -d' ' -f2) | |
24 | ||
25 | if [[ -z "$last_full" || -z "$last_bkp" || -z "$orphaned_sets" || -z "$incomplete_sets" ]]; then | |
26 | echo "duply-backup $folder UNKNOWN - impossible to parse result" | |
27 | exit 3 | |
28 | fi | |
29 | ||
30 | last_full_age=$(( ($(date "+%s") - $(date -d "$last_full" "+%s")) / (60*60*24) )) | |
31 | last_bkp_age=$(( ($(date "+%s") - $(date -d "$last_bkp" "+%s")) / (60*60) )) | |
32 | ||
33 | PERFS="orphan=$orphaned_sets;1;;0; incomplete=$incomplete_sets;1;;0; age=${last_bkp_age}h;30;48;0; full_age=${last_full_age}d;35;45;0;" | |
34 | ||
35 | ||
36 | WARNINGS="" | |
37 | ERRORS="" | |
38 | if [[ "$incomplete_sets" -gt 0 ]]; then | |
39 | WARNINGS="$WARNINGS - Incomplete sets is $incomplete_sets" | |
40 | fi | |
41 | ||
42 | if [[ "$orphaned_sets" -gt 0 ]]; then | |
43 | WARNINGS="$WARNINGS - Orphaned sets is $orphaned_sets" | |
44 | fi | |
45 | ||
46 | if [[ "$last_full_age" -gt 45 ]]; then | |
47 | ERRORS="$ERRORS - Last full backup is too old $last_full" | |
48 | elif [[ "$last_full_age" -gt 35 ]]; then | |
49 | WARNINGS="$WARNINGS - Last full backup is getting old $last_full" | |
50 | fi | |
51 | ||
52 | if [[ "$last_bkp_age" -gt 48 ]]; then | |
53 | ERRORS="$ERRORS - Last backup is too old $last_bkp" | |
54 | elif [[ "$last_bkp_age" -gt 30 ]]; then | |
55 | WARNINGS="$WARNINGS - Last backup is getting old $last_bkp" | |
56 | fi | |
57 | ||
58 | if [[ -n "$ERRORS" ]]; then | |
59 | echo "duply-backup $folder CRITICAL$ERRORS$WARNINGS | $PERFS" | |
60 | exit 2 | |
61 | elif [[ -n "$WARNINGS" ]]; then | |
62 | echo "duply-backup $folder WARNING$WARNINGS | $PERFS" | |
63 | exit 1 | |
64 | else | |
65 | echo "duply-backup $folder OK | $PERFS" | |
66 | fi |