Compare commits

...

9 Commits
1.16 ... 1.18.1

Author SHA1 Message Date
Dave Conroy
e6009e7a1e Release 1.18.1 - See CHANGELOG.md 2020-03-14 07:59:31 -07:00
Dave Conroy
06b6e685c7 Support new tiredofit/alpine base image 2019-12-30 07:40:13 -08:00
Dave Conroy
d7bdcbd0dc Release 1.17.0 - See CHANGELOG.md 2019-12-09 13:58:11 -08:00
Dave Conroy
62ee7ad3dc Update README.md 2019-10-19 09:09:25 -07:00
Dave Conroy
65c879172f Fix docker-compose.yml example 2019-10-19 09:08:20 -07:00
Dave Conroy
33c942551a Merge pull request #18 from alwynpan/1.16.1
Fix couchdb backup endpoint; Set ENABLE_ZABBIX to FALSE by default
2019-10-01 18:22:55 -07:00
Yao (Alwyn) Pan
36e4d9a2a2 Fix couchdb backup endpoint; Set ENABLE_ZABBIX to FALSE by default 2019-10-02 10:27:26 +10:00
Dave Conroy
aa1c8b3591 Merge pull request #16 from tito/tito-patch-1
Fix usage of DB_PORT for single mariadb database
2019-09-16 07:12:54 -07:00
Mathieu Virbel
243bbb9709 Fix usage of DB_PORT for single mariadb database
Fixes #15
2019-09-16 12:32:16 +02:00
6 changed files with 105 additions and 87 deletions

View File

@@ -1,3 +1,40 @@
## 1.18.1 2020-03-14 <dave at tiredofit dot ca>
### Changed
- Allow for passwords with spaces in them for MariaDB / MySQL
## 1.18.0 2019-12-29 <dave at tiredofit dot ca>
### Added
- Update image to support new tiredofit/alpine base images
## 1.17.3 2019-12-12 <dave at tiredofit dot ca>
### Changed
- Quiet down Zabbix Agent
## 1.17.2 2019-12-12 <dave at tiredofit dot ca>
### Changed
- Re Enable ZABBIX
## 1.17.1 2019-12-10 <dave at tiredofit dot ca>
### Changed
- Fix spelling mistake in container initialization
## 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> ## 1.16 - 2019-06-16 - <dave at tiredofit dot ca>
* Check to see if Database Exists before performing backup * Check to see if Database Exists before performing backup

View File

@@ -1,21 +1,18 @@
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 \
@@ -26,6 +23,7 @@ COPY --from=mongo-packages / /usr/src/apk
bzip2 \ bzip2 \
influxdb \ influxdb \
mariadb-client \ mariadb-client \
mongodb-tools \
libressl \ libressl \
pigz \ pigz \
postgresql \ postgresql \
@@ -33,26 +31,20 @@ COPY --from=mongo-packages / /usr/src/apk
redis \ redis \
xz \ xz \
&& \ && \
\
apk add \ apk add \
pixz@testing \ pixz@testing \
&& \ && \
\ \
## Locally Install Mongo Package mkdir -p /usr/src/pbzip2 && \
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 && \ 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 && \ cd /usr/src/pbzip2 && \
make && \ make && \
make install && \ 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

View File

@@ -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

View File

@@ -6,7 +6,6 @@
[![Docker Stars](https://img.shields.io/docker/stars/tiredofit/db-backup.svg)](https://hub.docker.com/r/tiredofit/db-backup) [![Docker Stars](https://img.shields.io/docker/stars/tiredofit/db-backup.svg)](https://hub.docker.com/r/tiredofit/db-backup)
[![Docker Layers](https://images.microbadger.com/badges/image/tiredofit/db-backup.svg)](https://microbadger.com/images/tiredofit/db-backup) [![Docker Layers](https://images.microbadger.com/badges/image/tiredofit/db-backup.svg)](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
@@ -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 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 * 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)

View File

@@ -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

View File

@@ -1,26 +1,17 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
source /assets/functions/*
PROCESS_NAME="db-backup"
date >/dev/null date >/dev/null
if [ "$1" != "NOW" ]; then if [ "$1" != "NOW" ]; then
sleep 10 sleep 10
fi fi
### Set Debug Mode
if [ "$DEBUG_MODE" = "TRUE" ] || [ "$DEBUG_MODE" = "true" ]; then
set -x
fi
### Sanity Test ### Sanity Test
if [ ! -n "$DB_TYPE" ]; then sanity_var DB_TYPE "Database Type"
echo '** [db-backup] ERROR: No Database Type Selected! ' sanity_var DB_HOST "Database Host"
exit 1
fi
if [ ! -n "$DB_HOST" ]; then
echo '** [db-backup] ERROR: No Database Host Entered! '
exit 1
fi
### Set Defaults ### Set Defaults
COMPRESSION=${COMPRESSION:-GZ} COMPRESSION=${COMPRESSION:-GZ}
@@ -74,7 +65,7 @@ fi
"mysql" | "MYSQL" | "mariadb" | "MARIADB") "mysql" | "MYSQL" | "mariadb" | "MARIADB")
DBTYPE=mysql DBTYPE=mysql
DBPORT=${DB_PORT:-3306} DBPORT=${DB_PORT:-3306}
[[ ( -n "${DB_PASS}" ) ]] && MYSQL_PASS_STR=" -p${DBPASS}" [[ ( -n "${DB_PASS}" ) ]] && MYSQL_PASS_STR=" -p'${DBPASS}'"
;; ;;
"postgres" | "postgresql" | "pgsql" | "POSTGRES" | "POSTGRESQL" | "PGSQL" ) "postgres" | "postgresql" | "pgsql" | "POSTGRES" | "POSTGRESQL" | "PGSQL" )
DBTYPE=pgsql DBTYPE=pgsql
@@ -97,7 +88,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,7 +96,7 @@ 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 -P $DBPORT -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
@@ -118,7 +109,7 @@ function backup_mysql() {
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
@@ -149,7 +140,7 @@ function backup_pgsql() {
export PGPASSWORD=${DBPASS} export PGPASSWORD=${DBPASS}
DATABASES=`psql -h $DBHOST -U $DBUSER -p ${DBPORT} -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" print_info "Dumping database: $db"
TARGET=pgsql_${db}_${DBHOST}_${now}.sql TARGET=pgsql_${db}_${DBHOST}_${now}.sql
pg_dump -h ${DBHOST} -p ${DBPORT} -U ${DBUSER} $db > ${TMPDIR}/${TARGET} pg_dump -h ${DBHOST} -p ${DBPORT} -U ${DBUSER} $db > ${TMPDIR}/${TARGET}
generate_md5 generate_md5
@@ -168,17 +159,17 @@ 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} ${REDIS_PASS_STR} --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" print_info "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} ${REDIS_PASS_STR} | 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} ${REDIS_PASS_STR} | 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" print_info "Redis Backup Complete"
fi fi
try=$((try - 1)) try=$((try - 1))
echo "** [db-backup] Redis Busy - Waiting and retrying in 5 seconds" print_info "Redis Busy - Waiting and retrying in 5 seconds"
sleep 5 sleep 5
done done
generate_md5 generate_md5
@@ -188,7 +179,7 @@ function backup_redis() {
function backup_rethink() { function backup_rethink() {
TARGET=rethink_${db}_${DBHOST}_${now}.tar.gz TARGET=rethink_${db}_${DBHOST}_${now}.tar.gz
echo "** [db-backup] Dumping rethink Database: $db" print_info "Dumping rethink Database: $db"
rethinkdb dump -f ${TMPDIR}/${TARGET} -c ${DBHOST}:${DBPORT} ${RETHINK_PASS_STR} ${RETHINK_DB_STR} rethinkdb dump -f ${TMPDIR}/${TARGET} -c ${DBHOST}:${DBPORT} ${RETHINK_PASS_STR} ${RETHINK_DB_STR}
move_backup move_backup
} }
@@ -201,7 +192,7 @@ function check_availability() {
while ! (nc -z ${DBHOST} ${DBPORT}) ; do while ! (nc -z ${DBHOST} ${DBPORT}) ; do
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
echo "** [db-backup] CouchDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "CouchDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)"
done done
;; ;;
"influx" ) "influx" )
@@ -209,7 +200,7 @@ function check_availability() {
while ! (nc -z ${DBHOST} ${DBPORT}) ; do while ! (nc -z ${DBHOST} ${DBPORT}) ; do
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
echo "** [db-backup] InfluxDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "InfluxDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)"
done done
;; ;;
"mongo" ) "mongo" )
@@ -217,7 +208,7 @@ function check_availability() {
while ! (nc -z ${DBHOST} ${DBPORT}) ; do while ! (nc -z ${DBHOST} ${DBPORT}) ; do
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
echo "** [db-backup] Mongo Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "Mongo Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)"
done done
;; ;;
"mysql" ) "mysql" )
@@ -230,7 +221,7 @@ function check_availability() {
: :
break break
fi fi
echo "** [db-backup] MySQL/MariaDB Server "$DBHOST" is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "MySQL/MariaDB Server "$DBHOST" is not accessible, retrying.. ($COUNTER seconds so far)"
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
done done
@@ -243,7 +234,7 @@ function check_availability() {
do do
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
echo "** [db-backup] Postgres Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "Postgres Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)"
done done
;; ;;
"redis" ) "redis" )
@@ -251,7 +242,7 @@ function check_availability() {
while ! (nc -z ${DBHOST} ${DBPORT}) ; do while ! (nc -z ${DBHOST} ${DBPORT}) ; do
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
echo "** [db-backup] Redis Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "Redis Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)"
done done
;; ;;
"rethink" ) "rethink" )
@@ -259,7 +250,7 @@ function check_availability() {
while ! (nc -z ${DBHOST} ${DBPORT}) ; do while ! (nc -z ${DBHOST} ${DBPORT}) ; do
sleep 5 sleep 5
let COUNTER+=5 let COUNTER+=5
echo "** [db-backup] RethinkDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)" print_warn "RethinkDB Host '"$DBHOST"' is not accessible, retrying.. ($COUNTER seconds so far)"
done done
;; ;;
esac esac
@@ -299,7 +290,7 @@ function move_backup() {
### Container Startup ### Container Startup
echo '** [db-backup] Initialized at at '$(date) print_info "Initialized on `date`"
### Wait for Next time to start backup ### Wait for Next time to start backup
current_time=$(date +"%s") current_time=$(date +"%s")
@@ -361,8 +352,8 @@ echo '** [db-backup] Initialized at at '$(date)
### Zabbix ### Zabbix
if [ "$ENABLE_ZABBIX" = "TRUE" ] || [ "$ENABLE_ZABBIX" = "true" ]; then 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}` silent 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'` silent zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k dbbackup.datetime -o `date -r ${DB_DUMP_TARGET}/${TARGET} +'%s'`
fi fi
### Automatic Cleanup ### Automatic Cleanup