diff --git a/backup.sh b/backup.sh index d251ed7..450bb41 100755 --- a/backup.sh +++ b/backup.sh @@ -1,10 +1,18 @@ #!/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; } -# 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}"); } -# Alternatively, take it from env var [ -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; } DATE=$(date +%Y%m%d%H%M) diff --git a/restore.sh b/restore.sh index 15d6b81..e17b61c 100755 --- a/restore.sh +++ b/restore.sh @@ -1,10 +1,14 @@ #!/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; } -# 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}"); } -# Alternatively, take it from env var -[ -z "${MYSQL_PASS}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; } +[ -z "${MYSQL_PASS:=$MYSQL_PASSWORD}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; } if [ "$#" -ne 1 ] then @@ -14,7 +18,7 @@ fi set -o pipefail if [ -z "${USE_PLAIN_SQL}" ] -then +then SQL=$(gunzip -c "$1") else SQL=$(cat "$1")