-
Notifications
You must be signed in to change notification settings - Fork 14
/
checklastbackup.sh
executable file
·38 lines (33 loc) · 1.14 KB
/
checklastbackup.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
#!/bin/sh
# Checks whether the backup is up-to-date. It is considered out-of-date when
# no backup has been created during the "critical time" shown below.
#
# LICENSE: CC0/Public Domain - To the extent possible under law, rugk has waived all copyright and related or neighboring rights to this work. This work is published from: Deutschland.
LAST_BACKUP_DIR="/var/log/borg/last"
CRITICAL_TIME=$(( 25*60*60 )) # 25h
dir_contains_files() {
ls -A "$1"
}
wait=0
# check for borg backup notes
if [ -d "$LAST_BACKUP_DIR" ] && [ "$( dir_contains_files $LAST_BACKUP_DIR )" ]; then
for file in "$LAST_BACKUP_DIR"/*; do
name=$( basename "$file" .time )
time=$( cat "$file" )
relvtime=$(( $(date +%s) - time ))
if [ "$relvtime" -ge "$CRITICAL_TIME" ]; then
echo "WARNING: The borg backup named \"$name\" is outdated."
echo " Last successful execution: $( date --date=@"$time" +'%A, %F %T' )"
wait=1
fi
done
else
echo "ERROR: No borg backup 'last' dir…"
wait=1
fi
if [ "$wait" = "1" ]; then
echo "Press enter to continue…"
# (deliberately unused and I don't care about backslashes here)
# shellcheck disable=SC2034,SC2162
read key
fi