From 721c393d2d39615e95702198d843ec9d01eb8abd Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Wed, 10 Nov 2021 21:17:12 +0200 Subject: [PATCH] Allow overriding cron schedule, fix vars --- .env.sample | 6 ++++++ Dockerfile | 8 +++----- compose.yml | 1 + setup-cron.sh | 11 +++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 setup-cron.sh diff --git a/.env.sample b/.env.sample index dc90698..6aa0e3d 100644 --- a/.env.sample +++ b/.env.sample @@ -4,10 +4,16 @@ SECRET_RESTIC_PASSWORD_VERSION=v1 COMPOSE_FILE=compose.yml +SERVER_NAME=example.com +RESTIC_HOST=minio.example.com + +CRON_SCHEDULE='*/5 * * * *' + # SSH storage #SECRET_SSH_KEY_VERSION=v1 #COMPOSE_FILE="$COMPOSE_FILE:compose.ssh.yml" # S3 storage #SECRET_AWS_SECRET_ACCESS_KEY_VERSION=v1 +#AWS_ACCESS_KEY_ID=something-secret #COMPOSE_FILE="$COMPOSE_FILE:compose.s3.yml" diff --git a/Dockerfile b/Dockerfile index 10e10ae..debb7b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,7 @@ RUN apk add --upgrade --no-cache \ restic COPY backup.sh /usr/bin/backup.sh -RUN chmod +x /usr/bin/backup.sh +COPY setup-cron.sh /usr/bin/setup-cron.sh +RUN chmod +x /usr/bin/backup.sh /usr/bin/setup-cron.sh -RUN echo "* * * * * /usr/bin/backup.sh" | crontab - -RUN crontab -l - -ENTRYPOINT ["crond", "-f", "-L", "/dev/stdout"] +ENTRYPOINT [ "/usr/bin/setup-cron.sh" ] diff --git a/compose.yml b/compose.yml index 4dcd125..b536cea 100644 --- a/compose.yml +++ b/compose.yml @@ -8,6 +8,7 @@ services: - "/var/run/docker.sock:/var/run/docker.sock" - "backups:/backups" environment: + - CRON_SCHEDULE - RESTIC_REPO - RESTIC_PASSWORD_FILE=/run/secrets/restic_password - BACKUP_DEST=/backups diff --git a/setup-cron.sh b/setup-cron.sh new file mode 100644 index 0000000..6864b67 --- /dev/null +++ b/setup-cron.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e +set -o pipefail + +cron_schedule="${CRON_SCHEDULE:?CRON_SCHEDULE not set}" + +echo "$cron_schedule /usr/bin/backup.sh" | crontab - +crontab -l + +crond -f -L /dev/stdout