mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 13:44:08 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bd534258e | ||
|
|
48bea7aeee | ||
|
|
c3179d58ba | ||
|
|
fcafa1753d | ||
|
|
d74a516967 | ||
|
|
b0a5fafc4c |
@@ -1,3 +1,11 @@
|
||||
## 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)
|
||||
@@ -60,3 +68,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
|
||||
|
||||
@@ -84,6 +84,7 @@ fi
|
||||
"redis" | "REDIS" )
|
||||
DBTYPE=redis
|
||||
DBPORT=${DB_PORT:-6379}
|
||||
[[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${DBPASS}"
|
||||
;;
|
||||
"rethink" | "RETHINK" )
|
||||
DBTYPE=rethink
|
||||
@@ -103,9 +104,9 @@ function backup_couch() {
|
||||
}
|
||||
|
||||
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`
|
||||
|
||||
|
||||
for db in $DATABASES; do
|
||||
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
|
||||
echo "** [db-backup] Dumping database: $db"
|
||||
@@ -137,7 +138,7 @@ function backup_mongo() {
|
||||
mongodump --out ${TMPDIR}/${TARGET} --host ${DBHOST} --port ${DBPORT} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
||||
cd ${TMPDIR}
|
||||
tar cf ${TARGET}.tar ${TARGET}/*
|
||||
TARGET=${TARGET}.tar
|
||||
TARGET=${TARGET}.tar
|
||||
generate_md5
|
||||
compression
|
||||
move_backup
|
||||
@@ -166,13 +167,13 @@ function backup_pgsql() {
|
||||
|
||||
function backup_redis() {
|
||||
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"
|
||||
sleep 10
|
||||
try=5
|
||||
while [ $try -gt 0 ] ; do
|
||||
saved=$(echo 'info Persistence' | redis-cli -h ${DBHOST} -p ${DBPORT} | 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"}')
|
||||
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} ${REDIS_PASS_STR} | awk '/rdb_last_bgsave_status:ok/{print "ok"}')
|
||||
if [[ "$saved" = "saved" ]] && [[ "$ok" = "ok" ]]; then
|
||||
echo "** [db-backup] Redis Backup Complete"
|
||||
fi
|
||||
@@ -186,7 +187,7 @@ function backup_redis() {
|
||||
}
|
||||
|
||||
function backup_rethink() {
|
||||
TARGET=rethink_${db}_${DBHOST}_${now}.tar.gz
|
||||
TARGET=rethink_${db}_${DBHOST}_${now}.tar.gz
|
||||
echo "** [db-backup] Dumping rethink Database: $db"
|
||||
rethinkdb dump -f ${TMPDIR}/${TARGET} -c ${DBHOST}:${DBPORT} ${RETHINK_PASS_STR} ${RETHINK_DB_STR}
|
||||
move_backup
|
||||
@@ -212,7 +213,7 @@ function compression() {
|
||||
}
|
||||
|
||||
function generate_md5() {
|
||||
if [ "$MD5" = "TRUE" ] || [ "$MD5" = "true" ] ; then
|
||||
if [ "$MD5" = "TRUE" ] || [ "$MD5" = "true" ] ; then
|
||||
cd $TMPDIR
|
||||
md5sum ${TARGET} > ${TARGET}.md5
|
||||
fi
|
||||
@@ -225,13 +226,13 @@ function move_backup() {
|
||||
}
|
||||
|
||||
|
||||
### Container Startup
|
||||
### Container Startup
|
||||
echo '** [db-backup] Initialized at at '$(date)
|
||||
|
||||
### Wait for Next time to start backup
|
||||
current_time=$(date +"%s")
|
||||
today=$(date +"%Y%m%d")
|
||||
|
||||
|
||||
if [[ $DB_DUMP_BEGIN =~ ^\+(.*)$ ]]; then
|
||||
waittime=$(( ${BASH_REMATCH[1]} * 60 ))
|
||||
else
|
||||
@@ -279,12 +280,12 @@ echo '** [db-backup] Initialized at at '$(date)
|
||||
;;
|
||||
esac
|
||||
|
||||
### Zabbix
|
||||
### Zabbix
|
||||
if [ "$ENABLE_ZABBIX" = "TRUE" ] || [ "$ENABLE_ZABBIX" = "true" ]; then
|
||||
zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k dbbackup.size -o `stat -c%s ${DB_DUMP_TARGET}/${TARGET}`
|
||||
zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k dbbackup.datetime -o `date -r ${DB_DUMP_TARGET}/${TARGET} +'%s'`
|
||||
fi
|
||||
|
||||
|
||||
### Automatic Cleanup
|
||||
if [[ -n "$DB_CLEANUP_TIME" ]]; then
|
||||
find $DB_DUMP_TARGET/ -mmin +$DB_CLEANUP_TIME -iname "$DBTYPE_$DBNAME_*.*" -exec rm {} \;
|
||||
|
||||
Reference in New Issue
Block a user