2017-03-27 21:16:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
tail -F /mysql_backup.log &
|
|
|
|
|
2023-01-05 11:44:39 +01:00
|
|
|
if [ "${INIT_BACKUP:-0}" -gt "0" ]; then
|
2017-03-27 21:16:15 +02:00
|
|
|
echo "=> Create a backup on the startup"
|
|
|
|
/backup.sh
|
|
|
|
elif [ -n "${INIT_RESTORE_LATEST}" ]; then
|
|
|
|
echo "=> Restore latest backup"
|
2017-04-08 17:57:23 +02:00
|
|
|
until nc -z "$MYSQL_HOST" "$MYSQL_PORT"
|
2017-03-27 21:16:15 +02:00
|
|
|
do
|
|
|
|
echo "waiting database container..."
|
|
|
|
sleep 1
|
|
|
|
done
|
2023-01-17 22:57:09 +01:00
|
|
|
# Needed to exclude the 'latest.<database>.sql.gz' file, consider only filenames starting with number
|
|
|
|
# Only data-tagged backups, eg. '202212250457.database.sql.gz', must be trapped by the regex
|
|
|
|
find /backup -maxdepth 1 -name '[0-9]*.*.sql.gz' | sort | tail -1 | xargs /restore.sh
|
2017-03-27 21:16:15 +02:00
|
|
|
fi
|
|
|
|
|
2023-01-19 20:14:48 +01:00
|
|
|
function final_backup {
|
2023-01-05 11:59:16 +01:00
|
|
|
echo "=> Captured trap for final backup"
|
|
|
|
echo "=> Requested last backup at $(date "+%Y-%m-%d %H:%M:%S")"
|
|
|
|
exec /backup.sh
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "${EXIT_BACKUP}" ]; then
|
|
|
|
echo "=> Listening on container shutdown gracefully to make last backup before close"
|
|
|
|
trap final_backup SIGHUP SIGINT SIGTERM
|
|
|
|
fi
|
|
|
|
|
2023-01-20 12:04:42 +01:00
|
|
|
touch /HEALTHY.status
|
2023-01-05 11:55:04 +01:00
|
|
|
|
2021-05-08 21:58:48 +02:00
|
|
|
echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf
|
|
|
|
crontab /tmp/crontab.conf
|
2021-05-09 11:28:53 +02:00
|
|
|
echo "=> Running cron task manager in foreground"
|
2023-01-05 11:59:16 +01:00
|
|
|
crond -f -l 8 -L /mysql_backup.log &
|
|
|
|
|
|
|
|
echo "Listening on crond, and wait..."
|
|
|
|
|
2023-01-17 22:23:34 +01:00
|
|
|
tail -f /dev/null & wait $!
|
2023-01-05 11:59:16 +01:00
|
|
|
|
|
|
|
echo "Script is shutted down."
|