mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-18 16:22:33 +01:00
commit
c2055f02c6
3 changed files with 11 additions and 4 deletions
12
Dockerfile
12
Dockerfile
|
@ -3,13 +3,19 @@ LABEL maintainer "Fco. Javier Delgado del Hoyo <frandelhoyo@gmail.com>"
|
||||||
|
|
||||||
COPY ["run.sh", "backup.sh", "restore.sh", "/"]
|
COPY ["run.sh", "backup.sh", "restore.sh", "/"]
|
||||||
|
|
||||||
RUN apk add --update bash mysql-client gzip && rm -rf /var/cache/apk/* && mkdir /backup &&\
|
RUN apk add --update bash mysql-client gzip openssl && rm -rf /var/cache/apk/* && mkdir /backup &&\
|
||||||
chmod u+x /backup.sh /restore.sh
|
chmod u+x /backup.sh /restore.sh
|
||||||
|
|
||||||
|
ENV DOCKERIZE_VERSION v0.6.1
|
||||||
|
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
|
||||||
|
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
|
||||||
|
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
|
||||||
|
|
||||||
ENV CRON_TIME="0 3 * * sun" \
|
ENV CRON_TIME="0 3 * * sun" \
|
||||||
MYSQL_HOST="mysql" \
|
MYSQL_HOST="mysql" \
|
||||||
MYSQL_PORT="3306"
|
MYSQL_PORT="3306" \
|
||||||
|
TIMEOUT="10s"
|
||||||
|
|
||||||
VOLUME ["/backup"]
|
VOLUME ["/backup"]
|
||||||
|
|
||||||
CMD ["/run.sh"]
|
CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh
|
||||||
|
|
|
@ -27,6 +27,7 @@ docker container run -d \
|
||||||
- `MAX_BACKUPS`: The number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default.
|
- `MAX_BACKUPS`: The number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default.
|
||||||
- `INIT_BACKUP`: If set, create a backup when the container starts.
|
- `INIT_BACKUP`: If set, create a backup when the container starts.
|
||||||
- `INIT_RESTORE_LATEST`: Ff set, restores latest backup.
|
- `INIT_RESTORE_LATEST`: Ff set, restores latest backup.
|
||||||
|
- `TIMEOUT`: Wait a given number of seconds for the database to be ready and make the first backup, `10s` by default. After that time, the initial attempt for backup gives up and only the Cron job will try to make a backup.
|
||||||
|
|
||||||
If you want to make this image the perfect companion of your MySQL container, use [docker-compose](https://docs.docker.com/compose/). You can add more services that will be able to connect to the MySQL image using the name `my_mariadb`, note that you only expose the port `3306` internally to the servers and not to the host:
|
If you want to make this image the perfect companion of your MySQL container, use [docker-compose](https://docs.docker.com/compose/). You can add more services that will be able to connect to the MySQL image using the name `my_mariadb`, note that you only expose the port `3306` internally to the servers and not to the host:
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ 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" --databases "$db" $MYSQLDUMP_OPTS > "$FILENAME"
|
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" "$MYSQLDUMP_OPTS" > "$FILENAME"
|
||||||
then
|
then
|
||||||
gzip -f "$FILENAME"
|
gzip -f "$FILENAME"
|
||||||
rm "$LATEST" 2> /dev/null
|
rm "$LATEST" 2> /dev/null
|
||||||
|
|
Loading…
Reference in a new issue