restic-docker/entry.sh

30 lines
874 B
Bash
Raw Permalink Normal View History

2019-06-06 06:37:26 +00:00
#!bin/sh
echo "Starting container ..."
restic snapshots
rc=$?
if [[ $rc != 0 ]]; then
echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init."
restic init
fi
echo "Setup backup cron job with cron expression BACKUP_CRON: ${BACKUP_CRON}"
echo "${BACKUP_CRON} flock -n /tmp/backup.lockfile /bin/backup >> /var/log/cron.log 2>&1" > /var/spool/cron/crontabs/root
echo "Setup check cron job with cron expression CHECK_CRON: ${CHECK_CRON}"
echo "${CHECK_CRON} flock /tmp/backup.lockfile /bin/check >> /var/log/cron.log 2>&1" >> /var/spool/cron/crontabs/root
cat /var/spool/cron/crontabs/root
# Make sure the file exists before we start tail
touch /var/log/cron.log
# start the cron deamon
crond
echo "Container started."
if [ -n "${RESTIC_BACKUPONSTART}" ]; then
flock -n /tmp/backup.lockfile /bin/backup
fi
tail -fn0 /var/log/cron.log