@@ -20,16 +20,33 @@ bootstrap_variables() {
2020 ;;
2121 mongo* )
2222 dbtype=mongo
23- DB_PORT=${DB_PORT:-27017}
24- if [ -z "${MONGO_CUSTOM_URI}" ] ; then
23+ if [ -n "${MONGO_CUSTOM_URI}" ] ; then
24+ mongo_uri_proto=$(echo ${MONGO_CUSTOM_URI} | grep :// | sed -e's,^\(.*://\).*,\1,g')
25+ mongo_uri_scratch="${MONGO_CUSTOM_URI/${mongo_uri_proto}/}"
26+ mongo_uri_username_password=$(echo ${mongo_uri_scratch} | grep @ | rev | cut -d@ -f2- | rev)
27+ if [ -n "${mongo_uri_username_password}" ]; then mongo_uri_scratch=$(echo ${mongo_uri_scratch} | rev | cut -d@ -f1 | rev) ; fi
28+ mongo_uri_port=$(echo ${mongo_uri_scratch} | grep : | rev | cut -d: -f2- | rev)
29+ if [ -n "${mongo_uri_port}" ]; then mongo_uri_port=$(echo ${mongo_uri_scratch} | rev | cut -d: -f1 | cut -d/ -f2 | rev) ; fi
30+ mongo_uri_hostname=$(echo ${mongo_uri_scratch} | cut -d/ -f1 | cut -d: -f1 )
31+ mongo_uri_database=$(echo ${mongo_uri_scratch} | cut -d/ -f2 | cut -d? -f1 )
32+ mongo_uri_options=$(echo ${mongo_uri_scratch} | cut -d/ -f2 | cut -d? -f2 )
33+ DB_NAME=${DB_NAME:-"${mongo_uri_database,,}"}
34+ DB_HOST=${DB_HOST:-"${mongo_uri_hostname,,}"}
35+ else
36+ DB_PORT=${DB_PORT:-27017}
2537 [[ ( -n "${DB_USER}" ) || ( -n "${DB_USER_FILE}" ) ]] && file_env 'DB_USER'
2638 [[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
39+ [[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${DB_USER}"
40+ [[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${DB_PASS}"
41+ [[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${DB_NAME}"
42+ [[ ( -n "${DB_AUTH}" ) ]] && MONGO_AUTH_STR=" --authenticationDatabase ${DB_AUTH}"
2743 fi
2844 ;;
2945 "mysql" | "mariadb" )
3046 dbtype=mysql
3147 DB_PORT=${DB_PORT:-3306}
3248 [[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
49+ [[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${DB_PASS}
3350 sanity_var DB_NAME "Database Name to backup. Multiple seperated by commas"
3451 ;;
3552 "mssql" | "microsoftsql" )
@@ -45,12 +62,14 @@ bootstrap_variables() {
4562 dbtype=pgsql
4663 DB_PORT=${DB_PORT:-5432}
4764 [[ ( -n "${DB_PASS}" ) || ( -n "${DB_PASS_FILE}" ) ]] && file_env 'DB_PASS'
65+ [[ ( -n "${DB_PASS}" ) ]] && POSTGRES_PASS_STR="PGPASSWORD=${DB_PASS}"
4866 sanity_var DB_NAME "Database Name to backup. Multiple seperated by commas"
4967 ;;
5068 "redis" )
5169 dbtype=redis
5270 DB_PORT=${DB_PORT:-6379}
5371 [[ ( -n "${DB_PASS}" || ( -n "${DB_PASS_FILE}" ) ) ]] && file_env 'DB_PASS'
72+ [[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${DB_PASS}"
5473 ;;
5574 sqlite* )
5675 dbtype=sqlite3
@@ -61,39 +80,6 @@ bootstrap_variables() {
6180 file_env 'S3_KEY_ID'
6281 file_env 'S3_KEY_SECRET'
6382 fi
64-
65- ### Set the Database Authentication Details or parse any custom URIs
66- case "$dbtype" in
67- "mongo" )
68- if [ -n "${MONGO_CUSTOM_URI}" ] ; then
69- mongo_uri_proto=$(echo ${MONGO_CUSTOM_URI} | grep :// | sed -e's,^\(.*://\).*,\1,g')
70- mongo_uri_scratch="${MONGO_CUSTOM_URI/${mongo_uri_proto}/}"
71- mongo_uri_username_password=$(echo ${mongo_uri_scratch} | grep @ | rev | cut -d@ -f2- | rev)
72- if [ -n "${mongo_uri_username_password}" ]; then mongo_uri_scratch=$(echo ${mongo_uri_scratch} | rev | cut -d@ -f1 | rev) ; fi
73- mongo_uri_port=$(echo ${mongo_uri_scratch} | grep : | rev | cut -d: -f2- | rev)
74- if [ -n "${mongo_uri_port}" ]; then mongo_uri_port=$(echo ${mongo_uri_scratch} | rev | cut -d: -f1 | cut -d/ -f2 | rev) ; fi
75- mongo_uri_hostname=$(echo ${mongo_uri_scratch} | cut -d/ -f1 | cut -d: -f1 )
76- mongo_uri_database=$(echo ${mongo_uri_scratch} | cut -d/ -f2 | cut -d? -f1 )
77- mongo_uri_options=$(echo ${mongo_uri_scratch} | cut -d/ -f2 | cut -d? -f2 )
78- DB_NAME=${DB_NAME:-"${mongo_uri_database,,}"}
79- DB_HOST=${DB_HOST:-"${mongo_uri_hostname,,}"}
80- else
81- [[ ( -n "${DB_USER}" ) ]] && MONGO_USER_STR=" --username ${DB_USER}"
82- [[ ( -n "${DB_PASS}" ) ]] && MONGO_PASS_STR=" --password ${DB_PASS}"
83- [[ ( -n "${DB_NAME}" ) ]] && MONGO_DB_STR=" --db ${DB_NAME}"
84- [[ ( -n "${DB_AUTH}" ) ]] && MONGO_AUTH_STR=" --authenticationDatabase ${DB_AUTH}"
85- fi
86- ;;
87- "mysql" )
88- [[ ( -n "${DB_PASS}" ) ]] && export MYSQL_PWD=${DB_PASS}
89- ;;
90- "postgres" )
91- [[ ( -n "${DB_PASS}" ) ]] && POSTGRES_PASS_STR="PGPASSWORD=${DB_PASS}"
92- ;;
93- "redis" )
94- [[ ( -n "${DB_PASS}" ) ]] && REDIS_PASS_STR=" -a ${DB_PASS}"
95- ;;
96- esac
9783}
9884
9985backup_couch() {
@@ -168,7 +154,6 @@ backup_mongo() {
168154 mongo_compression="--gzip"
169155 compression_string="and compressing with gzip"
170156 fi
171-
172157 if [ -n "${MONGO_CUSTOM_URI}" ] ; then
173158 mongo_backup_parameter="--uri=${MONGO_CUSTOM_URI} ${EXTRA_OPTS}"
174159 else
821806 fi
822807 fi
823808}
824-
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