You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.4 KiB
34 lines
1.4 KiB
#!/bin/bash
|
|
|
|
SHELL=/bin/bash
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
## Check on daily bases if backup exist in config and when is the last backup done :
|
|
## ALERT if backup is set and last backup is older than 24h
|
|
|
|
LOCK_WORKING_DIR="/var/run/myc-manage"
|
|
mkdir -p "$LOCK_WORKING_DIR"
|
|
|
|
IS_BACKUP_SET=$(cat /opt/apps/myc-deploy/compose.yml </dev/null | grep backup)
|
|
if [[ "$IS_BACKUP_SET" == *"backup"* ]]; then
|
|
date_last_backup=$(cat /srv/datastore/data/cron/var/log/cron/rsync-backup_script.log | grep "total size is" | tail -1 | cut -f -2 -d " ")
|
|
backup_timestamp=$(date -d "$date_last_backup" +%s)
|
|
max_timestamp=$(date -d "24 hours ago" +%s)
|
|
if [ "$backup_timestamp" -lt "$max_timestamp" ]; then
|
|
if [ -e $LOCK_WORKING_DIR/check_backup.lock ]; then
|
|
exit 0
|
|
else
|
|
touch $LOCK_WORKING_DIR/check_backup.lock
|
|
timestamp=$(date +%s)
|
|
time_difference=$((timestamp - backup_timestamp))
|
|
days=$((time_difference / 86400))
|
|
hours=$((time_difference % 86400 / 3600))
|
|
message="[$(hostname)]: WARNING no backup done in the last 24h (No backup since $days days and $hours hours)"
|
|
send "$message"
|
|
fi
|
|
else
|
|
if [ -e $LOCK_WORKING_DIR/check_backup.lock ]; then
|
|
rm $LOCK_WORKING_DIR/check_backup.lock
|
|
fi
|
|
fi
|
|
fi
|