Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 009ce0f

Browse files
author
Jonathan Mills
committed
Allow read of DB_xxxx env variables from DB_xxxx__FILE docker secrets
1 parent 4d986be commit 009ce0f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

mariadb-backup.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ set -e
66
# Based on the mode, different default options will be set.
77
#
88

9+
file_env() {
10+
local var="$1"
11+
local fileVar="${var}__FILE"
12+
local def="${2:-}"
13+
14+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
15+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
16+
exit 1
17+
fi
18+
local val="$def"
19+
if [ "${!var:-}" ]; then
20+
val="${!var}"
21+
elif [ "${!fileVar:-}" ]; then
22+
val="$(< "${!fileVar}")"
23+
fi
24+
export "$var"="$val"
25+
unset "$fileVar"
26+
}
27+
28+
if [[ "${DB_USER}" == "root" ]]; then
29+
#
30+
# If this is set to the default, then unset it in case we are going to get it from a secret
31+
#
32+
unset DB_USER
33+
fi
34+
35+
file_env "DB_PASS"
36+
file_env "DB_USER"
37+
file_env "DB_HOST"
38+
file_env "DB_NAME"
39+
940
MODE=${MODE:-BACKUP}
1041
TARBALL=${TARBALL:-}
1142
DB_PORT=${DB_PORT:-3306}
@@ -43,7 +74,7 @@ echo " UID: ${BACKUP_UID:=666}"
4374
echo " GID: ${BACKUP_GID:=666}"
4475
echo " Umask: ${UMASK:=0022}"
4576
echo
46-
echo " Base directory: i ${BASE_DIR:=/backup}"
77+
echo " Base directory: ${BASE_DIR:=/backup}"
4778
[[ "${MODE^^}" == "RESTORE" ]] && \
4879
echo " Restore directory: ${RESTORE_DIR}"
4980
echo

0 commit comments

Comments
 (0)