diff --git a/Dockerfile b/Dockerfile index 6ccb6c9..3d9ec2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ FROM mariadb:10 -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -q -y cron sudo automysqlbackup +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -q -y cron sudo automysqlbackup COPY mysql.cnf /etc/mysql/mariadb.conf.d/settings.cnf RUN chown mysql:mysql /etc/mysql/mariadb.conf.d/settings.cnf COPY docker-entrypoint.sh /usr/local/bin/ +COPY healthcheck.sh /usr/local/bin/ COPY automysqlbackup /etc/default COPY sudoers /etc/sudoers.d/mysudoers - -#HEALTHCHECK - +HEALTHCHECK CMD /usr/local/bin/healthcheck.sh diff --git a/README.md b/README.md index e1bbea8..b6d6c74 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ +[![Build Status](https://drone.asperti.com/api/badges/paspo/docker-mariadb-backup-slave/status.svg)](https://drone.asperti.com/paspo/docker-mariadb-backup-slave) + + # docker-mariadb-backup-slave -Setup a mariadb slave server with automysqlbackup \ No newline at end of file +Setup a mariadb slave server with automysqlbackup + + +## Parameters +### SERVER_ID +This is used to customize slave server ID. The default value is 33. You should use an unique ID for each server. +### READONLY +When set to **1**, the slave server is set as readonly. This is the default. If you set this variable to something different, the database will be read/write. +### REPLICATE_DO_DB +This is used to specify a single database to backup. It is generally advised to set this variable to the database name you want to backup. + + + + + +$ docker exec some-mariadb sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql + + +2019-11-24 10:57:24 0 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--log-basename=#' or '--relay-log=mysqld-relay-bin' to avoid this problem. diff --git a/healthcheck.sh b/healthcheck.sh new file mode 100755 index 0000000..14823f4 --- /dev/null +++ b/healthcheck.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +RES=$(mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ',') +if [ "$RES" = " Yes, Yes," ]; then + exit 0 +fi +exit 1 + \ No newline at end of file