Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ lib*.prl
lib*.a
lib*.prl

*.sql

# FIXME: Why are these files created?
\\
*/target_wrapper.sh

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 @@ -5,6 +5,21 @@ version: '3'

services:

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