Merge pull request #291 from danielgroen/master

auto db backup script
This commit is contained in:
David Bomba
2021-03-03 16:46:13 +11:00
committed by GitHub
3 changed files with 46 additions and 1 deletions

10
config/mysql/Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM mysql:5
ENV force_color_prompt yes
RUN apt-get update;
RUN apt-get install -y cron;
ENTRYPOINT \
service cron start; \
printenv | grep -v "no_proxy" >> /etc/environment; \
docker-entrypoint.sh mysqld

View File

@@ -0,0 +1,28 @@
#!/bin/sh
FREQUENTY=`basename "$0"`
TIMESTAMP=$(date +"%Y-%m-%d")
case $FREQUENTY in
daily)
DAYS=6
;;
weekly)
DAYS=30
find /backups -type f -name $TIMESTAMP-daily.sql.gz -delete
;;
monthly)
DAYS=122
find /backups -type f -name $TIMESTAMP-weekly.sql.gz -delete
;;
esac
mysqldump -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} | gzip > /backups/$TIMESTAMP-$FREQUENTY.sql.gz
# Remove old backups
find /backups -mtime +${DAYS} -type f -name *-$FREQUENTY.sql.gz -delete
exit 0;

View File

@@ -40,7 +40,8 @@ services:
- "in5.localhost:192.168.0.124 " #host and ip
db:
image: mysql:5
build:
context: ./config/mysql
ports:
- "3305:3306"
restart: always
@@ -51,6 +52,12 @@ services:
- MYSQL_DATABASE=ninja
volumes:
- ./docker/mysql/data:/var/lib/mysql:rw,delegated
# comment out next 4 lines if you don't want auto sql backups
- ./docker/mysql/bak:/backups:rw
- ./config/mysql/backup-script:/etc/cron.daily/daily:ro
- ./config/mysql/backup-script:/etc/cron.weekly/weekly:ro
- ./config/mysql/backup-script:/etc/cron.monthly/monthly:ro
networks:
- invoiceninja
extra_hosts: