Skip to content

Commit d174580

Browse files
committed
Added BACKUP_CONFIG_ENVFILE
See CHANGELOG.md of this commit
1 parent 081e8f0 commit d174580

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

.env-example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ MYSQL_HOST=localhost
44
MYSQL_USER=root
55
MYSQL_PASS=toor
66

7-
# (Optional) Databases to skip with no space between the args separated by a ,
7+
# (Optional, use recommended example below ) Databases to skip with no space between the args separated by a ,
88
SKIP_DATABASES=mysql,information_schema,performance_schema,phpmyadmin
99

1010
# (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
11+
# EXPERT_ARGS=--default-character-set=utf8 --extended-insert=FALSE --single-transaction --skip-comments --skip-dump-date --hex-blob --tz-utc
1212

1313
# (Optional) Command called on script success, WITH the double quotes !
14-
ON_SUCCESS="echo 'Hello world'"
14+
# ON_SUCCESS="echo 'Hello world'"

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- Check if mysql and mysqldump are installed
10-
10+
- Updated README.md
11+
- Added optional `BACKUP_CONFIG_ENVFILE` variable to set the env file location
12+
- Updated .env-example (commented out some optional variables)
13+
- Added check if `BACKUP_DIR` exists
1114

1215
## [1.0.0] - 2018-04-07
1316
### Added

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@ cp .env-example .env
1717
```bash
1818
nano .env
1919
```
20-
or
20+
or
2121
```bash
2222
vi .env
2323

24+
```
25+
then
26+
```
27+
./backup.sh
28+
```
29+
## Extras
30+
31+
To use an external env file in a custom location use example:
32+
```bash
33+
34+
export BACKUP_CONFIG_ENVFILE="/home/myuser/secretbackupconfig.env.txt"
35+
36+
./backup.sh
37+
38+
unset BACKUP_CONFIG_ENVFILE
2439
```
2540

2641
## Options

backup.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
# from : github:builtinnya/dotenv-shell-loader
44
DOTENV_SHELL_LOADER_SAVED_OPTS=$(set +o)
55
set -o allexport
6-
[ -f "$(dirname $0)/.env" ] && source "$(dirname $0)/.env"
6+
if [ ! -z "${BACKUP_CONFIG_ENVFILE}" ]; then
7+
if [ ! -f "${BACKUP_CONFIG_ENVFILE}" ]; then
8+
echo "Value of variable BACKUP_CONFIG_ENVFILE is not a file (${BACKUP_CONFIG_ENVFILE})"
9+
exit 1
10+
else
11+
[ -f "${BACKUP_CONFIG_ENVFILE}" ] && source "${BACKUP_CONFIG_ENVFILE}"
12+
fi
13+
else
14+
[ -f "$(dirname $0)/.env" ] && source "$(dirname $0)/.env"
15+
fi
716
set +o allexport
817
eval "$DOTENV_SHELL_LOADER_SAVED_OPTS"
918
unset DOTENV_SHELL_LOADER_SAVED_OPTS
@@ -21,6 +30,11 @@ fi
2130
if [ -z "${BACKUP_DIR}" ]; then
2231
echo "Empty Variable BACKUP_DIR"
2332
exit 1
33+
else
34+
if [ ! -d "${BACKUP_DIR}" ]; then
35+
echo "Value of variable BACKUP_DIR is not a directory (${BACKUP_DIR})"
36+
exit 1
37+
fi
2438
fi
2539

2640
if [ -z "${MYSQL_HOST}" ]; then

0 commit comments

Comments
 (0)