-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.sh
executable file
·38 lines (34 loc) · 1.2 KB
/
dump.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
DB_USER=${DB_USER:-${MYSQL_ENV_DB_USER}}
DB_PASS=${DB_PASS:-${MYSQL_ENV_DB_PASS}}
DB_NAME=${DB_NAME:-${MYSQL_ENV_DB_NAME}}
DB_HOST=${DB_HOST:-${MYSQL_ENV_DB_HOST}}
ALL_DATABASES=${ALL_DATABASES}
IGNORE_DATABASE=${IGNORE_DATABASE}
if [[ ${DB_USER} == "" ]]; then
echo "Missing DB_USER env variable"
exit 1
fi
if [[ ${DB_PASS} == "" ]]; then
echo "Missing DB_PASS env variable"
exit 1
fi
if [[ ${DB_HOST} == "" ]]; then
echo "Missing DB_HOST env variable"
exit 1
fi
if [[ ${ALL_DATABASES} == "" ]]; then
if [[ ${DB_NAME} == "" ]]; then
echo "Missing DB_NAME env variable"
exit 1
fi
mysqldump --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" "$@" "${DB_NAME}" > /mysqldump/"${DB_NAME}".sql
else
databases=`mysql --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "$IGNORE_DATABASE" ]]; then
echo "Dumping database: $db"
mysqldump --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --databases $db > /mysqldump/$db.sql
fi
done
fi