mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 13:44:08 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7bdcbd0dc | ||
|
|
62ee7ad3dc | ||
|
|
65c879172f | ||
|
|
33c942551a | ||
|
|
36e4d9a2a2 | ||
|
|
aa1c8b3591 | ||
|
|
243bbb9709 | ||
|
|
78e7434a85 | ||
|
|
d1d093b87d | ||
|
|
ea00709aa1 | ||
|
|
219a6463f3 | ||
|
|
0ed89369a9 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,3 +1,15 @@
|
|||||||
|
## 1.17.0 2019-12-09 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Stop compiling mongodb-tools as it is back in Alpine:edge repositories
|
||||||
|
- Cleanup Code
|
||||||
|
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|||||||
90
Dockerfile
90
Dockerfile
@@ -1,59 +1,51 @@
|
|||||||
FROM tiredofit/mongo-builder as mongo-packages
|
|
||||||
|
|
||||||
FROM tiredofit/alpine:edge
|
FROM tiredofit/alpine:edge
|
||||||
LABEL maintainer="Dave Conroy (dave at tiredofit dot ca)"
|
LABEL maintainer="Dave Conroy (dave at tiredofit dot ca)"
|
||||||
|
|
||||||
### Copy Mongo Packages
|
|
||||||
COPY --from=mongo-packages / /usr/src/apk
|
|
||||||
|
|
||||||
### Set Environment Variables
|
### Set Environment Variables
|
||||||
ENV ENABLE_CRON=FALSE \
|
ENV ENABLE_CRON=FALSE \
|
||||||
ENABLE_SMTP=FALSE
|
ENABLE_SMTP=FALSE \
|
||||||
|
ENABLE_ZABBIX=FALSE \
|
||||||
|
ZABBIX_HOSTNAME=db-backup
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
RUN set -ex && \
|
RUN set -ex && \
|
||||||
echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
|
echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
|
||||||
apk update && \
|
apk update && \
|
||||||
apk upgrade && \
|
apk upgrade && \
|
||||||
apk add --virtual .db-backup-build-deps \
|
apk add -t .db-backup-build-deps \
|
||||||
build-base \
|
build-base \
|
||||||
bzip2-dev \
|
bzip2-dev \
|
||||||
git \
|
git \
|
||||||
xz-dev \
|
xz-dev \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
apk add -t .db-backup-run-deps \
|
apk add -t .db-backup-run-deps \
|
||||||
bzip2 \
|
bzip2 \
|
||||||
influxdb \
|
influxdb \
|
||||||
mariadb-client \
|
mariadb-client \
|
||||||
libressl \
|
mongodb-tools \
|
||||||
pigz \
|
libressl \
|
||||||
postgresql \
|
pigz \
|
||||||
postgresql-client \
|
postgresql \
|
||||||
redis \
|
postgresql-client \
|
||||||
xz \
|
redis \
|
||||||
&& \
|
xz \
|
||||||
apk add \
|
&& \
|
||||||
pixz@testing \
|
\
|
||||||
&& \
|
apk add \
|
||||||
|
pixz@testing \
|
||||||
## Locally Install Mongo Package
|
&& \
|
||||||
cd /usr/src/apk && \
|
\
|
||||||
apk add -t .db-backup-mongo-deps --allow-untrusted \
|
mkdir -p /usr/src/pbzip2 && \
|
||||||
mongodb-tools*.apk \
|
curl -ssL https://launchpad.net/pbzip2/1.1/1.1.13/+download/pbzip2-1.1.13.tar.gz | tar xvfz - --strip=1 -C /usr/src/pbzip2 && \
|
||||||
&& \
|
cd /usr/src/pbzip2 && \
|
||||||
\
|
make && \
|
||||||
cd /usr/src && \
|
make install && \
|
||||||
mkdir -p pbzip2 && \
|
\
|
||||||
curl -ssL https://launchpad.net/pbzip2/1.1/1.1.13/+download/pbzip2-1.1.13.tar.gz | tar xvfz - --strip=1 -C /usr/src/pbzip2 && \
|
|
||||||
cd pbzip2 && \
|
|
||||||
make && \
|
|
||||||
make install && \
|
|
||||||
\
|
|
||||||
### Cleanup
|
### Cleanup
|
||||||
rm -rf /usr/src/* && \
|
apk del .db-backup-build-deps && \
|
||||||
apk del .db-backup-build-deps && \
|
rm -rf /usr/src/* && \
|
||||||
rm -rf /tmp/* /var/cache/apk/*
|
rm -rf /tmp/* /var/cache/apk/*
|
||||||
|
|
||||||
### S6 Setup
|
### S6 Setup
|
||||||
ADD install /
|
ADD install /
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2016 Dave Conroy
|
Copyright (c) 2019 Dave Conroy
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
22
README.md
22
README.md
@@ -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)
|
||||||
@@ -6,14 +6,13 @@
|
|||||||
[](https://hub.docker.com/r/tiredofit/db-backup)
|
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||||
[](https://microbadger.com/images/tiredofit/db-backup)
|
[](https://microbadger.com/images/tiredofit/db-backup)
|
||||||
|
|
||||||
|
|
||||||
# Introduction
|
# Introduction
|
||||||
|
|
||||||
This will build a container for backing up multiple type of DB Servers
|
This will build a container for backing up multiple type of DB Servers
|
||||||
|
|
||||||
Currently backs up CouchDB, InfluxDB, MySQL, MongoDB Postgres, Redis, Rethink servers.
|
Currently backs up CouchDB, InfluxDB, MySQL, MongoDB Postgres, Redis, Rethink servers.
|
||||||
|
|
||||||
* dump to local filesystem
|
* dump to local filesystem
|
||||||
* select database user and password
|
* select database user and password
|
||||||
* backup all databases
|
* backup all databases
|
||||||
* choose to have an MD5 sum after backup for verification
|
* choose to have an MD5 sum after backup for verification
|
||||||
@@ -23,7 +22,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) 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)
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ This Container uses Alpine:Edge as a base.
|
|||||||
- [Quick Start](#quick-start)
|
- [Quick Start](#quick-start)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Data Volumes](#data-volumes)
|
- [Data Volumes](#data-volumes)
|
||||||
- [Environment Variables](#environmentvariables)
|
- [Environment Variables](#environmentvariables)
|
||||||
- [Maintenance](#maintenance)
|
- [Maintenance](#maintenance)
|
||||||
- [Shell Access](#shell-access)
|
- [Shell Access](#shell-access)
|
||||||
|
|
||||||
@@ -51,12 +50,12 @@ You must have a working DB server or container available for this to work proper
|
|||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
Automated builds of the image are available on [Docker Hub](https://hub.docker.com/r/tiredofit/db-backup) and is the recommended
|
Automated builds of the image are available on [Docker Hub](https://hub.docker.com/r/tiredofit/db-backup) and is the recommended
|
||||||
method of installation.
|
method of installation.
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull tiredofit/db-backup
|
docker pull tiredofit/db-backup:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
# Quick Start
|
# Quick Start
|
||||||
@@ -77,7 +76,7 @@ The following directories are used for configuration and can be mapped for persi
|
|||||||
| Directory | Description |
|
| Directory | Description |
|
||||||
|-----------|-------------|
|
|-----------|-------------|
|
||||||
| `/backup` | Backups |
|
| `/backup` | Backups |
|
||||||
|
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
@@ -87,11 +86,12 @@ Along with the Environment Variables from the [Base image](https://hub.docker.co
|
|||||||
| Parameter | Description |
|
| Parameter | Description |
|
||||||
|-----------|-------------|
|
|-----------|-------------|
|
||||||
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, or none `NONE` - Default `GZ`
|
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, or none `NONE` - Default `GZ`
|
||||||
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` `rethink`
|
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `pgsql` `mongo` `redis` `rethink`
|
||||||
| `DB_SERVER` | Server Hostname e.g. `mariadb`
|
| `DB_HOST` | Server Hostname e.g. `mariadb`
|
||||||
| `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`
|
||||||
@@ -109,7 +109,7 @@ Manual Backups can be perforemd by entering the container and typing `backup-now
|
|||||||
|
|
||||||
#### Shell Access
|
#### Shell Access
|
||||||
|
|
||||||
For debugging and maintenance purposes you may want access the containers shell.
|
For debugging and maintenance purposes you may want access the containers shell.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker exec -it (whatever your container name is e.g.) db-backup bash
|
docker exec -it (whatever your container name is e.g.) db-backup bash
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ services:
|
|||||||
links:
|
links:
|
||||||
- example-db
|
- example-db
|
||||||
volumes:
|
volumes:
|
||||||
- ./backups:/backups
|
- ./backups:/backup
|
||||||
environment:
|
environment:
|
||||||
- DB_TYPE=mariadb
|
- DB_TYPE=mariadb
|
||||||
- DB_HOST=example-db
|
- DB_HOST=example-db
|
||||||
@@ -32,7 +32,6 @@ services:
|
|||||||
- MD5=TRUE
|
- MD5=TRUE
|
||||||
- COMPRESSION=XZ
|
- COMPRESSION=XZ
|
||||||
- SPLIT_DB=FALSE
|
- SPLIT_DB=FALSE
|
||||||
|
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ fi
|
|||||||
### Functions
|
### Functions
|
||||||
function backup_couch() {
|
function backup_couch() {
|
||||||
TARGET=couch_${DBNAME}_${DBHOST}_${now}.txt
|
TARGET=couch_${DBNAME}_${DBHOST}_${now}.txt
|
||||||
curl -X GET http://${DBHOST}:${DBPORT}/${DBNAME}/ all docs? include docs=true >${TMPDIR}/${TARGET}
|
curl -X GET http://${DBHOST}:${DBPORT}/${DBNAME}/_all_docs?include_docs=true >${TMPDIR}/${TARGET}
|
||||||
generate_md5
|
generate_md5
|
||||||
compression
|
compression
|
||||||
move_backup
|
move_backup
|
||||||
@@ -105,20 +105,20 @@ function backup_couch() {
|
|||||||
|
|
||||||
function backup_mysql() {
|
function backup_mysql() {
|
||||||
if [ "$SPLIT_DB" = "TRUE" ] || [ "$SPLIT_DB" = "true" ]; then
|
if [ "$SPLIT_DB" = "TRUE" ] || [ "$SPLIT_DB" = "true" ]; then
|
||||||
DATABASES=`mysql -h $DBHOST -u$DBUSER -p$DBPASS --batch -e "SHOW DATABASES;" | grep -v Database|grep -v schema`
|
DATABASES=`mysql -h $DBHOST -P $DBPORT -u$DBUSER -p$DBPASS --batch -e "SHOW DATABASES;" | grep -v Database|grep -v schema`
|
||||||
|
|
||||||
for db in $DATABASES; do
|
for db in $DATABASES; do
|
||||||
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
|
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
|
||||||
echo "** [db-backup] Dumping database: $db"
|
echo "** [db-backup] Dumping database: $db"
|
||||||
TARGET=mysql_${db}_${DBHOST}_${now}.sql
|
TARGET=mysql_${db}_${DBHOST}_${now}.sql
|
||||||
mysqldump --max-allowed-packet=512M -h $DBHOST -u$DBUSER ${MYSQL_PASS_STR} --databases $db > ${TMPDIR}/${TARGET}
|
mysqldump --max-allowed-packet=512M -h $DBHOST -P $DBPORT -u$DBUSER ${MYSQL_PASS_STR} --databases $db > ${TMPDIR}/${TARGET}
|
||||||
generate_md5
|
generate_md5
|
||||||
compression
|
compression
|
||||||
move_backup
|
move_backup
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
mysqldump --max-allowed-packet=512M -A -h $DBHOST -u$DBUSER ${MYSQL_PASS_STR} > ${TMPDIR}/${TARGET}
|
mysqldump --max-allowed-packet=512M -A -h $DBHOST -P $DBPORT -u$DBUSER ${MYSQL_PASS_STR} > ${TMPDIR}/${TARGET}
|
||||||
generate_md5
|
generate_md5
|
||||||
compression
|
compression
|
||||||
move_backup
|
move_backup
|
||||||
@@ -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