Script to monitor backup sets

When self hosting your own backup system it's not that uncommon to have some sort of monitoring system, just to make sure backups are present and exectuted according to the scheduling.

To address this topic I added to my backup hosting server a script that:
- analyze if there are files modified in a specific internal
- use "s-nail" to send email notifications in case of issues

The script source code is available below, keep an eye on the following configuration parameters needed to make it run in the right way:
- LOGFILE: where store logs
- ROOTDIR: the directory containing backup sets
- BKLIST: the list of backups and their timings
- MTA_*: the parameters needed to send notification emails

#!/bin/bash

### CONFIG PARAMS - CHANGE AS NEEDED ###

# 0. backup monitoring log file
LOGFILE="/tmp/backup-monitoring.log"

# 1. base directory containing backup sets
ROOTDIR="/home/backup"

# 2. list of backup folders (relative to ROOTDIR) + internal (days) between backups
BKLIST="personal-pc:1 work-pc:1 media-library:7"

# 3. username to send notification email
MTA_USER="your_smtp_username"
# 4. password to send notification email
MTA_PASS="your_smtp_password"
# 5. hostname to send notification email (smtp server)
MTA_HOST="yout.smtp.server"
# 6. tcp port to send notification email (587=smtp+starttls)
MTA_PORT="587"
# 7. email address as "from" in the notification email 
MTA_FROM="Backup <>"
# 8. email address as "to" in the notification email
MTA_TO=""

### MONITORING & NOTIFICATION PROCEDURES ###

date >> $LOGFILE || exit 1

SNAILBIN=$( which s-nail 2>/dev/null )

if [ "${SNAILBIN}" = "" ]; then
    echo "No s-nail command found"
    exit 2
fi

cd "${ROOTDIR}" 2>/dev/null >/dev/null
if [ "$?" != "0" ]; then
    echo "Unable to enter ${ROOTDIR}"
    exit 3
fi

for BKITEM in $BKLIST ;
do

    DIR="$( echo "${BKITEM}" | cut -d: -f1 )"
    AGE="$( echo "${BKITEM}" | cut -d: -f2 )"

    CHANGED=$( find "${DIR}" -type f -mtime -${AGE} 2>/dev/null )

    # no changes found ... send notification
    if [ "${CHANGED}" = "" ]; then

        MTA_SUBJECT="$( hostname ) - ${DIR} : No backup changes in ${AGE} days"

        echo "$(date +%Y.%m.%d) ${MTA_SUBJECT}" | $SNAILBIN \
            -S v15-compat \
            -S mta="submission://${MTA_USER}:${MTA_PASS}@${MTA_HOST}:${MTA_PORT}" \
            -S smtp-use-starttls \
            -S smtp-auth=login   \
            -r "${MTA_FROM}"     \
            -s "${MTA_SUBJECT}"  \
            "${MTA_TO}"          \
       >>$LOGFILE 2>>$LOGFILE

    fi

done

echo "" >> $LOGFILE