1
0
Fork 0

Add a script to check the last borg backup

This commit is contained in:
Luca Beltrame 2020-07-20 00:03:06 +02:00
parent 2019dab02a
commit 9c2868feda
Signed by: einar
GPG key ID: 4707F46E9EC72DEC

45
borg_check_last.sh Executable file
View file

@ -0,0 +1,45 @@
#!/bin/bash
# SPDX-License_identifier: BSD-3-Clause
# Script to check the last known date of the backup and warn if too old
# Requires jq and yq
set -e
set -o nounset
set -o pipefail
mailto="root"
fromname="yournamehere"
mailfrom="yournamehere <yourmail>"
max_days=7
last_bak=$(borgmatic list --last 1 --format "{end} {NEWLINE}" --successful --json | \
jq '.[].archives | sort_by(.end)[].end | gsub("\\.000000$"; "Z") | fromdate')
repository_name=$(yq '.location.repositories[0]' /etc/borgmatic/config.yaml)
current=$(date +%s)
difference="$(( current - last_bak ))"
diff_days="$(( difference / (3600 * 24) ))"
host_name=$(hostname)
if (( diff_days > max_days ));
then
sendmail "$mailto" <<EOF
From: $mailfrom
To: $fromname <$mailto>
Subject:[borgbackup] Warning: backup older than $diff_days days.
Hello,
This is an automated message sent from $host_name.
The backup in $repository_name has not been updated in more than $max_days
days. It is advisable to check for errors or disabled services.
--
Automated report system
EOF
fi