From 3c9af7f6c5f597773cc2b1b60e8cac2ac7ae7d7b Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Wed, 29 Oct 2025 16:56:47 +0300 Subject: [PATCH] use go-cron Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- Dockerfile | 9 +++++++++ src/run.sh | 20 ++++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5965fd9..5e2a8ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,15 @@ RUN curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f4 apk add --allow-untrusted mssql-tools18_18.1.1.1-1_amd64.apk && \ rm msodbcsql18_18.1.1.1-1_amd64.apk mssql-tools18_18.1.1.1-1_amd64.apk +# Install go-cron for scheduled backups +# Source: https://github.com/ivoronin/go-cron +ARG TARGETARCH +RUN curl -L https://github.com/ivoronin/go-cron/releases/download/v0.0.5/go-cron_0.0.5_linux_${TARGETARCH}.tar.gz -O && \ + tar xvf go-cron_0.0.5_linux_${TARGETARCH}.tar.gz && \ + rm go-cron_0.0.5_linux_${TARGETARCH}.tar.gz && \ + mv go-cron /usr/local/bin/go-cron && \ + chmod +x /usr/local/bin/go-cron + RUN rm -rf /var/cache/apk/* ENV PATH="${PATH}:/opt/mssql-tools18/bin" diff --git a/src/run.sh b/src/run.sh index a80f9cd..977d66e 100644 --- a/src/run.sh +++ b/src/run.sh @@ -11,22 +11,10 @@ fi if [ -z "$SCHEDULE" ]; then sh backup.sh else - # For non-root users, use a writable directory for crontabs - # busybox crond supports -c option to specify crontab directory - CRON_USER=$(id -u) - CRON_DIR="${HOME}/crontabs" - - # Create crontab directory - mkdir -p "$CRON_DIR" - - # Write crontab entry - echo "$SCHEDULE /bin/sh $(pwd)/backup.sh" > "$CRON_DIR/$CRON_USER" - chmod 600 "$CRON_DIR/$CRON_USER" - echo "Backup schedule configured: $SCHEDULE" - echo "Crontab file: $CRON_DIR/$CRON_USER" - echo "Starting crond..." + echo "Starting go-cron..." - # Start crond in foreground mode with custom crontab directory - exec crond -f -d 8 -c "$CRON_DIR" + # Use go-cron to run backup.sh on the specified schedule + # go-cron takes schedule and command as arguments + exec go-cron "$SCHEDULE" /bin/sh "$(pwd)/backup.sh" fi