allow to run crontab job with userid 1000

This commit is contained in:
Fco. Javier Delgado del Hoyo 2021-05-08 21:58:48 +02:00
parent 4e5a9162f4
commit 038d4faf7f
3 changed files with 19 additions and 7 deletions

View file

@ -13,7 +13,15 @@ RUN go install
FROM alpine:3.12
LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
RUN apk add --update tzdata bash mysql-client gzip openssl mariadb-connector-c && rm -rf /var/cache/apk/*
RUN apk add --update \
tzdata \
bash \
mysql-client \
gzip \
openssl \
mariadb-connector-c \
busybox-suid && \
rm -rf /var/cache/apk/*
COPY --from=binary /go/bin/dockerize /usr/local/bin
@ -23,7 +31,12 @@ ENV CRON_TIME="0 3 * * sun" \
TIMEOUT="10s"
COPY ["run.sh", "backup.sh", "restore.sh", "/"]
RUN mkdir /backup && chmod u+x /backup.sh /restore.sh
RUN mkdir /backup && \
chmod 755 /run.sh /backup.sh /restore.sh && \
touch /mysql_backup.log && \
chmod 666 /mysql_backup.log && \
adduser -S -u 1000 -g 100 cronuser
VOLUME ["/backup"]
CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh

View file

@ -14,12 +14,12 @@ do
echo "==> Dumping database: $db"
FILENAME=/backup/$DATE.$db.sql
LATEST=/backup/latest.$db.sql.gz
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $db $MYSQLDUMP_OPTS > "$FILENAME"
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" $MYSQLDUMP_OPTS > "$FILENAME"
then
gzip "-$GZIP_LEVEL" -f "$FILENAME"
echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)"
rm "$LATEST" 2> /dev/null
cd /backup || exit && ln -s $(basename "$FILENAME".gz) $(basename "$LATEST") && cd -
cd /backup || exit && ln -s "$(basename "$FILENAME".gz)" "$(basename "$LATEST")" && cd - || exit
DB_COUNTER=$(( DB_COUNTER + 1 ))
else
rm -rf "$FILENAME"

5
run.sh
View file

@ -1,5 +1,4 @@
#!/bin/bash
touch /mysql_backup.log
tail -F /mysql_backup.log &
if [ "${INIT_BACKUP}" -gt "0" ]; then
@ -15,7 +14,7 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then
find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh
fi
echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /crontab.conf
crontab /crontab.conf
echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf
crontab /tmp/crontab.conf
echo "=> Running cron task manager"
exec crond -f