-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·37 lines (28 loc) · 909 Bytes
/
backup.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
#!/usr/bin/env bash
set -ex
echo "Backup MariaDB"
if [[ ! -z "${PRE_HOOK}" ]]
then
echo Run pre-hook: "${PRE_HOOK}"
eval "${PRE_HOOK}"
fi
MARIADB_PARAMS="-u${DB_USER:-root} -p${DB_PASSWORD} -h${DB_HOST:-mariadb} -P${DB_PORT:-3306}"
DATABASES=$(mysql -N ${MARIADB_PARAMS} -e 'show databases')
for DATABASE in $DATABASES
do
if [[ $EXCLUDE_DATABASES =~ (^|[[:space:]])$DATABASE($|[[:space:]]) ]]
then
echo Skip database "${DATABASE}"
else
BACKUP_FILE="${BACKUP_DIR:-/var/backups}/${DATABASE}.sql"
echo Backup database "${DATABASE}" to "${BACKUP_FILE}"
mysqldump ${MARIADB_PARAMS} --complete-insert --routines --triggers --single-transaction "$DATABASE" > "${BACKUP_FILE}"
echo Finished backup "${DATABASE}"
fi
done
echo "Backups complete"
if [[ ! -z "${POST_HOOK}" ]]
then
echo Run post-hook: "${POST_HOOK}"
eval "${POST_HOOK}"
fi