diff --git a/borg_check_last.sh b/borg_check_last.sh new file mode 100755 index 0000000..99bcc88 --- /dev/null +++ b/borg_check_last.sh @@ -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 " + +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" < +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