mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-19 00:32:34 +01:00
allow to run crontab job with userid 1000
This commit is contained in:
parent
4e5a9162f4
commit
038d4faf7f
3 changed files with 19 additions and 7 deletions
17
Dockerfile
17
Dockerfile
|
@ -13,7 +13,15 @@ RUN go install
|
||||||
FROM alpine:3.12
|
FROM alpine:3.12
|
||||||
LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
|
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
|
COPY --from=binary /go/bin/dockerize /usr/local/bin
|
||||||
|
|
||||||
|
@ -23,7 +31,12 @@ ENV CRON_TIME="0 3 * * sun" \
|
||||||
TIMEOUT="10s"
|
TIMEOUT="10s"
|
||||||
|
|
||||||
COPY ["run.sh", "backup.sh", "restore.sh", "/"]
|
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"]
|
VOLUME ["/backup"]
|
||||||
|
|
||||||
CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh
|
CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh
|
||||||
|
|
|
@ -14,12 +14,12 @@ do
|
||||||
echo "==> Dumping database: $db"
|
echo "==> Dumping database: $db"
|
||||||
FILENAME=/backup/$DATE.$db.sql
|
FILENAME=/backup/$DATE.$db.sql
|
||||||
LATEST=/backup/latest.$db.sql.gz
|
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
|
then
|
||||||
gzip "-$GZIP_LEVEL" -f "$FILENAME"
|
gzip "-$GZIP_LEVEL" -f "$FILENAME"
|
||||||
echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)"
|
echo "==> Creating symlink to latest backup: $(basename "$FILENAME".gz)"
|
||||||
rm "$LATEST" 2> /dev/null
|
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 ))
|
DB_COUNTER=$(( DB_COUNTER + 1 ))
|
||||||
else
|
else
|
||||||
rm -rf "$FILENAME"
|
rm -rf "$FILENAME"
|
||||||
|
|
5
run.sh
5
run.sh
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
touch /mysql_backup.log
|
|
||||||
tail -F /mysql_backup.log &
|
tail -F /mysql_backup.log &
|
||||||
|
|
||||||
if [ "${INIT_BACKUP}" -gt "0" ]; then
|
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
|
find /backup -maxdepth 1 -name '*.sql.gz' | tail -1 | xargs /restore.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /crontab.conf
|
echo "${CRON_TIME} /backup.sh >> /mysql_backup.log 2>&1" > /tmp/crontab.conf
|
||||||
crontab /crontab.conf
|
crontab /tmp/crontab.conf
|
||||||
echo "=> Running cron task manager"
|
echo "=> Running cron task manager"
|
||||||
exec crond -f
|
exec crond -f
|
||||||
|
|
Loading…
Reference in a new issue