Skip to content

Commit 2b441f1

Browse files
committed
Restore old functionality for Mongo backup when not using MONGO_CUSTOM_URI
1 parent 8b41f5e commit 2b441f1

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ Currently backs up CouchDB, InfluxDB, MySQL, MongoDB, Postgres, Redis servers.
3737
- [About](#about)
3838
- [Maintainer](#maintainer)
3939
- [Table of Contents](#table-of-contents)
40-
- [Persistent Storage](#persistent-storage)
4140
- [Prerequisites and Assumptions](#prerequisites-and-assumptions)
4241
- [Installation](#installation)
4342
- [Build from Source](#build-from-source)
4443
- [Prebuilt Images](#prebuilt-images)
4544
- [Multi Architecture](#multi-architecture)
4645
- [Configuration](#configuration)
4746
- [Quick Start](#quick-start)
48-
- [Persistent Storage](#persistent-storage-1)
47+
- [Persistent Storage](#persistent-storage)
4948
- [Environment Variables](#environment-variables)
5049
- [Base Images used](#base-images-used)
5150
- [Container Options](#container-options)
@@ -149,8 +148,6 @@ Be sure to view the following repositories to understand all the customizable op
149148
| `DB_PASS` | (optional if DB doesn't require it) password for the database | |
150149
| `DB_PORT` | (optional) Set port to connect to DB_HOST. Defaults are provided | varies |
151150
| `INFLUX_VERSION` | What Version of Influx are you backing up from `1`.x or `2` series - AMD64 and ARM64 only for `2` | |
152-
| `MONGO_HOST_TYPE` | Connect to regular `mongodb` or `atlas` | `mongodb` |
153-
| | You can also skip this and override the uri prefix with `MONGO_URI_PREFIX=mongodb+srv://` or whatever you would like | |
154151
| `MONGO_CUSTOM_URI` | If you wish to override the MongoDB Connection string enter it here e.g. `mongodb+srv://username:[email protected]` | |
155152
| | 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 |
156153

install/assets/defaults/10-db-backup

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ SKIP_AVAILABILITY_CHECK=${SKIP_AVAILABILITY_CHECK:-"FALSE"}
2424
SPLIT_DB=${SPLIT_DB:-"TRUE"}
2525
TEMP_LOCATION=${TEMP_LOCATION:-"/tmp/backups"}
2626

27-
if [ -n "${MONGO_CUSTOM_URI}" ]; then MONGO_HOST_TYPE="atlas" ; fi

install/assets/functions/10-db-backup

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,13 @@ backup_mongo() {
170170
fi
171171

172172
if [ -n "${MONGO_CUSTOM_URI}" ] ; then
173-
mongo_generated_uri="${MONGO_CUSTOM_URI} ${EXTRA_OPTS}"
173+
mongo_backup_parameter="--uri=${MONGO_CUSTOM_URI} ${EXTRA_OPTS}"
174174
else
175-
if [ "${MONGO_HOST_TYPE,,}" = "atlas" ] ; then
176-
MONGO_URI_PREFIX=${MONGO_URI_PREFIX:-"mongodb+srv://"}
177-
mongo_generated_uri="${MONGO_URI_PREFIX}${DB_HOST} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}"
178-
else
179-
MONGO_URI_PREFIX=${MONGO_URI_PREFIX:-"mongodb://"}
180-
mongo_generated_uri="${MONGO_URI_PREFIX}${DB_HOST}:${DB_PORT} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}"
181-
fi
175+
mongo_backup_parameter="--host ${DB_HOST} --port ${DB_PORT} ${MONGO_USER_STR}${MONGO_PASS_STR}${MONGO_AUTH_STR}${MONGO_DB_STR} ${EXTRA_OPTS}"
182176
fi
183177
pre_dbbackup "${DB_NAME}"
184178
print_notice "Dumping MongoDB database: '${DB_NAME}' ${compression_string}"
185-
silent mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} --uri="${mongo_generated_uri}"
179+
silent mongodump --archive=${TEMP_LOCATION}/${target} ${mongo_compression} "${mongo_backup_parameter}"
186180
exit_code=$?
187181
check_exit_code $target
188182
generate_checksum
@@ -399,7 +393,7 @@ check_availability() {
399393
esac
400394
;;
401395
"mongo" )
402-
if [ "${MONGO_HOST_TYPE,,}" = "atlas" ] ; then
396+
if [ -n "${MONGO_CUSTOM_URI}" ] ; then
403397
print_debug "Skipping Connectivity Check"
404398
else
405399
counter=0
@@ -828,3 +822,23 @@ EOF
828822
fi
829823
}
830824

825+
urlencode() {
826+
old_lc_collate=$LC_COLLATE
827+
LC_COLLATE=C
828+
829+
local length="${#1}"
830+
for (( i = 0; i < length; i++ )); do
831+
local c="${1:$i:1}"
832+
case $c in
833+
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
834+
*) printf '%%%02X' "'$c" ;;
835+
esac
836+
done
837+
838+
LC_COLLATE=$old_lc_collate
839+
}
840+
841+
urldecode() {
842+
local url_encoded="${1//+/ }"
843+
printf '%b' "${url_encoded//%/\\x}"
844+
}

0 commit comments

Comments
 (0)