mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 13:44:08 +01:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bd534258e | ||
|
|
48bea7aeee | ||
|
|
c3179d58ba | ||
|
|
fcafa1753d | ||
|
|
d74a516967 | ||
|
|
b0a5fafc4c | ||
|
|
9051ba559a | ||
|
|
bf672c0fda | ||
|
|
9993ad2970 | ||
|
|
dc17d60b7b | ||
|
|
49356629fe | ||
|
|
b938c8a761 | ||
|
|
5807ba07e3 | ||
|
|
96f3120e35 | ||
|
|
af5c6198ce | ||
|
|
5d1ae25828 |
34
CHANGELOG.md
34
CHANGELOG.md
@@ -1,3 +1,36 @@
|
|||||||
|
## 1.15 - 2019-05-24 - <claudioaltamura @ github>
|
||||||
|
|
||||||
|
* Added abaility to backup password protected Redis Hosts
|
||||||
|
|
||||||
|
## 1.14 - 2019-04-20 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
* Switch to using locally built mongodb-tools from tiredofit/mongo-builder due to Alpine removing precompiled packages from repositories
|
||||||
|
|
||||||
|
## 1.13 - 2019-03-09 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
* Fixed Postgres backup without SPLIT_DB enabled (credit MelwinKfr@github)
|
||||||
|
* Added DB_PORT reference to properly backup Postgres with non default ports (thanks Maxximus007@github)
|
||||||
|
|
||||||
|
## 1.12 - 2019-03-01 - <stevetodorov at github>
|
||||||
|
|
||||||
|
* Fix for XZ Compression failing
|
||||||
|
|
||||||
|
## 1.11 - 2018-11-19 - <skylord123 at github>
|
||||||
|
|
||||||
|
* Fix for Urnary Operator Error
|
||||||
|
|
||||||
|
## 1.10 - 2018-11-19 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
* Fix for InfluxDB for backing up and supporting DB_PORT variable - Thanks skylord123@github
|
||||||
|
|
||||||
|
## 1.9 - 2018-11-03 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
* Switch from OpenSSL to LibreSSL
|
||||||
|
|
||||||
|
## 1.8 - 2018-07-18 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
* Fix warnings on startup related to 1.7 Changes
|
||||||
|
|
||||||
## 1.7 - 2018-06-06 - <dave at tiredofit dot ca>
|
## 1.7 - 2018-06-06 - <dave at tiredofit dot ca>
|
||||||
|
|
||||||
* Added ability for Manual Backup (enter container and type `backup-now`)
|
* Added ability for Manual Backup (enter container and type `backup-now`)
|
||||||
@@ -35,3 +68,4 @@
|
|||||||
|
|
||||||
* Initial Release
|
* Initial Release
|
||||||
* Alpine:Edge
|
* Alpine:Edge
|
||||||
|
|
||||||
|
|||||||
61
Dockerfile
61
Dockerfile
@@ -1,50 +1,59 @@
|
|||||||
|
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
|
||||||
|
|
||||||
### 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 --virtual .db-backup-build-deps \
|
||||||
build-base \
|
build-base \
|
||||||
bzip2-dev \
|
bzip2-dev \
|
||||||
git \
|
git \
|
||||||
xz-dev \
|
xz-dev \
|
||||||
; \
|
&& \
|
||||||
\
|
\
|
||||||
apk add --virtual .db-backup-run-deps \
|
apk add -t .db-backup-run-deps \
|
||||||
bzip2 \
|
bzip2 \
|
||||||
mongodb-tools \
|
influxdb \
|
||||||
mariadb-client \
|
mariadb-client \
|
||||||
openssl \
|
libressl \
|
||||||
pigz \
|
pigz \
|
||||||
postgresql \
|
postgresql \
|
||||||
postgresql-client \
|
postgresql-client \
|
||||||
redis \
|
redis \
|
||||||
xz \
|
xz \
|
||||||
; \
|
&& \
|
||||||
\
|
apk add \
|
||||||
apk add \
|
pixz@testing \
|
||||||
influxdb@testing \
|
&& \
|
||||||
pixz@testing \
|
|
||||||
; \
|
## Locally Install Mongo Package
|
||||||
\
|
cd /usr/src/apk && \
|
||||||
cd /usr/src ; \
|
apk add -t .db-backup-mongo-deps --allow-untrusted \
|
||||||
mkdir -p 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 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 && \
|
||||||
# Cleanup
|
cd pbzip2 && \
|
||||||
rm -rf /usr/src/* ; \
|
make && \
|
||||||
apk del .db-backup-build-deps ; \
|
make install && \
|
||||||
rm -rf /tmp/* /var/cache/apk/*
|
\
|
||||||
|
### Cleanup
|
||||||
|
rm -rf /usr/src/* && \
|
||||||
|
apk del .db-backup-build-deps && \
|
||||||
|
rm -rf /tmp/* /var/cache/apk/*
|
||||||
|
|
||||||
### S6 Setup
|
### S6 Setup
|
||||||
ADD install /
|
ADD install /
|
||||||
|
|||||||
23
README.md
23
README.md
@@ -1,5 +1,12 @@
|
|||||||
# tiredofit/db-backup
|
# tiredofit/db-backup
|
||||||
|
|
||||||
|
|
||||||
|
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||||
|
[](https://hub.docker.com/r/tiredofit/db-backup)
|
||||||
|
[](https://hub.docker.com/r/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
|
||||||
@@ -16,8 +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 a [customized version of](https://hub.docker.com/r/tiredofit/alpine) alpine:edge as a base.
|
This Container uses Alpine:Edge as a base.
|
||||||
|
|
||||||
|
|
||||||
[Changelog](CHANGELOG.md)
|
[Changelog](CHANGELOG.md)
|
||||||
|
|
||||||
@@ -45,7 +51,8 @@ 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/tiredofit/db-backup) and is the recommended method of installation.
|
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.
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -79,8 +86,9 @@ 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`
|
||||||
| `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_HOST` | Server Hostname e.g. `mariadb`
|
| `DB_SERVER` | 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
|
||||||
@@ -88,14 +96,11 @@ Along with the Environment Variables from the [Base image](https://hub.docker.co
|
|||||||
| `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`
|
||||||
| | Relative +MM, i.e. how many minutes after starting the container, e.g. `+0` (immediate), `+10` (in 10 minutes), or `+90` in an hour and a half
|
| | Relative +MM, i.e. how many minutes after starting the container, e.g. `+0` (immediate), `+10` (in 10 minutes), or `+90` in an hour and a half
|
||||||
| `DB_DUMP_DEBUG` | If set to `true`, print copious shell script messages to the container log. Otherwise only basic messages are printed.
|
|
||||||
| `DB_DUMP_TARGET` | Where to put the dump file, should be a directory. Default - `/backups` |
|
|
||||||
| | Local If the value of `DB_DUMP_TARGET` starts with a `/` character, will dump to a local path, which should be volume-mounted.
|
|
||||||
| `DB_CLEANUP_TIME` | Value in minutes to delete old backups (only fired when dump freqency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything.
|
| `DB_CLEANUP_TIME` | Value in minutes to delete old backups (only fired when dump freqency fires). 1440 would delete anything above 1 day old. You don't need to set this variable if you want to hold onto everything.
|
||||||
| `COMPRESSION` | Use either Gzip `GZ`, Bzip2 `BZ`, XZip `XZ`, or none `NONE` - Default `GZ`
|
| `DEBUG_MODE` | If set to `true`, print copious shell script messages to the container log. Otherwise only basic messages are printed.
|
||||||
| `MD5` | Generate MD5 Sum in Directory, `TRUE` or `FALSE` - Default `TRUE`
|
| `MD5` | Generate MD5 Sum in Directory, `TRUE` or `FALSE` - Default `TRUE`
|
||||||
| `SPLIT_DB` | If using root as username and multiple DBs on system, set to TRUE to create Seperate DB Backups instead of all in one. - Default `FALSE` |
|
|
||||||
| `PARALLEL_COMPRESSION` | Use multiple cores when compressing backups `TRUE` or `FALSE` - Default `TRUE` |
|
| `PARALLEL_COMPRESSION` | Use multiple cores when compressing backups `TRUE` or `FALSE` - Default `TRUE` |
|
||||||
|
| `SPLIT_DB` | If using root as username and multiple DBs on system, set to TRUE to create Seperate DB Backups instead of all in one. - Default `FALSE` |
|
||||||
|
|
||||||
|
|
||||||
## Maintenance
|
## Maintenance
|
||||||
|
|||||||
4
install/etc/cont-finish.d/10-db-backup
Normal file
4
install/etc/cont-finish.d/10-db-backup
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/with-contenv bash
|
||||||
|
|
||||||
|
pkill bash
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
date >/dev/null
|
date >/dev/null
|
||||||
|
|
||||||
if [ $1 != "NOW" ]; then
|
if [ "$1" != "NOW" ]; then
|
||||||
sleep 10
|
sleep 10
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ MD5=${MD5:-TRUE}
|
|||||||
SPLIT_DB=${SPLIT_DB:-FALSE}
|
SPLIT_DB=${SPLIT_DB:-FALSE}
|
||||||
TMPDIR=/tmp/backups
|
TMPDIR=/tmp/backups
|
||||||
|
|
||||||
if [ $1 = "NOW" ]; then
|
if [ "$1" = "NOW" ]; then
|
||||||
DB_DUMP_BEGIN=+0
|
DB_DUMP_BEGIN=+0
|
||||||
MANUAL=TRUE
|
MANUAL=TRUE
|
||||||
fi
|
fi
|
||||||
@@ -50,7 +50,7 @@ if [ "$PARALLEL_COMPRESSION" = "TRUE " ]; then
|
|||||||
else
|
else
|
||||||
BZIP="bzip2"
|
BZIP="bzip2"
|
||||||
GZIP="gzip"
|
GZIP="gzip"
|
||||||
XZIP=="xz"
|
XZIP="xz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -84,6 +84,7 @@ fi
|
|||||||
"redis" | "REDIS" )
|
"redis" | "REDIS" )
|
||||||
DBTYPE=redis
|
DBTYPE=redis
|
||||||
DBPORT=${DB_PORT:-6379}
|
DBPORT=${DB_PORT:-6379}
|
||||||
|
[[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${DBPASS}"
|
||||||
;;
|
;;
|
||||||
"rethink" | "RETHINK" )
|
"rethink" | "RETHINK" )
|
||||||
DBTYPE=rethink
|
DBTYPE=rethink
|
||||||
@@ -126,7 +127,7 @@ function backup_mysql() {
|
|||||||
|
|
||||||
function backup_influx() {
|
function backup_influx() {
|
||||||
for DB in $DB_NAME; do
|
for DB in $DB_NAME; do
|
||||||
influxd backup -database $DB -host {DBHOST} ${TMPDIR}/${TARGET}
|
influxd backup -database $DB -host ${DBHOST}:${DBPORT} ${TMPDIR}/${TARGET}
|
||||||
generate_md5
|
generate_md5
|
||||||
compression
|
compression
|
||||||
move_backup
|
move_backup
|
||||||
@@ -146,7 +147,7 @@ function backup_mongo() {
|
|||||||
function backup_pgsql() {
|
function backup_pgsql() {
|
||||||
if [ "$SPLIT_DB" = "TRUE" ] || [ "$SPLIT_DB" = "true" ]; then
|
if [ "$SPLIT_DB" = "TRUE" ] || [ "$SPLIT_DB" = "true" ]; then
|
||||||
export PGPASSWORD=${DBPASS}
|
export PGPASSWORD=${DBPASS}
|
||||||
DATABASES=`psql -h $DBHOST -U $DBUSER -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' `
|
DATABASES=`psql -h $DBHOST -U $DBUSER -p ${DBPORT} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' `
|
||||||
for db in $DATABASES; do
|
for db in $DATABASES; do
|
||||||
echo "** [db-backup] Dumping database: $db"
|
echo "** [db-backup] Dumping database: $db"
|
||||||
TARGET=pgsql_${db}_${DBHOST}_${now}.sql
|
TARGET=pgsql_${db}_${DBHOST}_${now}.sql
|
||||||
@@ -157,7 +158,7 @@ function backup_pgsql() {
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
export PGPASSWORD=${DBPASS}
|
export PGPASSWORD=${DBPASS}
|
||||||
pg_dump -h ${DBHOST} -U ${DBUSER} $db > ${TMPDIR}/${TARGET}
|
pg_dump -h ${DBHOST} -U ${DBUSER} -p ${DBPORT} ${DBNAME} > ${TMPDIR}/${TARGET}
|
||||||
generate_md5
|
generate_md5
|
||||||
compression
|
compression
|
||||||
move_backup
|
move_backup
|
||||||
@@ -166,13 +167,13 @@ function backup_pgsql() {
|
|||||||
|
|
||||||
function backup_redis() {
|
function backup_redis() {
|
||||||
TARGET=redis_${db}_${DBHOST}_${now}.rdb
|
TARGET=redis_${db}_${DBHOST}_${now}.rdb
|
||||||
echo bgsave | redis-cli -h ${DBHOST} -p ${DBPORT} --rdb ${TMPDIR}/${TARGET}
|
echo bgsave | redis-cli -h ${DBHOST} -p ${DBPORT} ${REDIS_PASS_STR} --rdb ${TMPDIR}/${TARGET}
|
||||||
echo "** [db-backup] Dumping Redis - Flushing Redis Cache First"
|
echo "** [db-backup] Dumping Redis - Flushing Redis Cache First"
|
||||||
sleep 10
|
sleep 10
|
||||||
try=5
|
try=5
|
||||||
while [ $try -gt 0 ] ; do
|
while [ $try -gt 0 ] ; do
|
||||||
saved=$(echo 'info Persistence' | redis-cli -h ${DBHOST} -p ${DBPORT} | awk '/rdb_bgsave_in_progress:0/{print "saved"}')
|
saved=$(echo 'info Persistence' | redis-cli -h ${DBHOST} -p ${DBPORT} ${REDIS_PASS_STR} | awk '/rdb_bgsave_in_progress:0/{print "saved"}')
|
||||||
ok=$(echo 'info Persistence' | redis-cli -h ${DBHOST} -p ${DBPORT} | awk '/rdb_last_bgsave_status:ok/{print "ok"}')
|
ok=$(echo 'info Persistence' | redis-cli -h ${DBHOST} -p ${DBPORT} ${REDIS_PASS_STR} | awk '/rdb_last_bgsave_status:ok/{print "ok"}')
|
||||||
if [[ "$saved" = "saved" ]] && [[ "$ok" = "ok" ]]; then
|
if [[ "$saved" = "saved" ]] && [[ "$ok" = "ok" ]]; then
|
||||||
echo "** [db-backup] Redis Backup Complete"
|
echo "** [db-backup] Redis Backup Complete"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user