mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-21 21:33:28 +01:00
Check for host availability before backup
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
## 1.16 - 2019-06-16 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
* Check to see if Database Exists before performing backup
|
||||||
|
* Fix for MysQL/MariaDB custom ports - Credit to <spumer@github>
|
||||||
|
|
||||||
## 1.15 - 2019-05-24 - <claudioaltamura @ github>
|
## 1.15 - 2019-05-24 - <claudioaltamura @ github>
|
||||||
|
|
||||||
* Added abaility to backup password protected Redis Hosts
|
* Added abaility to backup password protected Redis Hosts
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ COPY --from=mongo-packages / /usr/src/apk
|
|||||||
apk add \
|
apk add \
|
||||||
pixz@testing \
|
pixz@testing \
|
||||||
&& \
|
&& \
|
||||||
|
\
|
||||||
## Locally Install Mongo Package
|
## Locally Install Mongo Package
|
||||||
cd /usr/src/apk && \
|
cd /usr/src/apk && \
|
||||||
apk add -t .db-backup-mongo-deps --allow-untrusted \
|
apk add -t .db-backup-mongo-deps --allow-untrusted \
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# tiredofit/db-backup
|
# hub.docker.com/r/tiredofit/db-backup
|
||||||
|
|
||||||
|
|
||||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
[](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 how often to run a dump
|
||||||
* select when to start the first dump, whether time of day or relative to container start time
|
* 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)
|
[Changelog](CHANGELOG.md)
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ method of installation.
|
|||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull tiredofit/db-backup
|
docker pull tiredofit/db-backup:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
# Quick Start
|
# 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_NAME` | Schema Name e.g. `database`
|
||||||
| `DB_USER` | username for the database - use `root` to backup all MySQL of them.
|
| `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_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_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
|
| `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`
|
| | Absolute HHMM, e.g. `2330` or `0415`
|
||||||
|
|||||||
@@ -193,6 +193,78 @@ function backup_rethink() {
|
|||||||
move_backup
|
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() {
|
function compression() {
|
||||||
case "$COMPRESSION" in
|
case "$COMPRESSION" in
|
||||||
"GZ" | "gz" | "gzip" | "GZIP")
|
"GZ" | "gz" | "gzip" | "GZIP")
|
||||||
@@ -258,24 +330,31 @@ echo '** [db-backup] Initialized at at '$(date)
|
|||||||
### Take a Dump
|
### Take a Dump
|
||||||
case "$DBTYPE" in
|
case "$DBTYPE" in
|
||||||
"couch" )
|
"couch" )
|
||||||
|
check_availability
|
||||||
backup_couch
|
backup_couch
|
||||||
;;
|
;;
|
||||||
"influx" )
|
"influx" )
|
||||||
|
check_availability
|
||||||
backup_influx
|
backup_influx
|
||||||
;;
|
;;
|
||||||
"mysql" )
|
"mysql" )
|
||||||
|
check_availability
|
||||||
backup_mysql
|
backup_mysql
|
||||||
;;
|
;;
|
||||||
"mongo" )
|
"mongo" )
|
||||||
|
check_availability
|
||||||
backup_mongo
|
backup_mongo
|
||||||
;;
|
;;
|
||||||
"pgsql" )
|
"pgsql" )
|
||||||
|
check_availability
|
||||||
backup_pgsql
|
backup_pgsql
|
||||||
;;
|
;;
|
||||||
"redis" )
|
"redis" )
|
||||||
|
check_availability
|
||||||
backup_redis
|
backup_redis
|
||||||
;;
|
;;
|
||||||
"rethink" )
|
"rethink" )
|
||||||
|
check_availability
|
||||||
backup_rethink
|
backup_rethink
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user