diff --git a/.env-example b/.env-example index a2c18b9..4aaed61 100644 --- a/.env-example +++ b/.env-example @@ -3,7 +3,12 @@ BACKUP_DIR=/home/myuser/preciousdata MYSQL_HOST=localhost MYSQL_USER=root MYSQL_PASS=toor -# Databases to skip with no space between the args separated by a , + +# (Optional) Databases to skip with no space between the args separated by a , SKIP_DATABASES=mysql,information_schema,performance_schema,phpmyadmin -# No not use if you are a goat -EXPERT_ARGS=--default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc \ No newline at end of file + +# (Optional) No not use if you are a goat +EXPERT_ARGS=--default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc + +# (Optional) Command called on script success, WITH the double quotes ! +ON_SUCCESS="echo 'Hello world'" diff --git a/README.md b/README.md index f325384..cf27d9f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ vi .env | MYSQL_PASS | | YES | | SKIP_DATABASES | | YES | | EXPERT_ARGS | --default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc | YES | +| ON_SUCCESS | | YES | + +> ON_SUCCESS is called on script success ## Example .env @@ -53,4 +56,4 @@ SKIP_DATABASES=mysql,information_schema,performance_schema,phpmyadmin | views.sql | The views | | triggers.sql | The triggers | | routines.sql | All the procedures & functions | -| users.sql | All MySQL users | \ No newline at end of file +| users.sql | All MySQL users | diff --git a/backup.sh b/backup.sh index e49c3f1..8ac1d71 100755 --- a/backup.sh +++ b/backup.sh @@ -1,7 +1,12 @@ #!/bin/bash -export -n $(egrep -v '^#' $(dirname $0)/.env | xargs) - +# from : github:builtinnya/dotenv-shell-loader +DOTENV_SHELL_LOADER_SAVED_OPTS=$(set +o) +set -o allexport +[ -f "$(dirname $0)/.env" ] && source "$(dirname $0)/.env" +set +o allexport +eval "$DOTENV_SHELL_LOADER_SAVED_OPTS" +unset DOTENV_SHELL_LOADER_SAVED_OPTS if [ -z "${BACKUP_DIR}" ]; then echo "Empty Variable BACKUP_DIR" @@ -116,4 +121,6 @@ sed -i -e 's/\\\\//g' ${BACKUP_DIR}/grants.sql # echo -e ${GRANTS_SQL} echo "Backup done !" - +if [ ! -z "${ON_SUCCESS}" ]; then +`echo ${ON_SUCCESS}` +fi