mirror of
https://github.com/ditkrg/db-backup-s3.git
synced 2026-01-22 13:56:47 +00:00
use go-cron
Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com>
This commit is contained in:
parent
7db86e3d72
commit
3c9af7f6c5
@ -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 && \
|
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
|
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/*
|
RUN rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
ENV PATH="${PATH}:/opt/mssql-tools18/bin"
|
ENV PATH="${PATH}:/opt/mssql-tools18/bin"
|
||||||
|
|||||||
20
src/run.sh
20
src/run.sh
@ -11,22 +11,10 @@ fi
|
|||||||
if [ -z "$SCHEDULE" ]; then
|
if [ -z "$SCHEDULE" ]; then
|
||||||
sh backup.sh
|
sh backup.sh
|
||||||
else
|
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 "Backup schedule configured: $SCHEDULE"
|
||||||
echo "Crontab file: $CRON_DIR/$CRON_USER"
|
echo "Starting go-cron..."
|
||||||
echo "Starting crond..."
|
|
||||||
|
|
||||||
# Start crond in foreground mode with custom crontab directory
|
# Use go-cron to run backup.sh on the specified schedule
|
||||||
exec crond -f -d 8 -c "$CRON_DIR"
|
# go-cron takes schedule and command as arguments
|
||||||
|
exec go-cron "$SCHEDULE" /bin/sh "$(pwd)/backup.sh"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user