mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-22 05:33:53 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c23d7991fe | ||
|
|
3f58cfd284 | ||
|
|
2d01f5e692 | ||
|
|
dbd0a03b0d | ||
|
|
6527f4ff63 | ||
|
|
d843d21a1b | ||
|
|
24ed769429 | ||
|
|
cbd87a5ede |
34
CHANGELOG.md
34
CHANGELOG.md
@@ -1,3 +1,35 @@
|
|||||||
|
## 3.2.0 2022-03-31 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Install InfluxDB2 Client alongside version 1 (amd64 and arm64)
|
||||||
|
- Introduce InfluxDB 2 backup support
|
||||||
|
- Introduce multiple compression types other than Gzip for Influx 1/2
|
||||||
|
- Introduce compression for MSSQL backups
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Testing for Host availability for CouchDB and InfluxDB
|
||||||
|
|
||||||
|
|
||||||
|
## 3.1.3 2022-03-30 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix for MariaDB not sending database name to post script
|
||||||
|
- Check for executible bit on post scripts both via environment variable and /assets/custom
|
||||||
|
- SPLIT_DB defaulted to TRUE
|
||||||
|
|
||||||
|
|
||||||
|
## 3.1.2 2022-03-29 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix for blank Notice when individual backup is completed (time taken)
|
||||||
|
|
||||||
|
|
||||||
|
## 3.1.1 2022-03-28 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Resolve some issues with backups of Mongo and others not saving the proper timestamp
|
||||||
|
|
||||||
|
|
||||||
## 3.1.0 2022-03-23 <dave at tiredofit dot ca>
|
## 3.1.0 2022-03-23 <dave at tiredofit dot ca>
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -239,7 +271,7 @@
|
|||||||
|
|
||||||
|
|
||||||
## 2.9.2 2021-10-22 <teenigma@github>
|
## 2.9.2 2021-10-22 <teenigma@github>
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix compression failing on Redis backup
|
- Fix compression failing on Redis backup
|
||||||
|
|
||||||
|
|||||||
13
Dockerfile
13
Dockerfile
@@ -2,7 +2,9 @@ FROM docker.io/tiredofit/alpine:3.15
|
|||||||
LABEL maintainer="Dave Conroy (github.com/tiredofit)"
|
LABEL maintainer="Dave Conroy (github.com/tiredofit)"
|
||||||
|
|
||||||
### Set Environment Variables
|
### Set Environment Variables
|
||||||
ENV MSSQL_VERSION=17.8.1.1-1 \
|
|
||||||
|
ENV INFLUX2_VERSION=2.2.1 \
|
||||||
|
MSSQL_VERSION=17.8.1.1-1 \
|
||||||
CONTAINER_ENABLE_MESSAGING=FALSE \
|
CONTAINER_ENABLE_MESSAGING=FALSE \
|
||||||
CONTAINER_ENABLE_MONITORING=TRUE \
|
CONTAINER_ENABLE_MONITORING=TRUE \
|
||||||
CONTAINER_PROCESS_RUNAWAY_PROTECTOR=FALSE \
|
CONTAINER_PROCESS_RUNAWAY_PROTECTOR=FALSE \
|
||||||
@@ -44,9 +46,14 @@ RUN set -ex && \
|
|||||||
\
|
\
|
||||||
apkArch="$(apk --print-arch)"; \
|
apkArch="$(apk --print-arch)"; \
|
||||||
case "$apkArch" in \
|
case "$apkArch" in \
|
||||||
x86_64) mssql=true ; 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 ;; \
|
x86_64) mssql=true ; influx2=true ; influx_arch=amd64; ;; \
|
||||||
*) echo >&2 "Detected non x86_64 build variant, skipping MSSQL installation" ;; \
|
aarch64 ) influx2=true ; influx_arch=arm64 ;; \
|
||||||
|
*) sleep 0.1 ;; \
|
||||||
esac; \
|
esac; \
|
||||||
|
\
|
||||||
|
if [ $mssql = "true" ] ; then 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 ; else echo >&2 "Detected non x86_64 build variant, skipping MSSQL installation" ; fi; \
|
||||||
|
if [ $influx2 = "true" ] ; then curl -sSL https://dl.influxdata.com/influxdb/releases/influxdb2-client-${INFLUX2_VERSION}-linux-${influx_arch}.tar.gz | tar xvfz - --strip=1 -C /usr/src/ ; chmod +x /usr/src/influx ; mv /usr/src/influx /usr/sbin/ ; else echo >&2 "Unable to build Influx 2 on this system" ; fi ; \
|
||||||
|
\
|
||||||
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 && \
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
|||||||
|
|
||||||
* dump to local filesystem or backup to S3 Compatible services
|
* dump to local filesystem or backup to S3 Compatible services
|
||||||
* select database user and password
|
* select database user and password
|
||||||
* backup all databases
|
* backup all databases, single, or multiple databases
|
||||||
|
* backup all to seperate files or one singular file
|
||||||
* choose to have an MD5 or SHA1 sum after backup for verification
|
* choose to have an MD5 or SHA1 sum after backup for verification
|
||||||
* delete old backups after specific amount of time
|
* delete old backups after specific amount of time
|
||||||
* choose compression type (none, gz, bz, xz, zstd)
|
* choose compression type (none, gz, bz, xz, zstd)
|
||||||
@@ -49,6 +50,7 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
|||||||
- [Base Images used](#base-images-used)
|
- [Base Images used](#base-images-used)
|
||||||
- [Container Options](#container-options)
|
- [Container Options](#container-options)
|
||||||
- [Database Specific Options](#database-specific-options)
|
- [Database Specific Options](#database-specific-options)
|
||||||
|
- [For Influx DB2:](#for-influx-db2)
|
||||||
- [Scheduling Options](#scheduling-options)
|
- [Scheduling Options](#scheduling-options)
|
||||||
- [Backup Options](#backup-options)
|
- [Backup Options](#backup-options)
|
||||||
- [Backing Up to S3 Compatible Services](#backing-up-to-s3-compatible-services)
|
- [Backing Up to S3 Compatible Services](#backing-up-to-s3-compatible-services)
|
||||||
@@ -142,6 +144,11 @@ Be sure to view the following repositories to understand all the customizable op
|
|||||||
| `DB_USER` | username for the database(s) - Can use `root` for MySQL | |
|
| `DB_USER` | username for the database(s) - Can use `root` for MySQL | |
|
||||||
| `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 | |
|
||||||
| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | varies |
|
| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | varies |
|
||||||
|
| `INFLUX_VERSION` | What Version of Influx are you backing up from `1`.x or `2.x` series - AMD64 and ARM64 only for `2` | |
|
||||||
|
|
||||||
|
#### For Influx DB2:
|
||||||
|
Your Organization will be mapped to `DB_USER` and your root token will need to be mapped to `DB_PASS`. You may use `DB_NAME=ALL` to backup the entire set of databases. For `DB_HOST` use syntax of `http(s)://db-name`
|
||||||
|
|
||||||
### Scheduling Options
|
### Scheduling Options
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ PARALLEL_COMPRESSION_THREADS=${PARALLEL_COMPRESSION_THREADS:-"$(nproc)"}
|
|||||||
S3_CERT_SKIP_VERIFY=${S3_CERT_SKIP_VERIFY:-"TRUE"}
|
S3_CERT_SKIP_VERIFY=${S3_CERT_SKIP_VERIFY:-"TRUE"}
|
||||||
S3_PROTOCOL=${S3_PROTOCOL:-"https"}
|
S3_PROTOCOL=${S3_PROTOCOL:-"https"}
|
||||||
SIZE_VALUE=${SIZE_VALUE:-"bytes"}
|
SIZE_VALUE=${SIZE_VALUE:-"bytes"}
|
||||||
SPLIT_DB=${SPLIT_DB:-"FALSE"}
|
SPLIT_DB=${SPLIT_DB:-"TRUE"}
|
||||||
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
|
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
|
||||||
dbhost=${DB_HOST}
|
dbhost=${DB_HOST}
|
||||||
dbname=${DB_NAME}
|
dbname=${DB_NAME}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ bootstrap_variables() {
|
|||||||
dbport=${DB_PORT:-8088}
|
dbport=${DB_PORT:-8088}
|
||||||
file_env 'DB_USER'
|
file_env 'DB_USER'
|
||||||
file_env 'DB_PASS'
|
file_env 'DB_PASS'
|
||||||
|
sanity_var INFLUX_VERSION "What InfluxDB version you are backing up from '1' or '2'"
|
||||||
;;
|
;;
|
||||||
mongo* )
|
mongo* )
|
||||||
dbtype=mongo
|
dbtype=mongo
|
||||||
@@ -77,67 +78,103 @@ bootstrap_variables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
backup_couch() {
|
backup_couch() {
|
||||||
|
pre_dbbackup
|
||||||
target=couch_${dbname}_${dbhost}_${now}.txt
|
target=couch_${dbname}_${dbhost}_${now}.txt
|
||||||
compression
|
compression
|
||||||
print_notice "Dumping CouchDB database: '${dbname}'"
|
print_notice "Dumping CouchDB database: '${dbname}' ${compression_string}"
|
||||||
curl -X GET http://${dbhost}:${dbport}/${dbname}/_all_docs?include_docs=true ${compress_cmd} | $compress_cmd > ${TEMP_LOCATION}/${target}
|
curl -sSL -X GET ${dbhost}:${dbport}/${dbname}/_all_docs?include_docs=true ${compress_cmd} | $compress_cmd > ${TEMP_LOCATION}/${target}
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup_hooks
|
post_dbbackup $dbname
|
||||||
send_statistics
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_influx() {
|
backup_influx() {
|
||||||
if [ "${ENABLE_COMPRESSION,,}" = "none" ] || [ "${ENABLE_COMPRESSION,,}" = "false" ] ; then
|
if [ "${dbname,,}" = "all" ] ; then
|
||||||
:
|
print_debug "Preparing to back up everything"
|
||||||
|
db_names=justbackupeverything
|
||||||
else
|
else
|
||||||
print_notice "Compressing InfluxDB backup with gzip"
|
db_names=$(echo "${dbname}" | tr ',' '\n')
|
||||||
influx_compression="-portable"
|
fi
|
||||||
|
|
||||||
|
case "${INFLUX_VERSION,,}" in
|
||||||
|
1 )
|
||||||
|
for db in ${db_names}; do
|
||||||
|
pre_dbbackup
|
||||||
|
if [ "${db}" != "justbackupeverything" ] ; then bucket="-bucket $db" ; else db=all ; fi
|
||||||
|
target=influx_${db}_${dbhost}_${now}
|
||||||
|
compression
|
||||||
|
print_notice "Dumping Influx database: '${db}'"
|
||||||
|
influxd backup ${influx_compression} ${bucket} -host ${dbhost}:${dbport} ${EXTRA_OPTS} "${TEMP_LOCATION}"/"${target_dir}"
|
||||||
|
exit_code=$?
|
||||||
|
check_exit_code $target_dir
|
||||||
|
print_notice "Creating archive file of '${target_dir}' with tar ${compresion_string}"
|
||||||
|
tar cf - "${TEMP_LOCATION}"/"${target_dir}" | $dir_compress_cmd > "${TEMP_LOCATION}"/"${target_dir}".tar"${extension}"
|
||||||
|
target=influx_${db}_${dbhost}_${now}.tar${extension}
|
||||||
|
generate_checksum
|
||||||
|
move_dbbackup
|
||||||
|
post_dbbackup $db
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
2 )
|
||||||
|
for db in ${db_names}; do
|
||||||
|
pre_dbbackup
|
||||||
|
if [ "${db}" != "justbackupeverything" ] ; then bucket="--bucket $db" ; else db=all ; fi
|
||||||
|
target=influx2_${db}_${dbhost}_${now}
|
||||||
|
compression
|
||||||
|
print_notice "Dumping Influx2 database: '${db}'"
|
||||||
|
influx backup --org ${dbuser} ${bucket} --host ${dbhost}:${dbport} --token ${dbpass} ${EXTRA_OPTS} --compression none "${TEMP_LOCATION}"/"${target_dir}"
|
||||||
|
exit_code=$?
|
||||||
|
check_exit_code $target_dir
|
||||||
|
create_archive
|
||||||
|
target=influx2_${db}_${dbhost}_${now}.tar${extension}
|
||||||
|
generate_checksum
|
||||||
|
move_dbbackup
|
||||||
|
post_dbbackup $db
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
create_archive() {
|
||||||
|
if [ "${exit_code}" = "0" ] ; then
|
||||||
|
print_notice "Creating archive file of '${target_dir}' with tar ${compresion_string}"
|
||||||
|
tar cf - "${TEMP_LOCATION}"/"${target_dir}" | $dir_compress_cmd > "${TEMP_LOCATION}"/"${target_dir}".tar"${extension}"
|
||||||
|
else
|
||||||
|
print_warn "Skipping creating archive file because backup did not complete successfully"
|
||||||
fi
|
fi
|
||||||
for db in ${DB_NAME}; do
|
|
||||||
print_notice "Dumping Influx database: '${db}'"
|
|
||||||
target=influx_${db}_${dbhost}_${now}
|
|
||||||
influxd backup ${influx_compression} -database $db -host ${dbhost}:${dbport} ${TEMP_LOCATION}/${target}
|
|
||||||
exit_code=$?
|
|
||||||
check_exit_code $target
|
|
||||||
generate_checksum
|
|
||||||
move_dbbackup
|
|
||||||
send_statistics
|
|
||||||
post_dbbackup_hooks
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_mongo() {
|
backup_mongo() {
|
||||||
|
pre_dbbackup
|
||||||
if [ "${ENABLE_COMPRESSION,,}" = "none" ] || [ "${ENABLE_COMPRESSION,,}" = "false" ] ; then
|
if [ "${ENABLE_COMPRESSION,,}" = "none" ] || [ "${ENABLE_COMPRESSION,,}" = "false" ] ; then
|
||||||
target=${dbtype}_${dbname}_${dbhost}_${now}.archive
|
target=${dbtype}_${dbname}_${dbhost}_${now}.archive
|
||||||
else
|
else
|
||||||
print_notice "Compressing MongoDB backup with gzip"
|
|
||||||
target=${dbtype}_${dbname}_${dbhost}_${now}.archive.gz
|
target=${dbtype}_${dbname}_${dbhost}_${now}.archive.gz
|
||||||
mongo_compression="--gzip"
|
mongo_compression="--gzip"
|
||||||
|
compression_string="and compressing with gzip"
|
||||||
fi
|
fi
|
||||||
print_notice "Dumping MongoDB database: '${DB_NAME}'"
|
print_notice "Dumping MongoDB database: '${DB_NAME}' ${compression_string}"
|
||||||
mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} --host ${dbhost} --port ${dbport} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
cd "${TEMP_LOCATION}"
|
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
send_statistics
|
post_dbbackup
|
||||||
post_dbbackup_hooks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_mssql() {
|
backup_mssql() {
|
||||||
|
pre_dbbackup
|
||||||
target=mssql_${dbname}_${dbhost}_${now}.bak
|
target=mssql_${dbname}_${dbhost}_${now}.bak
|
||||||
|
compression
|
||||||
print_notice "Dumping MSSQL database: '${dbname}'"
|
print_notice "Dumping MSSQL database: '${dbname}'"
|
||||||
/opt/mssql-tools/bin/sqlcmd -E -C -S ${dbhost}\,${dbport} -U ${dbuser} -P ${dbpass} –Q "BACKUP DATABASE \[${dbname}\] TO DISK = N'${TEMP_LOCATION}/${target}' WITH NOFORMAT, NOINIT, NAME = '${dbname}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
|
/opt/mssql-tools/bin/sqlcmd -E -C -S ${dbhost}\,${dbport} -U ${dbuser} -P ${dbpass} –Q "BACKUP DATABASE \[${dbname}\] TO DISK = N'${TEMP_LOCATION}/${target}' WITH NOFORMAT, NOINIT, NAME = '${dbname}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
send_statistics
|
post_dbbackup $dbname
|
||||||
post_dbbackup_hooks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_mysql() {
|
backup_mysql() {
|
||||||
@@ -175,7 +212,7 @@ backup_mysql() {
|
|||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup
|
post_dbbackup $db
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
print_debug "Not splitting database dumps into their own files"
|
print_debug "Not splitting database dumps into their own files"
|
||||||
@@ -188,7 +225,7 @@ backup_mysql() {
|
|||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup
|
post_dbbackup all
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +259,7 @@ backup_pgsql() {
|
|||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup
|
post_dbbackup $db
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
print_debug "Not splitting database dumps into their own files"
|
print_debug "Not splitting database dumps into their own files"
|
||||||
@@ -243,14 +280,14 @@ backup_pgsql() {
|
|||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup
|
post_dbbackup all
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_redis() {
|
backup_redis() {
|
||||||
pre_dbbackup
|
pre_dbbackup
|
||||||
print_notice "Dumping Redis - Flushing Redis Cache First"
|
print_notice "Dumping Redis - Flushing Redis Cache First"
|
||||||
target=redis_${db}_${dbhost}_${now}.rdb
|
target=redis_all_${dbhost}_${now}.rdb
|
||||||
echo bgsave | redis-cli -h ${dbhost} -p ${dbport} ${REDIS_PASS_STR} --rdb ${TEMP_LOCATION}/${target} ${EXTRA_OPTS}
|
echo bgsave | redis-cli -h ${dbhost} -p ${dbport} ${REDIS_PASS_STR} --rdb ${TEMP_LOCATION}/${target} ${EXTRA_OPTS}
|
||||||
sleep 10
|
sleep 10
|
||||||
try=5
|
try=5
|
||||||
@@ -270,7 +307,7 @@ backup_redis() {
|
|||||||
$compress_cmd "${TEMP_LOCATION}/${target_original}"
|
$compress_cmd "${TEMP_LOCATION}/${target_original}"
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup
|
post_dbbackup all
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_sqlite3() {
|
backup_sqlite3() {
|
||||||
@@ -283,72 +320,78 @@ backup_sqlite3() {
|
|||||||
sqlite3 "${dbhost}" ".backup '${TEMP_LOCATION}/backup.sqlite3'"
|
sqlite3 "${dbhost}" ".backup '${TEMP_LOCATION}/backup.sqlite3'"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
cat "${TEMP_LOCATION}"/backup.sqlite3 | $compress_cmd > "${TEMP_LOCATION}/${target}"
|
cat "${TEMP_LOCATION}"/backup.sqlite3 | ${dir_compress_cmd} > "${TEMP_LOCATION}/${target}"
|
||||||
generate_checksum
|
generate_checksum
|
||||||
move_dbbackup
|
move_dbbackup
|
||||||
post_dbbackup
|
post_dbbackup $db
|
||||||
}
|
}
|
||||||
|
|
||||||
check_availability() {
|
check_availability() {
|
||||||
### Set the Database Type
|
### Set the Database Type
|
||||||
case "$dbtype" in
|
case "$dbtype" in
|
||||||
"couch" )
|
"couch" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
while ! (nc -z ${dbhost} ${dbport}) ; do
|
code_received=0
|
||||||
|
while [ "${code_received}" != "200" ]; do
|
||||||
|
code_received=$(curl -XGET -sSL -o /dev/null -L -w ''%{http_code}'' ${dbhost}:${dbport})
|
||||||
|
if [ "${code_received}" = "200" ] ; then break ; fi
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "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" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
while ! (nc -z ${dbhost} ${dbport}) ; do
|
code_received=0
|
||||||
|
while [ "${code_received}" != "200" ]; do
|
||||||
|
code_received=$(curl -XGET -sSL -o /dev/null -w ''%{http_code}'' ${dbhost}:${dbport}/health)
|
||||||
|
if [ "${code_received}" = "200" ] ; then break ; fi
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "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" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
while ! (nc -z ${dbhost} ${dbport}) ; do
|
while ! (nc -z ${dbhost} ${dbport}) ; do
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "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" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
export MYSQL_PWD=${dbpass}
|
export MYSQL_PWD=${dbpass}
|
||||||
while ! (mysqladmin -u"${dbuser}" -P"${dbport}" -h"${dbhost}" status > /dev/null 2>&1) ; do
|
while ! (mysqladmin -u"${dbuser}" -P"${dbport}" -h"${dbhost}" status > /dev/null 2>&1) ; do
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "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)"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
"mssql" )
|
"mssql" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
while ! (nc -z ${dbhost} ${dbport}) ; do
|
while ! (nc -z ${dbhost} ${dbport}) ; do
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "MSSQL Host '${dbhost}' is not accessible, retrying.. ($COUNTER seconds so far)"
|
print_warn "MSSQL Host '${dbhost}' is not accessible, retrying.. ($counter seconds so far)"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
"pgsql" )
|
"pgsql" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
export PGPASSWORD=${dbpass}
|
export PGPASSWORD=${dbpass}
|
||||||
until pg_isready --dbname=${dbname} --host=${dbhost} --port=${dbport} --username=${dbuser} -q
|
until pg_isready --dbname=${dbname} --host=${dbhost} --port=${dbport} --username=${dbuser} -q
|
||||||
do
|
do
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "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" )
|
||||||
COUNTER=0
|
counter=0
|
||||||
while ! (nc -z "${dbhost}" "${dbport}") ; do
|
while ! (nc -z "${dbhost}" "${dbport}") ; do
|
||||||
sleep 5
|
sleep 5
|
||||||
(( COUNTER+=5 ))
|
(( counter+=5 ))
|
||||||
print_warn "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
|
||||||
;;
|
;;
|
||||||
"sqlite3" )
|
"sqlite3" )
|
||||||
@@ -404,26 +447,39 @@ compression() {
|
|||||||
gz* )
|
gz* )
|
||||||
compress_cmd="pigz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS} "
|
compress_cmd="pigz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS} "
|
||||||
compression_type="gzip"
|
compression_type="gzip"
|
||||||
|
extension=".gz"
|
||||||
|
dir_compress_cmd=${compress_cmd}
|
||||||
|
target_dir=${target}
|
||||||
target=${target}.gz
|
target=${target}.gz
|
||||||
;;
|
;;
|
||||||
bz* )
|
bz* )
|
||||||
compress_cmd="pbzip2 -${COMPRESSION_LEVEL} -p${PARALLEL_COMPRESSION_THREADS} "
|
compress_cmd="pbzip2 -${COMPRESSION_LEVEL} -p${PARALLEL_COMPRESSION_THREADS} "
|
||||||
compression_type="bzip2"
|
compression_type="bzip2"
|
||||||
|
dir_compress_cmd=${compress_cmd}
|
||||||
|
extension=".bz2"
|
||||||
|
target_dir=${target}
|
||||||
target=${target}.bz2
|
target=${target}.bz2
|
||||||
;;
|
;;
|
||||||
xz* )
|
xz* )
|
||||||
compress_cmd="pixz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS} "
|
compress_cmd="pixz -${COMPRESSION_LEVEL} -p ${PARALLEL_COMPRESSION_THREADS} "
|
||||||
compression_type="xzip"
|
compression_type="xzip"
|
||||||
|
dir_compress_cmd=${compress_cmd}
|
||||||
|
extension=".xz"
|
||||||
|
target_dir=${target}
|
||||||
target=${target}.xz
|
target=${target}.xz
|
||||||
;;
|
;;
|
||||||
zst* )
|
zst* )
|
||||||
compress_cmd="zstd --rm -${COMPRESSION_LEVEL} -T${PARALLEL_COMPRESSION_THREADS}"
|
compress_cmd="zstd --rm -${COMPRESSION_LEVEL} -T${PARALLEL_COMPRESSION_THREADS}"
|
||||||
compression_type="zstd"
|
compression_type="zstd"
|
||||||
|
dir_compress_cmd=${compress_cmd}
|
||||||
|
extension=".zst"
|
||||||
|
target_dir=${target}
|
||||||
target=${target}.zst
|
target=${target}.zst
|
||||||
;;
|
;;
|
||||||
"none" | "false")
|
"none" | "false")
|
||||||
compress_cmd="cat "
|
|
||||||
compression_type="none"
|
compression_type="none"
|
||||||
|
dir_compress_cmd="cat"
|
||||||
|
target_dir=${target}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -469,55 +525,61 @@ generate_checksum() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
move_dbbackup() {
|
move_dbbackup() {
|
||||||
case "$SIZE_VALUE" in
|
if [ "${exit_code}" = "0" ] ; then
|
||||||
"b" | "bytes" )
|
case "${SIZE_VALUE,,}" in
|
||||||
SIZE_VALUE=1
|
"b" | "bytes" )
|
||||||
;;
|
SIZE_VALUE=1
|
||||||
"[kK]" | "[kK][bB]" | "kilobytes" | "[mM]" | "[mM][bB]" | "megabytes" )
|
;;
|
||||||
SIZE_VALUE="-h"
|
"[kK]" | "[kK][bB]" | "kilobytes" | "[mM]" | "[mM][bB]" | "megabytes" )
|
||||||
;;
|
SIZE_VALUE="-h"
|
||||||
*)
|
;;
|
||||||
SIZE_VALUE=1
|
*)
|
||||||
;;
|
SIZE_VALUE=1
|
||||||
esac
|
;;
|
||||||
if [ "$SIZE_VALUE" = "1" ] ; then
|
esac
|
||||||
FILESIZE=$(stat -c%s "${TEMP_LOCATION}"/"${target}")
|
if [ "$SIZE_VALUE" = "1" ] ; then
|
||||||
print_notice "Backup of ${target} created with the size of ${FILESIZE} bytes"
|
filesize=$(stat -c%s "${TEMP_LOCATION}"/"${target}")
|
||||||
|
print_notice "Backup of ${target} created with the size of ${filesize} bytes"
|
||||||
|
else
|
||||||
|
filesize=$(du -h "${TEMP_LOCATION}"/"${target}" | awk '{ print $1}')
|
||||||
|
print_notice "Backup of ${target} created with the size of ${filesize}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "${BACKUP_LOCATION,,}" in
|
||||||
|
"file" | "filesystem" )
|
||||||
|
print_debug "Moving backup to filesystem"
|
||||||
|
mkdir -p "${DB_DUMP_TARGET}"
|
||||||
|
mv "${TEMP_LOCATION}"/*."${checksum_extension}" "${DB_DUMP_TARGET}"/
|
||||||
|
mv "${TEMP_LOCATION}"/"${target}" "${DB_DUMP_TARGET}"/"${target}"
|
||||||
|
;;
|
||||||
|
"s3" | "minio" )
|
||||||
|
print_debug "Moving backup to S3 Bucket"
|
||||||
|
export AWS_ACCESS_KEY_ID=${S3_KEY_ID}
|
||||||
|
export AWS_SECRET_ACCESS_KEY=${S3_KEY_SECRET}
|
||||||
|
export AWS_DEFAULT_REGION=${S3_REGION}
|
||||||
|
if [ -f "${S3_CERT_CA_FILE}" ] ; then
|
||||||
|
print_debug "Using Custom CA for S3 Backups"
|
||||||
|
s3_ca_cert="--ca-bundle ${S3_CERT_CA_FILE}"
|
||||||
|
fi
|
||||||
|
if var_true "${S3_CERT_SKIP_VERIFY}" ; then
|
||||||
|
print_debug "Skipping SSL verification for HTTPS S3 Hosts"
|
||||||
|
s3_ssl="--no-verify-ssl"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ ( -n "${S3_HOST}" ) ]] && PARAM_AWS_ENDPOINT_URL=" --endpoint-url ${S3_PROTOCOL}://${S3_HOST}"
|
||||||
|
|
||||||
|
aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${TEMP_LOCATION}/${target} s3://${S3_BUCKET}/${S3_PATH}/${target} ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
|
||||||
|
unset s3_ssl
|
||||||
|
unset s3_ca_cert
|
||||||
|
rm -rf "${TEMP_LOCATION}"/*."${checksum_extension}"
|
||||||
|
rm -rf "${TEMP_LOCATION}"/"${target}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
FILESIZE=$(du -h "${TEMP_LOCATION}"/"${target}" | awk '{ print $1}')
|
print_warn "Skipping moving DB Backup to final location because backup did not complete successfully"
|
||||||
print_notice "Backup of ${target} created with the size of ${FILESIZE}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "${BACKUP_LOCATION,,}" in
|
rm -rf "${TEMP_LOCATION}"/*
|
||||||
"file" | "filesystem" )
|
|
||||||
print_debug "Moving backup to filesystem"
|
|
||||||
mkdir -p "${DB_DUMP_TARGET}"
|
|
||||||
mv "${TEMP_LOCATION}"/*."${checksum_extension}" "${DB_DUMP_TARGET}"/
|
|
||||||
mv "${TEMP_LOCATION}"/"${target}" "${DB_DUMP_TARGET}"/"${target}"
|
|
||||||
;;
|
|
||||||
"s3" | "minio" )
|
|
||||||
print_debug "Moving backup to S3 Bucket"
|
|
||||||
export AWS_ACCESS_KEY_ID=${S3_KEY_ID}
|
|
||||||
export AWS_SECRET_ACCESS_KEY=${S3_KEY_SECRET}
|
|
||||||
export AWS_DEFAULT_REGION=${S3_REGION}
|
|
||||||
if [ -f "${S3_CERT_CA_FILE}" ] ; then
|
|
||||||
print_debug "Using Custom CA for S3 Backups"
|
|
||||||
s3_ca_cert="--ca-bundle ${S3_CERT_CA_FILE}"
|
|
||||||
fi
|
|
||||||
if var_true "${S3_CERT_SKIP_VERIFY}" ; then
|
|
||||||
print_debug "Skipping SSL verification for HTTPS S3 Hosts"
|
|
||||||
s3_ssl="--no-verify-ssl"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[[ ( -n "${S3_HOST}" ) ]] && PARAM_AWS_ENDPOINT_URL=" --endpoint-url ${S3_PROTOCOL}://${S3_HOST}"
|
|
||||||
|
|
||||||
aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${TEMP_LOCATION}/${target} s3://${S3_BUCKET}/${S3_PATH}/${target} ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
|
|
||||||
unset s3_ssl
|
|
||||||
unset s3_ca_cert
|
|
||||||
rm -rf "${TEMP_LOCATION}"/*."${checksum_extension}"
|
|
||||||
rm -rf "${TEMP_LOCATION}"/"${target}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pre_dbbackup() {
|
pre_dbbackup() {
|
||||||
@@ -542,21 +604,28 @@ post_dbbackup() {
|
|||||||
|
|
||||||
### Post Script Support
|
### Post Script Support
|
||||||
if [ -n "${POST_SCRIPT}" ] ; then
|
if [ -n "${POST_SCRIPT}" ] ; then
|
||||||
print_notice "Found POST_SCRIPT environment variable. Executing '${POST_SCRIPT}"
|
if [ -x "${POST_SCRIPT}" ] ; then
|
||||||
eval "${POST_SCRIPT}" "${exit_code}" "${dbtype}" "${dbhost}" "${dbname}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${FILESIZE}" "${checksum_value}"
|
print_notice "Found POST_SCRIPT environment variable. Executing '${POST_SCRIPT}"
|
||||||
|
eval "${POST_SCRIPT}" "${exit_code}" "${dbtype}" "${dbhost}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${FILESIZE}" "${checksum_value}"
|
||||||
|
else
|
||||||
|
print_error "Can't execute POST_SCRIPT environment variable '${POST_SCRIPT}' as its filesystem bit is not executible!"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### Post Backup Custom Script Support
|
### Post Backup Custom Script Support
|
||||||
if [ -d "/assets/custom-scripts/" ] ; then
|
if [ -d "/assets/custom-scripts/" ] ; then
|
||||||
print_notice "Found Post Backup Custom Script to execute"
|
|
||||||
for f in $(find /assets/custom-scripts/ -name \*.sh -type f); do
|
for f in $(find /assets/custom-scripts/ -name \*.sh -type f); do
|
||||||
print_notice "Running Script: '${f}'"
|
if [ -x "${f}" ] ; then
|
||||||
## script EXIT_CODE DB_TYPE DB_HOST DB_NAME STARTEPOCH FINISHEPOCH DURATIONEPOCH BACKUP_FILENAME FILESIZE CHECKSUMVALUE
|
print_notice "Executing post backup custom script : '${f}'"
|
||||||
${f} "${exit_code}" "${dbtype}" "${dbhost}" "${dbname}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${FILESIZE}" "${checksum_value}"
|
## script EXIT_CODE DB_TYPE DB_HOST DB_NAME STARTEPOCH FINISHEPOCH DURATIONEPOCH BACKUP_FILENAME FILESIZE CHECKSUMVALUE
|
||||||
|
${f} "${exit_code}" "${dbtype}" "${dbhost}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${FILESIZE}" "${checksum_value}"
|
||||||
|
else
|
||||||
|
print_error "Can't run post backup custom script: '${f}' as its filesystem bit is not executible!"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_notice "DB Backup for '${db}' time taken: $(echo ${dbbackup_total_time} | awk '{printf "Hours: %d Minutes: %02d Seconds: %02d", $1/3600, ($1/60)%60, $1%60}')"
|
print_notice "DB Backup for '${1}' time taken: $(echo ${dbbackup_total_time} | awk '{printf "Hours: %d Minutes: %02d Seconds: %02d", $1/3600, ($1/60)%60, $1%60}')"
|
||||||
}
|
}
|
||||||
|
|
||||||
sanity_test() {
|
sanity_test() {
|
||||||
|
|||||||
Reference in New Issue
Block a user