mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 13:44:08 +01:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
738f7fad25 | ||
|
|
8c4733bf7f | ||
|
|
be4d8c0747 | ||
|
|
a13849df0a | ||
|
|
cb5347afe5 | ||
|
|
ca03c5369d | ||
|
|
3008d9125f | ||
|
|
19cf3d007f | ||
|
|
0bbf142349 | ||
|
|
1bc357866f | ||
|
|
b38ad7a5cc | ||
|
|
8bc02ee6c8 | ||
|
|
3e71c377c6 | ||
|
|
76a857239f |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,3 +1,33 @@
|
|||||||
|
## 2.3.1 2020-11-11 <bambi73@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Multiple Influx DB's not being backed up correctly
|
||||||
|
|
||||||
|
## 2.3.0 2020-10-15 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Microsoft SQL Server support (experimental)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Compiled Postgresql 13 from source to backup psql/13 hosts
|
||||||
|
|
||||||
|
## 2.2.2 2020-09-22 <tpansino@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Patch for 2.2.0 release fixing Docker Secrets Support. Was skipping password check.
|
||||||
|
|
||||||
|
## 2.2.1 2020-09-17 <alwynpan@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Ondemand/Manual backup with `backup-now` was throwing errors not being able to find a proper date
|
||||||
|
|
||||||
|
## 2.2.0 2020-09-14 <alwynpan@github>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Allow to use MariaDB and MongoDBs with no username and password while still allowing Docker Secrets
|
||||||
|
- Changed source of Alpine package repositories
|
||||||
|
|
||||||
|
|
||||||
## 2.1.1 2020-09-01 <zicklag@github>
|
## 2.1.1 2020-09-01 <zicklag@github>
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
118
Dockerfile
118
Dockerfile
@@ -1,15 +1,112 @@
|
|||||||
FROM tiredofit/alpine:edge
|
FROM tiredofit/alpine:edge
|
||||||
LABEL maintainer="Dave Conroy (dave at tiredofit dot ca)"
|
|
||||||
|
|
||||||
### Set Environment Variables
|
### Set Environment Variables
|
||||||
ENV ENABLE_CRON=FALSE \
|
ENV MSSQL_VERSION=17.5.2.1-1 \
|
||||||
|
ENABLE_CRON=FALSE \
|
||||||
ENABLE_SMTP=FALSE \
|
ENABLE_SMTP=FALSE \
|
||||||
ENABLE_ZABBIX=TRUE \
|
ENABLE_ZABBIX=TRUE \
|
||||||
ZABBIX_HOSTNAME=db-backup
|
ZABBIX_HOSTNAME=db-backup
|
||||||
|
|
||||||
### Dependencies
|
ENV LANG=en_US.utf8 \
|
||||||
|
PG_MAJOR=13 \
|
||||||
|
PG_VERSION=13.0 \
|
||||||
|
PGDATA=/var/lib/postgresql/data
|
||||||
|
|
||||||
|
|
||||||
|
### Create User Accounts
|
||||||
RUN set -ex && \
|
RUN set -ex && \
|
||||||
echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
|
addgroup -g 70 postgres && \
|
||||||
|
adduser -S -D -H -h /var/lib/postgresql -s /bin/sh -G postgres -u 70 postgres && \
|
||||||
|
mkdir -p /var/lib/postgresql && \
|
||||||
|
chown -R postgres:postgres /var/lib/postgresql && \
|
||||||
|
\
|
||||||
|
### Install Dependencies
|
||||||
|
apk update && \
|
||||||
|
apk upgrade && \
|
||||||
|
apk add \
|
||||||
|
openssl \
|
||||||
|
&& \
|
||||||
|
\
|
||||||
|
apk add --no-cache --virtual .postgres-build-deps \
|
||||||
|
bison \
|
||||||
|
build-base \
|
||||||
|
coreutils \
|
||||||
|
dpkg-dev \
|
||||||
|
dpkg \
|
||||||
|
flex \
|
||||||
|
gcc \
|
||||||
|
icu-dev \
|
||||||
|
libc-dev \
|
||||||
|
libedit-dev \
|
||||||
|
libxml2-dev \
|
||||||
|
libxslt-dev \
|
||||||
|
linux-headers \
|
||||||
|
make \
|
||||||
|
openssl-dev \
|
||||||
|
perl-utils \
|
||||||
|
perl-ipc-run \
|
||||||
|
util-linux-dev \
|
||||||
|
zlib-dev \
|
||||||
|
&& \
|
||||||
|
\
|
||||||
|
### Build Postgresql
|
||||||
|
mkdir -p /usr/src/postgresql && \
|
||||||
|
curl -sSL "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" | tar xvfj - --strip 1 -C /usr/src/postgresql && \
|
||||||
|
cd /usr/src/postgresql && \
|
||||||
|
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
|
||||||
|
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
|
||||||
|
awk '$1 == "#define" && $2 == "DEFAULT_PGSOCKET_DIR" && $3 == "\"/tmp\"" { $3 = "\"/var/run/postgresql\""; print; next } { print }' src/include/pg_config_manual.h > src/include/pg_config_manual.h.new && \
|
||||||
|
grep '/var/run/postgresql' src/include/pg_config_manual.h.new && \
|
||||||
|
mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h && \
|
||||||
|
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" && \
|
||||||
|
# explicitly update autoconf config.guess and config.sub so they support more arches/libcs
|
||||||
|
wget -O config/config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=7d3d27baf8107b630586c962c057e22149653deb' && \
|
||||||
|
wget -O config/config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=7d3d27baf8107b630586c962c057e22149653deb' && \
|
||||||
|
./configure \
|
||||||
|
--build="$gnuArch" \
|
||||||
|
--enable-integer-datetimes \
|
||||||
|
--enable-thread-safety \
|
||||||
|
--enable-tap-tests \
|
||||||
|
--disable-rpath \
|
||||||
|
--with-uuid=e2fs \
|
||||||
|
--with-gnu-ld \
|
||||||
|
--with-pgport=5432 \
|
||||||
|
--with-system-tzdata=/usr/share/zoneinfo \
|
||||||
|
--prefix=/usr/local \
|
||||||
|
--with-includes=/usr/local/include \
|
||||||
|
--with-libraries=/usr/local/lib \
|
||||||
|
--with-openssl \
|
||||||
|
--with-libxml \
|
||||||
|
--with-libxslt \
|
||||||
|
--with-icu \
|
||||||
|
&& \
|
||||||
|
\
|
||||||
|
make -j "$(nproc)" world && \
|
||||||
|
make install-world && \
|
||||||
|
make -C contrib install && \
|
||||||
|
runDeps="$( \
|
||||||
|
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
|
||||||
|
| tr ',' '\n' \
|
||||||
|
| sort -u \
|
||||||
|
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
||||||
|
)" && \
|
||||||
|
apk add -t .postgres-additional-deps \
|
||||||
|
$runDeps \
|
||||||
|
&& \
|
||||||
|
\
|
||||||
|
### Cleanup
|
||||||
|
apk del .postgres-build-deps && \
|
||||||
|
cd / && \
|
||||||
|
rm -rf \
|
||||||
|
/usr/src/postgresql \
|
||||||
|
/usr/local/share/doc \
|
||||||
|
/usr/local/share/man && \
|
||||||
|
find /usr/local -name '*.a' -delete && \
|
||||||
|
rm -rf /var/cache/apk/* && \
|
||||||
|
\
|
||||||
|
### Dependencies
|
||||||
|
set -ex && \
|
||||||
|
echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
|
||||||
apk update && \
|
apk update && \
|
||||||
apk upgrade && \
|
apk upgrade && \
|
||||||
apk add -t .db-backup-build-deps \
|
apk add -t .db-backup-build-deps \
|
||||||
@@ -19,24 +116,29 @@ RUN set -ex && \
|
|||||||
xz-dev \
|
xz-dev \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
apk add -t .db-backup-run-deps \
|
apk add --no-cache -t .db-backup-run-deps \
|
||||||
bzip2 \
|
bzip2 \
|
||||||
influxdb \
|
influxdb \
|
||||||
mariadb-client \
|
mariadb-client \
|
||||||
mongodb-tools \
|
mongodb-tools \
|
||||||
libressl \
|
libressl \
|
||||||
pigz \
|
pigz \
|
||||||
postgresql \
|
#postgresql \
|
||||||
postgresql-client \
|
#postgresql-client \
|
||||||
redis \
|
redis \
|
||||||
xz \
|
xz \
|
||||||
zstd \
|
zstd \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
apk add \
|
apk add --no-cache \
|
||||||
pixz@testing \
|
pixz@testing \
|
||||||
&& \
|
&& \
|
||||||
\
|
\
|
||||||
|
cd /usr/src && \
|
||||||
|
curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/msodbcsql17_${MSSQL_VERSION}_amd64.apk && \
|
||||||
|
curl -O https://download.microsoft.com/download/e/4/e/e4e67866-dffd-428c-aac7-8d28ddafb39b/mssql-tools_${MSSQL_VERSION}_amd64.apk && \
|
||||||
|
echo y | apk add --allow-untrusted msodbcsql17_${MSSQL_VERSION}_amd64.apk mssql-tools_${MSSQL_VERSION}_amd64.apk && \
|
||||||
|
\
|
||||||
mkdir -p /usr/src/pbzip2 && \
|
mkdir -p /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 && \
|
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 && \
|
cd /usr/src/pbzip2 && \
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
|||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
|
- [hub.docker.com/r/tiredofit/db-backup](#hubdockercomrtiredofitdb-backup)
|
||||||
- [Introduction](#introduction)
|
- [Introduction](#introduction)
|
||||||
- [Authors](#authors)
|
- [Authors](#authors)
|
||||||
- [Table of Contents](#table-of-contents)
|
- [Table of Contents](#table-of-contents)
|
||||||
@@ -90,8 +91,6 @@ The following directories are used for configuration and can be mapped for persi
|
|||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
*If you are trying to backup a database that doesn't have a user or a password (you should!) make sure you set `CONTAINER_ENABLE_DOCKER_SECRETS=FALSE`*
|
|
||||||
|
|
||||||
Along with the Environment Variables from the [Base image](https://hub.docker.com/r/tiredofit/alpine), below is the complete list of available options that can be used to customize your installation.
|
Along with the Environment Variables from the [Base image](https://hub.docker.com/r/tiredofit/alpine), below is the complete list of available options that can be used to customize your installation.
|
||||||
|
|
||||||
| Parameter | Description |
|
| Parameter | Description |
|
||||||
|
|||||||
@@ -14,8 +14,48 @@ fi
|
|||||||
sanity_var DB_TYPE "Database Type"
|
sanity_var DB_TYPE "Database Type"
|
||||||
sanity_var DB_HOST "Database Host"
|
sanity_var DB_HOST "Database Host"
|
||||||
|
|
||||||
|
### Set the Database Type
|
||||||
|
dbtype=${DB_TYPE}
|
||||||
|
|
||||||
|
case "$dbtype" in
|
||||||
|
"couch" | "couchdb" | "COUCH" | "COUCHDB" )
|
||||||
|
dbtype=couch
|
||||||
|
dbport=${DB_PORT:-5984}
|
||||||
file_env 'DB_USER'
|
file_env 'DB_USER'
|
||||||
file_env 'DB_PASS'
|
file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"influx" | "influxdb" | "INFLUX" | "INFLUXDB" )
|
||||||
|
dbtype=influx
|
||||||
|
dbport=${DB_PORT:-8088}
|
||||||
|
file_env 'DB_USER'
|
||||||
|
file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"mongo" | "mongodb" | "MONGO" | "MONGODB" )
|
||||||
|
dbtype=mongo
|
||||||
|
dbport=${DB_PORT:-27017}
|
||||||
|
[[ ( -n "${DB_USER}" ) || ( -n "${DB_USER_FILE}" ) ]] && file_env 'DB_USER'
|
||||||
|
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"mysql" | "MYSQL" | "mariadb" | "MARIADB")
|
||||||
|
dbtype=mysql
|
||||||
|
dbport=${DB_PORT:-3306}
|
||||||
|
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"mssql" | "MSSQL" | "microsoftsql" | "MICROSOFTSQL")
|
||||||
|
dbtype=mssql
|
||||||
|
dbport=${DB_PORT:-1433}
|
||||||
|
;;
|
||||||
|
"postgres" | "postgresql" | "pgsql" | "POSTGRES" | "POSTGRESQL" | "PGSQL" )
|
||||||
|
dbtype=pgsql
|
||||||
|
dbport=${DB_PORT:-5432}
|
||||||
|
[[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
"redis" | "REDIS" )
|
||||||
|
dbtype=redis
|
||||||
|
dbport=${DB_PORT:-6379}
|
||||||
|
[[ ( -n "${DB_PASS}" || ( -n "${DB_PASS_FILE}" ) ) ]] && file_env 'DB_PASS'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
### Set Defaults
|
### Set Defaults
|
||||||
BACKUP_LOCATION=${BACKUP_LOCATION:-"FILESYSTEM"}
|
BACKUP_LOCATION=${BACKUP_LOCATION:-"FILESYSTEM"}
|
||||||
@@ -27,7 +67,6 @@ DB_DUMP_TARGET=${DB_DUMP_TARGET:-/backup}
|
|||||||
dbhost=${DB_HOST}
|
dbhost=${DB_HOST}
|
||||||
dbname=${DB_NAME}
|
dbname=${DB_NAME}
|
||||||
dbpass=${DB_PASS}
|
dbpass=${DB_PASS}
|
||||||
dbtype=${DB_TYPE}
|
|
||||||
dbuser=${DB_USER}
|
dbuser=${DB_USER}
|
||||||
MD5=${MD5:-TRUE}
|
MD5=${MD5:-TRUE}
|
||||||
PARALLEL_COMPRESSION=${PARALLEL_COMPRESSION:-TRUE}
|
PARALLEL_COMPRESSION=${PARALLEL_COMPRESSION:-TRUE}
|
||||||
@@ -65,36 +104,20 @@ else
|
|||||||
zstd="zstd --rm -${COMPRESSION_LEVEL}"
|
zstd="zstd --rm -${COMPRESSION_LEVEL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Set the Database Type
|
### Set the Database Authentication Details
|
||||||
case "$dbtype" in
|
case "$dbtype" in
|
||||||
"couch" | "couchdb" | "COUCH" | "COUCHDB" )
|
"mongo" )
|
||||||
dbtype=couch
|
|
||||||
dbport=${DB_PORT:-5984}
|
|
||||||
;;
|
|
||||||
"influx" | "influxdb" | "INFLUX" | "INFLUXDB" )
|
|
||||||
dbtype=influx
|
|
||||||
dbport=${DB_PORT:-8088}
|
|
||||||
;;
|
|
||||||
"mongo" | "mongodb" | "MONGO" | "MONGODB" )
|
|
||||||
dbtype=mongo
|
|
||||||
dbport=${DB_PORT:-27017}
|
|
||||||
[[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${dbuser}"
|
[[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${dbuser}"
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${dbpass}"
|
[[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${dbpass}"
|
||||||
[[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${dbname}"
|
[[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${dbname}"
|
||||||
;;
|
;;
|
||||||
"mysql" | "MYSQL" | "mariadb" | "MARIADB")
|
"mysql" )
|
||||||
dbtype=mysql
|
|
||||||
dbport=${DB_PORT:-3306}
|
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${dbpass}
|
[[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${dbpass}
|
||||||
;;
|
;;
|
||||||
"postgres" | "postgresql" | "pgsql" | "POSTGRES" | "POSTGRESQL" | "PGSQL" )
|
"postgres" )
|
||||||
dbtype=pgsql
|
|
||||||
dbport=${DB_PORT:-5432}
|
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && POSTGRES_PASS_STR="PGPASSWORD=${dbpass}"
|
[[ ( -n "${DB_PASS}" ) ]] && POSTGRES_PASS_STR="PGPASSWORD=${dbpass}"
|
||||||
;;
|
;;
|
||||||
"redis" | "REDIS" )
|
"redis" )
|
||||||
dbtype=redis
|
|
||||||
dbport=${DB_PORT:-6379}
|
|
||||||
[[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${dbpass}"
|
[[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${dbpass}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -109,6 +132,42 @@ backup_couch() {
|
|||||||
move_backup
|
move_backup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backup_influx() {
|
||||||
|
if [ "${COMPRESSION}" = "NONE" ] || [ "${COMPRESSION}" = "none" ] || [ "${COMPRESSION}" = "FALSE" ] || [ "${COMPRESSION}" = "false" ] ; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
print_notice "Compressing InfluxDB backup with gzip"
|
||||||
|
influx_compression="-portable"
|
||||||
|
fi
|
||||||
|
for DB in $DB_NAME; do
|
||||||
|
target=influx_${DB}_${dbhost}_${now}
|
||||||
|
influxd backup ${influx_compression} -database $DB -host ${dbhost}:${dbport} ${tmpdir}/${target}
|
||||||
|
exit_code=$?
|
||||||
|
generate_md5
|
||||||
|
move_backup
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_mongo() {
|
||||||
|
if [ "${COMPRESSION}" = "NONE" ] || [ "${COMPRESSION}" = "none" ] || [ "${COMPRESSION}" = "FALSE" ] || [ "${COMPRESSION}" = "false" ] ; then
|
||||||
|
target=${dbtype}_${dbname}_${dbhost}_${now}.archive
|
||||||
|
else
|
||||||
|
print_notice "Compressing MongoDB backup with gzip"
|
||||||
|
target=${dbtype}_${dbname}_${dbhost}_${now}.archivegz
|
||||||
|
mongo_compression="--gzip"
|
||||||
|
fi
|
||||||
|
mongodump --archive=${tmpdir}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
||||||
|
exit_code=$?
|
||||||
|
cd ${tmpdir}
|
||||||
|
generate_md5
|
||||||
|
move_backup
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_mssql() {
|
||||||
|
target=mssql_${dbname}_${dbhost}_${now}.bak
|
||||||
|
/opt/mssql-tools/bin/sqlcmd -E -C -S ${dbhost}\,${dbport} -U ${dbuser} -P ${dbpass} –Q "BACKUP DATABASE \[${dbname}\] TO DISK = N'${tmpdir}/${target}' WITH NOFORMAT, NOINIT, NAME = '${dbname}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
|
||||||
|
}
|
||||||
|
|
||||||
backup_mysql() {
|
backup_mysql() {
|
||||||
if var_true "$SPLIT_DB" ; then
|
if var_true "$SPLIT_DB" ; then
|
||||||
DATABASES=$(mysql -h ${dbhost} -P $dbport -u$dbuser --batch -e "SHOW DATABASES;" | grep -v Database|grep -v schema)
|
DATABASES=$(mysql -h ${dbhost} -P $dbport -u$dbuser --batch -e "SHOW DATABASES;" | grep -v Database|grep -v schema)
|
||||||
@@ -133,36 +192,6 @@ backup_mysql() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_influx() {
|
|
||||||
if [ "${COMPRESSION}" = "NONE" ] || [ "${COMPRESSION}" = "none" ] || [ "${COMPRESSION}" = "FALSE" ] || [ "${COMPRESSION}" = "false" ] ; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
print_notice "Compressing InfluxDB backup with gzip"
|
|
||||||
influx_compression="-portable"
|
|
||||||
fi
|
|
||||||
for DB in $DB_NAME; do
|
|
||||||
influxd backup ${influx_compression} -database $DB -host ${dbhost}:${dbport} ${tmpdir}/${target}
|
|
||||||
exit_code=$?
|
|
||||||
generate_md5
|
|
||||||
move_backup
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
backup_mongo() {
|
|
||||||
if [ "${COMPRESSION}" = "NONE" ] || [ "${COMPRESSION}" = "none" ] || [ "${COMPRESSION}" = "FALSE" ] || [ "${COMPRESSION}" = "false" ] ; then
|
|
||||||
target=${dbtype}_${dbname}_${dbhost}_${now}.archive
|
|
||||||
else
|
|
||||||
print_notice "Compressing MongoDB backup with gzip"
|
|
||||||
target=${dbtype}_${dbname}_${dbhost}_${now}.archivegz
|
|
||||||
mongo_compression="--gzip"
|
|
||||||
fi
|
|
||||||
mongodump --archive=${tmpdir}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
|
||||||
exit_code=$?
|
|
||||||
cd ${tmpdir}
|
|
||||||
generate_md5
|
|
||||||
move_backup
|
|
||||||
}
|
|
||||||
|
|
||||||
backup_pgsql() {
|
backup_pgsql() {
|
||||||
if var_true $SPLIT_DB ; then
|
if var_true $SPLIT_DB ; then
|
||||||
export PGPASSWORD=${dbpass}
|
export PGPASSWORD=${dbpass}
|
||||||
@@ -249,6 +278,14 @@ check_availability() {
|
|||||||
(( COUNTER+=5 ))
|
(( COUNTER+=5 ))
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
"mssql" )
|
||||||
|
COUNTER=0
|
||||||
|
while ! (nc -z ${dbhost} ${dbport}) ; do
|
||||||
|
sleep 5
|
||||||
|
(( COUNTER+=5 ))
|
||||||
|
print_warn "MSSQL Host '${dbhost}' is not accessible, retrying.. ($COUNTER seconds so far)"
|
||||||
|
done
|
||||||
|
;;
|
||||||
"pgsql" )
|
"pgsql" )
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
export PGPASSWORD=${dbpass}
|
export PGPASSWORD=${dbpass}
|
||||||
@@ -375,6 +412,7 @@ move_backup() {
|
|||||||
print_debug "Backup routines Initialized on $(date)"
|
print_debug "Backup routines Initialized on $(date)"
|
||||||
|
|
||||||
### Wait for Next time to start backup
|
### Wait for Next time to start backup
|
||||||
|
if [ "$1" != "NOW" ]; then
|
||||||
current_time=$(date +"%s")
|
current_time=$(date +"%s")
|
||||||
today=$(date +"%Y%m%d")
|
today=$(date +"%Y%m%d")
|
||||||
|
|
||||||
@@ -390,6 +428,7 @@ print_debug "Backup routines Initialized on $(date)"
|
|||||||
|
|
||||||
print_notice "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")"
|
print_notice "Next Backup at $(date -d @${target_time} +"%Y-%m-%d %T %Z")"
|
||||||
sleep $waittime
|
sleep $waittime
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
### Commence Backup
|
### Commence Backup
|
||||||
@@ -413,6 +452,10 @@ print_debug "Backup routines Initialized on $(date)"
|
|||||||
check_availability
|
check_availability
|
||||||
backup_influx
|
backup_influx
|
||||||
;;
|
;;
|
||||||
|
"mssql" )
|
||||||
|
check_availability
|
||||||
|
backup_mssql
|
||||||
|
;;
|
||||||
"mysql" )
|
"mysql" )
|
||||||
check_availability
|
check_availability
|
||||||
backup_mysql
|
backup_mysql
|
||||||
|
|||||||
Reference in New Issue
Block a user