diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c03e5b..ea21ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.16 - 2019-06-16 - + +* Check to see if Database Exists before performing backup +* Fix for MysQL/MariaDB custom ports - Credit to + ## 1.15 - 2019-05-24 - * Added abaility to backup password protected Redis Hosts diff --git a/Dockerfile b/Dockerfile index b1834ca..ccea201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ COPY --from=mongo-packages / /usr/src/apk apk add \ pixz@testing \ && \ - + \ ## Locally Install Mongo Package cd /usr/src/apk && \ apk add -t .db-backup-mongo-deps --allow-untrusted \ diff --git a/README.md b/README.md index 72c6c79..f6a7190 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# tiredofit/db-backup +# hub.docker.com/r/tiredofit/db-backup [![Build Status](https://img.shields.io/docker/build/tiredofit/db-backup.svg)](https://hub.docker.com/r/tiredofit/db-backup) @@ -23,7 +23,7 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB Postgres, Redis, Rethink se * select how often to run a dump * select when to start the first dump, whether time of day or relative to container start time -This Container uses Alpine:Edge as a base. +* This Container uses a [customized Alpine Linux base](https://hub.docker.com/r/tiredofit/alpine) which includes [s6 overlay](https://github.com/just-containers/s6-overlay) enabled for PID 1 Init capabilities, [zabbix-agent](https://zabbix.org) based on `3.4` compiled for individual container monitoring, Cron also installed along with other tools (bash,curl, less, logrotate, nano, vim) for easier management. It also supports sending to external SMTP servers [Changelog](CHANGELOG.md) @@ -56,7 +56,7 @@ method of installation. ```bash -docker pull tiredofit/db-backup +docker pull tiredofit/db-backup:latest ``` # Quick Start @@ -92,6 +92,7 @@ Along with the Environment Variables from the [Base image](https://hub.docker.co | `DB_NAME` | Schema Name e.g. `database` | `DB_USER` | username for the database - use `root` to backup all MySQL of them. | `DB_PASS` | (optional if DB doesn't require it) password for the database +| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | `DB_DUMP_FREQ` | How often to do a dump, in minutes. Defaults to 1440 minutes, or once per day. | `DB_DUMP_BEGIN` | What time to do the first dump. Defaults to immediate. Must be in one of two formats | | Absolute HHMM, e.g. `2330` or `0415` diff --git a/install/etc/s6/services/10-db-backup/run b/install/etc/s6/services/10-db-backup/run index 717c5e1..cf4dd47 100755 --- a/install/etc/s6/services/10-db-backup/run +++ b/install/etc/s6/services/10-db-backup/run @@ -193,6 +193,78 @@ function backup_rethink() { move_backup } +function check_availability() { +### Set the Database Type + case "$DBTYPE" in + "couch" ) + COUNTER=0 + while ! (nc -z ${DBHOST} ${DBPORT}) ; do + sleep 5 + let COUNTER+=5 + echo "** [db-backup] CouchDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" + done + ;; + "influx" ) + COUNTER=0 + while ! (nc -z ${DBHOST} ${DBPORT}) ; do + sleep 5 + let COUNTER+=5 + echo "** [db-backup] InfluxDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" + done + ;; + "mongo" ) + COUNTER=0 + while ! (nc -z ${DBHOST} ${DBPORT}) ; do + sleep 5 + let COUNTER+=5 + echo "** [db-backup] Mongo Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" + done + ;; + "mysql" ) + COUNTER=0 + while true; do + mysqlcmd='mysql -u'${DBUSER}' -P '${DBPORT}' -h '${DBHOST}' -p'${DBPASS} + out="`$mysqlcmd -e "SELECT COUNT(*) FROM information_schema.FILES;" 2>&1`" + echo "$out" | grep -E "COUNT|Enter" 2>&1 > /dev/null + if [ $? -eq 0 ]; then + : + break + fi + echo "** [db-backup] MySQL/MariaDB Server "$DBHOST" is not accessible, retrying.. ($COUNTER seconds so far)" + sleep 5 + let COUNTER+=5 + done + ;; + "pgsql" ) + # Wait until mongo logs that it's ready (or timeout after 60s) + COUNTER=0 + export PGPASSWORD=${DBPASS} + until pg_isready --dbname=${DBNAME} --host=${DBHOST} --port=${DBPORT} --username=${DBUSER} -q + do + sleep 5 + let COUNTER+=5 + echo "** [db-backup] Postgres Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" + done + ;; + "redis" ) + COUNTER=0 + while ! (nc -z ${DBHOST} ${DBPORT}) ; do + sleep 5 + let COUNTER+=5 + echo "** [db-backup] Redis Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" + done + ;; + "rethink" ) + COUNTER=0 + while ! (nc -z ${DBHOST} ${DBPORT}) ; do + sleep 5 + let COUNTER+=5 + echo "** [db-backup] RethinkDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" + done + ;; + esac +} + function compression() { case "$COMPRESSION" in "GZ" | "gz" | "gzip" | "GZIP") @@ -258,24 +330,31 @@ echo '** [db-backup] Initialized at at '$(date) ### Take a Dump case "$DBTYPE" in "couch" ) + check_availability backup_couch ;; "influx" ) + check_availability backup_influx ;; "mysql" ) + check_availability backup_mysql ;; "mongo" ) + check_availability backup_mongo ;; "pgsql" ) + check_availability backup_pgsql ;; "redis" ) + check_availability backup_redis ;; "rethink" ) + check_availability backup_rethink ;; esac