evobackup/check-incs.sh

53 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2019-03-29 18:20:32 +01:00
#!/bin/sh
EVOBACKUP_CONFIGS="/etc/evobackup/*"
relative_date() {
format=$(echo $1 | cut -d'.' -f1)
time_jump=$(echo $1 | cut -d'.' -f2)
2019-12-15 18:52:09 +01:00
2019-03-29 18:20:32 +01:00
reference_date=$(date "${format}")
past_date=$(date --date "${reference_date} ${time_jump}" +"%Y-%m-%d")
2019-12-15 18:52:09 +01:00
2019-03-29 18:20:32 +01:00
echo ${past_date}
}
inc_exists() {
2019-12-15 18:52:09 +01:00
ls -d /backup/incs/$1 > /dev/null 2>&1
2019-03-29 18:20:32 +01:00
}
jail_exists() {
2019-12-15 18:52:09 +01:00
ls -d /backup/jails/$1 > /dev/null 2>&1
2019-03-29 18:20:32 +01:00
}
# default return value is 0 (succes)
rc=0
# loop for each configured jail
for file in ${EVOBACKUP_CONFIGS}; do
2019-12-15 18:52:09 +01:00
jail_name=$(basename ${file})
2019-03-29 18:20:32 +01:00
# check if jail is present
if jail_exists ${jail_name}; then
# get jail last configuration date
2019-12-15 18:52:09 +01:00
jail_config_age=$(date --date "$(stat -c %y ${file})" +"%s")
2019-03-29 18:20:32 +01:00
# loop for each line in jail configuration
2019-12-15 18:52:09 +01:00
for line in $(cat ${file}); do
2019-03-29 18:20:32 +01:00
# inc date in ISO format
2019-12-15 18:52:09 +01:00
inc_date=$(relative_date ${line})
2019-03-29 18:20:32 +01:00
# inc date in seconds from epoch
2019-12-15 18:52:09 +01:00
inc_age=$(date --date "${inc_date}" +"%s")
# check if the configuration changed after the inc date
if [ "${jail_config_age}" -lt "${inc_age}" ]; then
2019-03-29 18:20:32 +01:00
# Error if inc is not found
if ! inc_exists ${jail_name}/${inc_date}*; then
echo "ERROR: inc is missing \`${jail_name}/${inc_date}'" >&2
rc=1
fi
else
echo "INFO: no inc expected for ${inc_date} \`${jail_name}'"
fi
done
else
echo "ERROR: jail is missing \`${jail_name}'" >&2
rc=1
fi
done
exit $rc