#!/bin/bash touch /logs/mysql_backup.log /logs/mongo_backup.log tail -F /logs/mysql_backup.log /logs/mongo_backup.log & rm -rf /crontab.conf if [ "${INIT_BACKUP}" -gt "0" ]; then echo "=> Create a backup on the startup" /backup_mongo.sh /backup.sh elif [ -n "${INIT_RESTORE_LATEST}" ]; then echo "=> Restore latest backup" until nc -z "$MYSQL_HOST" "$MYSQL_PORT" do echo "waiting database container..." sleep 1 done find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh fi echo "${CRON_TIME} /backup.sh >> /logs/mysql_backup.log 2>&1 " >> /crontab.conf echo "${CRON_TIME} /backup_mongo.sh >> /logs/mongo_backup.log 2>&1" >> /crontab.conf crontab /crontab.conf echo "=> Running cron task manager" exec crond -f