diff --git a/README.md b/README.md index a0a6271..4cfa835 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers. - [About](#about) - [Maintainer](#maintainer) - [Table of Contents](#table-of-contents) - - [Persistent Storage](#persistent-storage) - [Prerequisites and Assumptions](#prerequisites-and-assumptions) - [Installation](#installation) - [Build from Source](#build-from-source) @@ -45,7 +44,7 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers. - [Multi Architecture](#multi-architecture) - [Configuration](#configuration) - [Quick Start](#quick-start) - - [Persistent Storage](#persistent-storage-1) + - [Persistent Storage](#persistent-storage) - [Environment Variables](#environment-variables) - [Base Images used](#base-images-used) - [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_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` | | -| `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` | | | | 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 | diff --git a/install/assets/defaults/10-db-backup b/install/assets/defaults/10-db-backup index c158a51..fd35b46 100755 --- a/install/assets/defaults/10-db-backup +++ b/install/assets/defaults/10-db-backup @@ -24,4 +24,3 @@ SKIP_AVAILABILITY_CHECK=${SKIP_AVAILABILITY_CHECK:-"FALSE"} SPLIT_DB=${SPLIT_DB:-"TRUE"} TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"} -if [ -n "${MONGO_CUSTOM_URI}" ]; then MONGO_HOST_TYPE="atlas" ; fi diff --git a/install/assets/functions/10-db-backup b/install/assets/functions/10-db-backup index f47a3bc..3c0f662 100755 --- a/install/assets/functions/10-db-backup +++ b/install/assets/functions/10-db-backup @@ -170,19 +170,13 @@ backup_mongo() { fi if [ -n "${MONGO_CUSTOM_URI}" ] ; then - mongo_generated_uri="${MONGO_CUSTOM_URI} ${EXTRA_OPTS}" + mongo_backup_parameter="--uri=${MONGO_CUSTOM_URI} ${EXTRA_OPTS}" else - if [ "${MONGO_HOST_TYPE,,}" = "atlas" ] ; then - 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 + mongo_backup_parameter="--host ${DB_HOST} --port ${DB_PORT} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}" fi pre_dbbackup "${DB_NAME}" 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=$? check_exit_code $target generate_checksum @@ -399,7 +393,7 @@ check_availability() { esac ;; "mongo" ) - if [ "${MONGO_HOST_TYPE,,}" = "atlas" ] ; then + if [ -n "${MONGO_CUSTOM_URI}" ] ; then print_debug "Skipping Connectivity Check" else counter=0 @@ -828,3 +822,23 @@ EOF 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}" +} \ No newline at end of file