mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-21 13:23:12 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcafa1753d | ||
|
|
d74a516967 | ||
|
|
b0a5fafc4c | ||
|
|
9051ba559a | ||
|
|
bf672c0fda | ||
|
|
9993ad2970 | ||
|
|
dc17d60b7b | ||
|
|
49356629fe | ||
|
|
b938c8a761 | ||
|
|
5807ba07e3 | ||
|
|
96f3120e35 | ||
|
|
af5c6198ce |
22
CHANGELOG.md
22
CHANGELOG.md
@@ -1,3 +1,24 @@
|
||||
## 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
|
||||
@@ -43,3 +64,4 @@
|
||||
|
||||
* Initial Release
|
||||
* Alpine:Edge
|
||||
|
||||
|
||||
44
Dockerfile
44
Dockerfile
@@ -1,6 +1,11 @@
|
||||
FROM tiredofit/mongo-builder as mongo-packages
|
||||
|
||||
FROM tiredofit/alpine:edge
|
||||
LABEL maintainer="Dave Conroy (dave at tiredofit dot ca)"
|
||||
|
||||
### Copy Mongo Packages
|
||||
COPY --from=mongo-packages / /usr/src/apk
|
||||
|
||||
### Set Environment Variables
|
||||
ENV ENABLE_CRON=FALSE \
|
||||
ENABLE_SMTP=FALSE
|
||||
@@ -17,9 +22,9 @@ LABEL maintainer="Dave Conroy (dave at tiredofit dot ca)"
|
||||
xz-dev \
|
||||
&& \
|
||||
\
|
||||
apk add --virtual .db-backup-run-deps \
|
||||
apk add -t .db-backup-run-deps \
|
||||
bzip2 \
|
||||
mongodb-tools \
|
||||
influxdb \
|
||||
mariadb-client \
|
||||
libressl \
|
||||
pigz \
|
||||
@@ -28,22 +33,27 @@ LABEL maintainer="Dave Conroy (dave at tiredofit dot ca)"
|
||||
redis \
|
||||
xz \
|
||||
&& \
|
||||
apk add \
|
||||
influxdb@testing \
|
||||
pixz@testing \
|
||||
apk add \
|
||||
pixz@testing \
|
||||
&& \
|
||||
\
|
||||
cd /usr/src && \
|
||||
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
|
||||
rm -rf /usr/src/* && \
|
||||
apk del .db-backup-build-deps && \
|
||||
rm -rf /tmp/* /var/cache/apk/*
|
||||
|
||||
## Locally Install Mongo Package
|
||||
cd /usr/src/apk && \
|
||||
apk add -t .db-backup-mongo-deps --allow-untrusted \
|
||||
mongodb-tools*.apk \
|
||||
&& \
|
||||
\
|
||||
cd /usr/src && \
|
||||
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
|
||||
rm -rf /usr/src/* && \
|
||||
apk del .db-backup-build-deps && \
|
||||
rm -rf /tmp/* /var/cache/apk/*
|
||||
|
||||
### S6 Setup
|
||||
ADD install /
|
||||
|
||||
@@ -86,6 +86,7 @@ Along with the Environment Variables from the [Base image](https://hub.docker.co
|
||||
|
||||
| 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_SERVER` | Server Hostname e.g. `mariadb`
|
||||
| `DB_NAME` | Schema Name e.g. `database`
|
||||
@@ -95,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
|
||||
| | 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
|
||||
| `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. Supports three formats |
|
||||
| | 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.
|
||||
| `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`
|
||||
| `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` |
|
||||
| `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
|
||||
|
||||
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
|
||||
|
||||
if [ $1 != "NOW" ]; then
|
||||
if [ "$1" != "NOW" ]; then
|
||||
sleep 10
|
||||
fi
|
||||
|
||||
@@ -37,7 +37,7 @@ MD5=${MD5:-TRUE}
|
||||
SPLIT_DB=${SPLIT_DB:-FALSE}
|
||||
TMPDIR=/tmp/backups
|
||||
|
||||
if [ $1 = "NOW" ]; then
|
||||
if [ "$1" = "NOW" ]; then
|
||||
DB_DUMP_BEGIN=+0
|
||||
MANUAL=TRUE
|
||||
fi
|
||||
@@ -50,7 +50,7 @@ if [ "$PARALLEL_COMPRESSION" = "TRUE " ]; then
|
||||
else
|
||||
BZIP="bzip2"
|
||||
GZIP="gzip"
|
||||
XZIP=="xz"
|
||||
XZIP="xz"
|
||||
fi
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ function backup_mysql() {
|
||||
|
||||
function backup_influx() {
|
||||
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
|
||||
compression
|
||||
move_backup
|
||||
@@ -146,7 +146,7 @@ function backup_mongo() {
|
||||
function backup_pgsql() {
|
||||
if [ "$SPLIT_DB" = "TRUE" ] || [ "$SPLIT_DB" = "true" ]; then
|
||||
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
|
||||
echo "** [db-backup] Dumping database: $db"
|
||||
TARGET=pgsql_${db}_${DBHOST}_${now}.sql
|
||||
@@ -157,7 +157,7 @@ function backup_pgsql() {
|
||||
done
|
||||
else
|
||||
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
|
||||
compression
|
||||
move_backup
|
||||
@@ -298,4 +298,4 @@ echo '** [db-backup] Initialized at at '$(date)
|
||||
fi
|
||||
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user