From 62569d9abfc936cd6b240bc01b9c6f8a990b529d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 18 Aug 2023 16:08:31 +0200 Subject: [PATCH] feat: run in cron or one-shot mode depending if KOPIA_CRON_SCHEDULE is set --- Dockerfile | 2 +- entrypoint.sh | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1661cea..4ef6a28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM kopia/kopia ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/* -ARG KOPIA_CRON_SCHEDULE="*/30 * * * *" +ARG KOPIA_CRON_SCHEDULE ENV KOPIA_CRON_SCHEDULE ${KOPIA_CRON_SCHEDULE} ARG KOPIA_USERNAME diff --git a/entrypoint.sh b/entrypoint.sh index 3ab50d9..6f688b2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,14 +1,21 @@ -#!/bin/sh +#!/bin/bash -CRONTAB=/etc/cron.d/kopia-backup +if [[ -z ${KOPIA_CRON_SCHEDULE} ]]; +then + echo "Running in one-shot mode" -printenv > /etc/environment + /run-backup.sh +else + CRONTAB=/etc/cron.d/kopia-backup -echo "Running cron with schedule ${KOPIA_CRON_SCHEDULE}" + printenv > /etc/environment -echo "${KOPIA_CRON_SCHEDULE} /run-backup.sh > /var/log/kopia-backup.log 2>&1" > ${CRONTAB} -chmod 0644 ${CRONTAB} -crontab ${CRONTAB} + echo "Running cron with schedule ${KOPIA_CRON_SCHEDULE}" -touch /var/log/kopia-backup.log -cron && tail -f /var/log/kopia-backup.log + echo "${KOPIA_CRON_SCHEDULE} /run-backup.sh > /var/log/kopia-backup.log 2>&1" > ${CRONTAB} + chmod 0644 ${CRONTAB} + crontab ${CRONTAB} + + touch /var/log/kopia-backup.log + cron && tail -f /var/log/kopia-backup.log +fi