mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-19 00:32:34 +01:00
Merge pull request #48 from fradelg/no-root-user
clean and sort Dockerfile
This commit is contained in:
commit
27ce6e2def
4 changed files with 26 additions and 15 deletions
20
Dockerfile
20
Dockerfile
|
@ -3,7 +3,9 @@ RUN apk -U add openssl git
|
||||||
|
|
||||||
ARG DOCKERIZE_VERSION=v0.6.1
|
ARG DOCKERIZE_VERSION=v0.6.1
|
||||||
WORKDIR /go/src/github.com/jwilder
|
WORKDIR /go/src/github.com/jwilder
|
||||||
RUN git clone https://github.com/jwilder/dockerize.git && cd dockerize && git checkout ${DOCKERIZE_VERSION}
|
RUN git clone https://github.com/jwilder/dockerize.git && \
|
||||||
|
cd dockerize && \
|
||||||
|
git checkout ${DOCKERIZE_VERSION}
|
||||||
|
|
||||||
WORKDIR /go/src/github.com/jwilder/dockerize
|
WORKDIR /go/src/github.com/jwilder/dockerize
|
||||||
RUN go get github.com/robfig/glock
|
RUN go get github.com/robfig/glock
|
||||||
|
@ -13,7 +15,14 @@ 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 && \
|
||||||
|
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 +32,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 777 /backup && \
|
||||||
|
chmod 755 /run.sh /backup.sh /restore.sh && \
|
||||||
|
touch /mysql_backup.log && \
|
||||||
|
chmod 666 /mysql_backup.log
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
[![Build Status](https://travis-ci.org/fradelg/docker-mysql-cron-backup.svg?branch=master)](https://travis-ci.org/fradelg/docker-mysql-cron-backup)
|
|
||||||
|
|
||||||
# mysql-cron-backup
|
# mysql-cron-backup
|
||||||
|
|
||||||
This docker image runs mysqldump to backup your databases periodically using cron task manager. Backups are placed in `/backup` so you can mount your backup docker volume in this path.
|
Run mysqldump to backup your databases periodically using the cron task manager in the container. Your backups are saved in `/backup`. You can mount any directory of your host or a docker volumes in /backup. Othwerwise, a docker volume is created in the default location.
|
||||||
|
|
||||||
## Usage:
|
## Usage:
|
||||||
|
|
||||||
|
@ -103,7 +101,7 @@ mysql-cron-backup:
|
||||||
### Restore using a docker command
|
### Restore using a docker command
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker container exec <your_mysql_backup_container_name> /restore.sh backup/<your_sql_backup_gz_file>
|
docker container exec <your_mysql_backup_container_name> /restore.sh /backup/<your_sql_backup_gz_file>
|
||||||
```
|
```
|
||||||
|
|
||||||
if no database name is specified, `restore.sh` will try to find the database name from the backup file.
|
if no database name is specified, `restore.sh` will try to find the database name from the backup file.
|
|
@ -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 --single-transaction -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" $db $MYSQLDUMP_OPTS > "$FILENAME"
|
if mysqldump --single-transaction -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")"
|
||||||
DB_COUNTER=$(( DB_COUNTER + 1 ))
|
DB_COUNTER=$(( DB_COUNTER + 1 ))
|
||||||
else
|
else
|
||||||
rm -rf "$FILENAME"
|
rm -rf "$FILENAME"
|
||||||
|
|
9
run.sh
9
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 in foreground"
|
||||||
exec crond -f
|
exec crond -f -l 8 -L /mysql_backup.log
|
||||||
|
|
Loading…
Reference in a new issue