mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-18 16:22:33 +01:00
Add ability to use secrets for mysql access
This commit is contained in:
parent
d07cf4ffb7
commit
37a8400103
2 changed files with 18 additions and 6 deletions
12
backup.sh
12
backup.sh
|
@ -1,10 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Get hostname: try read from file, else get from env
|
||||||
|
[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_HOST_FILE}"); }
|
||||||
|
[ -z "${MYSQL_HOST}" ] && { echo "=> MYSQL_HOST cannot be empty" && exit 1; }
|
||||||
|
# Get username: try read from file, else get from env
|
||||||
|
[ -z "${MYSQL_USER_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_USER_FILE}"); }
|
||||||
[ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
|
[ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
|
||||||
# If provided, take password from file
|
# Get password: try read from file, else get from env, else get from MYSQL_PASSWORD env
|
||||||
[ -z "${MYSQL_PASS_FILE}" ] || { MYSQL_PASS=$(head -1 "${MYSQL_PASS_FILE}"); }
|
[ -z "${MYSQL_PASS_FILE}" ] || { MYSQL_PASS=$(head -1 "${MYSQL_PASS_FILE}"); }
|
||||||
# Alternatively, take it from env var
|
|
||||||
[ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
[ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
||||||
|
# Get database name(s): try read from file, else get from env
|
||||||
|
# Note: when from file, there can be one database name per line in that file
|
||||||
|
[ -z "${MYSQL_DATABASE_FILE}" ] || { MYSQL_DATABASE=$(cat "${MYSQL_DATABASE_FILE}"); }
|
||||||
|
# Get level from env, else use 6
|
||||||
[ -z "${GZIP_LEVEL}" ] && { GZIP_LEVEL=6; }
|
[ -z "${GZIP_LEVEL}" ] && { GZIP_LEVEL=6; }
|
||||||
|
|
||||||
DATE=$(date +%Y%m%d%H%M)
|
DATE=$(date +%Y%m%d%H%M)
|
||||||
|
|
12
restore.sh
12
restore.sh
|
@ -1,10 +1,14 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Get hostname: try read from file, else get from env
|
||||||
|
[ -z "${MYSQL_HOST_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_HOST_FILE}"); }
|
||||||
|
[ -z "${MYSQL_HOST}" ] && { echo "=> MYSQL_HOST cannot be empty" && exit 1; }
|
||||||
|
# Get username: try read from file, else get from env
|
||||||
|
[ -z "${MYSQL_USER_FILE}" ] || { MYSQL_USER=$(head -1 "${MYSQL_USER_FILE}"); }
|
||||||
[ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
|
[ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
|
||||||
# If provided, take password from file
|
# Get password: try read from file, else get from env, else get from MYSQL_PASSWORD env
|
||||||
[ -z "${MYSQL_PASS_FILE}" ] || { MYSQL_PASS=$(head -1 "${MYSQL_PASS_FILE}"); }
|
[ -z "${MYSQL_PASS_FILE}" ] || { MYSQL_PASS=$(head -1 "${MYSQL_PASS_FILE}"); }
|
||||||
# Alternatively, take it from env var
|
[ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
||||||
[ -z "${MYSQL_PASS}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
|
||||||
|
|
||||||
if [ "$#" -ne 1 ]
|
if [ "$#" -ne 1 ]
|
||||||
then
|
then
|
||||||
|
@ -14,7 +18,7 @@ fi
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
if [ -z "${USE_PLAIN_SQL}" ]
|
if [ -z "${USE_PLAIN_SQL}" ]
|
||||||
then
|
then
|
||||||
SQL=$(gunzip -c "$1")
|
SQL=$(gunzip -c "$1")
|
||||||
else
|
else
|
||||||
SQL=$(cat "$1")
|
SQL=$(cat "$1")
|
||||||
|
|
Loading…
Reference in a new issue