Skip to content

Commit

Permalink
Added support for a command on script success
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Apr 6, 2018
1 parent 9352fa6 commit e5e48da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 8 additions & 3 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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

# (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'"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 |
| users.sql | All MySQL users |
13 changes: 10 additions & 3 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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

0 comments on commit e5e48da

Please sign in to comment.