-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcheck_borg_retention.sh
executable file
·42 lines (36 loc) · 1.21 KB
/
check_borg_retention.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
archives=$(jq -r '.archives[] | .archive' /var/backups/borglist.json)
keephourly=$(grep keephourly /etc/backup.d/91_all.borg | cut -d ' ' -f 3)
keepdaily=$(grep keepdaily /etc/backup.d/91_all.borg | cut -d ' ' -f 3)
keepmonthly=$(grep keepmonthly /etc/backup.d/91_all.borg | cut -d ' ' -f 3)
missing=()
for i in $(seq "$((keepmonthly - 1))" -1 1); do
archive=$(date -d "$i months ago" '+%Y-%m')
if ! echo "$archives" | grep -Eq "^$archive"; then
missing+=("$archive")
fi
done
for i in $(seq "$((keepdaily - 1))" -1 1); do
archive=$(date -d "$i day ago" '+%Y-%m-%d')
if ! echo "$archives" | grep -Eq "^$archive"; then
missing+=("$archive")
fi
done
if [ "$keephourly" -gt 1 ]; then
for i in $(seq "$keephourly" -1 1); do
archive=$(date -d "$i hour ago" '+%Y-%m-%d-%H')
if ! echo "$archives" | grep -Eq "^$archive"; then
missing+=("$archive")
fi
done
fi
if [ ${#missing[@]} -gt 1 ]; then
echo "CRITICAL - Missing ${#missing[@]} archives : " "${missing[@]}"
exit 2
elif [ ${#missing[@]} -gt 0 ]; then
echo "OK - But missing ${#missing[@]} archives : " "${missing[@]}"
exit 0
else
echo "OK - Found all archives"
exit 0
fi