Skip to content

Commit

Permalink
Add a cron mysqldump image
Browse files Browse the repository at this point in the history
  • Loading branch information
aalex committed Oct 26, 2020
1 parent d26bd19 commit d40de85
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ lib*.prl
lib*.a
lib*.prl

*.sql
2 changes: 2 additions & 0 deletions backups/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory contains the backups for the MySQL database.

15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ services:
CONFIG_USE_SQLITE: 'false'
MPOP_SERVICE_PORT_NUMBER: '3333'

cron:
build: ./mysqldump
# image: schnitzler/mysqldump
restart: always
volumes:
- ./mysqldump/crontab:/var/spool/cron/crontabs/root
- ./mysqldump/backup.sh:/usr/local/bin/backup.sh
- ./backups:/backups
command: ["-l", "8", "-d", "8"]
environment:
MYSQL_HOST: 'db'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'secret'
MYSQL_DATABASE: 'mpop_database'

phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
Expand Down
5 changes: 5 additions & 0 deletions mysqldump/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:3.9

RUN apk add --no-cache mysql-client
ENTRYPOINT ["crond", "-f"]

13 changes: 13 additions & 0 deletions mysqldump/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

FILENAME=${MYSQL_DATABASE}-$(date +%Y-%m-%d_%Hh%Mm%S).sql

set -o verbose

mysqldump \
--host=${MYSQL_HOST} \
--user=${MYSQL_USER} \
--password=${MYSQL_PASSWORD} \
--lock-tables=false \
${MYSQL_DATABASE} > /backups/${FILENAME}

4 changes: 4 additions & 0 deletions mysqldump/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#minute hour day month week command
#0 0 * * * /usr/local/bin/backup.sh
* * * * * /usr/local/bin/backup.sh

0 comments on commit d40de85

Please sign in to comment.