mirror of
https://github.com/tiredofit/docker-db-backup.git
synced 2025-12-21 13:23:12 +01:00
Restore old functionality for Mongo backup when not using MONGO_CUSTOM_URI
This commit is contained in:
@@ -37,7 +37,6 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
|||||||
- [About](#about)
|
- [About](#about)
|
||||||
- [Maintainer](#maintainer)
|
- [Maintainer](#maintainer)
|
||||||
- [Table of Contents](#table-of-contents)
|
- [Table of Contents](#table-of-contents)
|
||||||
- [Persistent Storage](#persistent-storage)
|
|
||||||
- [Prerequisites and Assumptions](#prerequisites-and-assumptions)
|
- [Prerequisites and Assumptions](#prerequisites-and-assumptions)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Build from Source](#build-from-source)
|
- [Build from Source](#build-from-source)
|
||||||
@@ -45,7 +44,7 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
|
|||||||
- [Multi Architecture](#multi-architecture)
|
- [Multi Architecture](#multi-architecture)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Quick Start](#quick-start)
|
- [Quick Start](#quick-start)
|
||||||
- [Persistent Storage](#persistent-storage-1)
|
- [Persistent Storage](#persistent-storage)
|
||||||
- [Environment Variables](#environment-variables)
|
- [Environment Variables](#environment-variables)
|
||||||
- [Base Images used](#base-images-used)
|
- [Base Images used](#base-images-used)
|
||||||
- [Container Options](#container-options)
|
- [Container Options](#container-options)
|
||||||
@@ -149,8 +148,6 @@ Be sure to view the following repositories to understand all the customizable op
|
|||||||
| `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` series - AMD64 and ARM64 only for `2` | |
|
| `INFLUX_VERSION` | What Version of Influx are you backing up from `1`.x or `2` series - AMD64 and ARM64 only for `2` | |
|
||||||
| `MONGO_HOST_TYPE` | Connect to regular `mongodb` or `atlas` | `mongodb` |
|
|
||||||
| | You can also skip this and override the uri prefix with `MONGO_URI_PREFIX=mongodb+srv://` or whatever you would like | |
|
|
||||||
| `MONGO_CUSTOM_URI` | If you wish to override the MongoDB Connection string enter it here e.g. `mongodb+srv://username:password@cluster.id.mongodb.net` | |
|
| `MONGO_CUSTOM_URI` | If you wish to override the MongoDB Connection string enter it here e.g. `mongodb+srv://username:password@cluster.id.mongodb.net` | |
|
||||||
| | This environment variable will be parsed and populate the `DB_NAME` and `DB_HOST` variables to properly build your backup filenames. You can overrde them by making your own entries |
|
| | This environment variable will be parsed and populate the `DB_NAME` and `DB_HOST` variables to properly build your backup filenames. You can overrde them by making your own entries |
|
||||||
|
|
||||||
|
|||||||
@@ -24,4 +24,3 @@ SKIP_AVAILABILITY_CHECK=${SKIP_AVAILABILITY_CHECK:-"FALSE"}
|
|||||||
SPLIT_DB=${SPLIT_DB:-"TRUE"}
|
SPLIT_DB=${SPLIT_DB:-"TRUE"}
|
||||||
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
|
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
|
||||||
|
|
||||||
if [ -n "${MONGO_CUSTOM_URI}" ]; then MONGO_HOST_TYPE="atlas" ; fi
|
|
||||||
|
|||||||
@@ -170,19 +170,13 @@ backup_mongo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${MONGO_CUSTOM_URI}" ] ; then
|
if [ -n "${MONGO_CUSTOM_URI}" ] ; then
|
||||||
mongo_generated_uri="${MONGO_CUSTOM_URI} ${EXTRA_OPTS}"
|
mongo_backup_parameter="--uri=${MONGO_CUSTOM_URI} ${EXTRA_OPTS}"
|
||||||
else
|
else
|
||||||
if [ "${MONGO_HOST_TYPE,,}" = "atlas" ] ; then
|
mongo_backup_parameter="--host ${DB_HOST} --port ${DB_PORT} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}"
|
||||||
MONGO_URI_PREFIX=${MONGO_URI_PREFIX:-"mongodb+srv://"}
|
|
||||||
mongo_generated_uri="${MONGO_URI_PREFIX}${DB_HOST} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}"
|
|
||||||
else
|
|
||||||
MONGO_URI_PREFIX=${MONGO_URI_PREFIX:-"mongodb://"}
|
|
||||||
mongo_generated_uri="${MONGO_URI_PREFIX}${DB_HOST}:${DB_PORT} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
pre_dbbackup "${DB_NAME}"
|
pre_dbbackup "${DB_NAME}"
|
||||||
print_notice "Dumping MongoDB database: '${DB_NAME}' ${compression_string}"
|
print_notice "Dumping MongoDB database: '${DB_NAME}' ${compression_string}"
|
||||||
silent mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} --uri="${mongo_generated_uri}"
|
silent mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} "${mongo_backup_parameter}"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
check_exit_code $target
|
check_exit_code $target
|
||||||
generate_checksum
|
generate_checksum
|
||||||
@@ -399,7 +393,7 @@ check_availability() {
|
|||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
"mongo" )
|
"mongo" )
|
||||||
if [ "${MONGO_HOST_TYPE,,}" = "atlas" ] ; then
|
if [ -n "${MONGO_CUSTOM_URI}" ] ; then
|
||||||
print_debug "Skipping Connectivity Check"
|
print_debug "Skipping Connectivity Check"
|
||||||
else
|
else
|
||||||
counter=0
|
counter=0
|
||||||
@@ -828,3 +822,23 @@ EOF
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
urlencode() {
|
||||||
|
old_lc_collate=$LC_COLLATE
|
||||||
|
LC_COLLATE=C
|
||||||
|
|
||||||
|
local length="${#1}"
|
||||||
|
for (( i = 0; i < length; i++ )); do
|
||||||
|
local c="${1:$i:1}"
|
||||||
|
case $c in
|
||||||
|
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
|
||||||
|
*) printf '%%%02X' "'$c" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
LC_COLLATE=$old_lc_collate
|
||||||
|
}
|
||||||
|
|
||||||
|
urldecode() {
|
||||||
|
local url_encoded="${1//+/ }"
|
||||||
|
printf '%b' "${url_encoded//%/\\x}"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user