mirror of
https://codeberg.org/mclemens/monitor-backup-dir.git
synced 2024-07-03 17:45:30 +00:00
22 lines
1.0 KiB
Bash
22 lines
1.0 KiB
Bash
|
target_dir=/var/borg
|
||
|
hash_dir=/var/hashes
|
||
|
mail_to="xxx@xxxx.xxx"
|
||
|
|
||
|
find ${target_dir}/* -maxdepth 0 -type d | while read line; do
|
||
|
host=$(echo "$line" | awk -F" +|/" '{print $NF}')
|
||
|
if [[ ! $host =~ ^(lost\+found)$ ]]; then
|
||
|
hash=$(mtree -cxp "$line" | grep -E -- ^\[^\#] | sha256sum)
|
||
|
if test -f "${hash_dir}/$host"; then
|
||
|
difference=$(diff ${hash_dir}/$host <(echo "$hash"))
|
||
|
if [ "$difference" == "" ]; then
|
||
|
mail_body="The host ${host} was not backed up since the last check. Please forward this mail to the owner of the affected system."
|
||
|
echo "$mail_body" | mail -s "${host} not backed up!" "$mail_to"
|
||
|
fi
|
||
|
else
|
||
|
mail_body="No previously generated hash for the ${host} could be found - probably because it ran for the first time. Please forward this mail to the owner of the affected system."
|
||
|
echo "$mail_body" | mail -s "Error while checking ${host} for missed backups!" "$mail_to"
|
||
|
fi
|
||
|
echo "$hash" > "${hash_dir}/$host"
|
||
|
fi
|
||
|
done
|