Skip to content

Commit e5e48da

Browse files
committed
Added support for a command on script success
1 parent 9352fa6 commit e5e48da

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

.env-example

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ BACKUP_DIR=/home/myuser/preciousdata
33
MYSQL_HOST=localhost
44
MYSQL_USER=root
55
MYSQL_PASS=toor
6-
# Databases to skip with no space between the args separated by a ,
6+
7+
# (Optional) Databases to skip with no space between the args separated by a ,
78
SKIP_DATABASES=mysql,information_schema,performance_schema,phpmyadmin
8-
# No not use if you are a goat
9-
EXPERT_ARGS=--default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc
9+
10+
# (Optional) No not use if you are a goat
11+
EXPERT_ARGS=--default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc
12+
13+
# (Optional) Command called on script success, WITH the double quotes !
14+
ON_SUCCESS="echo 'Hello world'"

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ vi .env
3131
| MYSQL_PASS | | YES |
3232
| SKIP_DATABASES | | YES |
3333
| EXPERT_ARGS | --default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc | YES |
34+
| ON_SUCCESS | | YES |
35+
36+
> ON_SUCCESS is called on script success
3437
3538
## Example .env
3639

@@ -53,4 +56,4 @@ SKIP_DATABASES=mysql,information_schema,performance_schema,phpmyadmin
5356
| views.sql | The views |
5457
| triggers.sql | The triggers |
5558
| routines.sql | All the procedures & functions |
56-
| users.sql | All MySQL users |
59+
| users.sql | All MySQL users |

backup.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22

3-
export -n $(egrep -v '^#' $(dirname $0)/.env | xargs)
4-
3+
# from : github:builtinnya/dotenv-shell-loader
4+
DOTENV_SHELL_LOADER_SAVED_OPTS=$(set +o)
5+
set -o allexport
6+
[ -f "$(dirname $0)/.env" ] && source "$(dirname $0)/.env"
7+
set +o allexport
8+
eval "$DOTENV_SHELL_LOADER_SAVED_OPTS"
9+
unset DOTENV_SHELL_LOADER_SAVED_OPTS
510

611
if [ -z "${BACKUP_DIR}" ]; then
712
echo "Empty Variable BACKUP_DIR"
@@ -116,4 +121,6 @@ sed -i -e 's/\\\\//g' ${BACKUP_DIR}/grants.sql
116121
# echo -e ${GRANTS_SQL}
117122

118123
echo "Backup done !"
119-
124+
if [ ! -z "${ON_SUCCESS}" ]; then
125+
`echo ${ON_SUCCESS}`
126+
fi

0 commit comments

Comments
 (0)