-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone-db.sh
executable file
·47 lines (36 loc) · 1.16 KB
/
clone-db.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
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
DB_HOST=${DB_HOST:-127.0.0.1}
DB_USER=${DB_USER:-root}
DB_PASS=${DB_PASS:-}
DB_NAME=${DB_NAME:-test}
CLONE_DB_HOST=${CLONE_DB_HOST:-$DB_HOST}
CLONE_DB_USER=${CLONE_DB_USER:-$DB_USER}
CLONE_DB_PASS=${CLONE_DB_PASS:-$DB_PASS}
CLONE_DB_NAME=${CLONE_DB_NAME:-"${DB_NAME}-copy"}
TEMPDIR="/tmp"
OUTDIR=${OUTDIR:-"${TEMPDIR}/outdir"}
SKIP_OUTDIR=${SKIP_OUTDIR:-"false"}
if [ ! -d "${OUTDIR}" ]; then
mkdir -p $OUTDIR
fi
{ \
echo [client]
echo host=${DB_HOST}
echo user=${DB_USER}
echo password="${DB_PASS}"
echo [mydumper]
} > "${TEMPDIR}/.mydumper.cnf"
{ \
echo [client]
echo host=${CLONE_DB_HOST}
echo user=${CLONE_DB_USER}
echo password="${CLONE_DB_PASS}"
echo [myloader]
} > "${TEMPDIR}/.myloader.cnf"
mydumper --defaults-file ${TEMPDIR}/.mydumper.cnf -o $OUTDIR --routines --triggers --events --skip-definer --database "${DB_NAME}" --verbose 3 $EXTRA_MYDUMPER_ARGS
myloader --defaults-file ${TEMPDIR}/.myloader.cnf -d $OUTDIR --database "${CLONE_DB_NAME}" --verbose 3 $EXTRA_MYLOADER_ARGS
if [ "false" == "${SKIP_OUTDIR}" ]; then
rm -rf $OUTDIR
fi
rm -f "${TEMPDIR}/.mydumper.cnf"
rm -f "${TEMPDIR}/.myloader.cnf"