-
Notifications
You must be signed in to change notification settings - Fork 0
/
do-dup.sh
28 lines (21 loc) · 927 Bytes
/
do-dup.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
#!/bin/bash
set -e
export SRC_HOST=${SRC_HOST}
export SRC_NAME=${SRC_NAME}
export SRC_USER=${SRC_USER}
export SRC_PASS=${SRC_PASS}
export SRC_PORT=${SRC_PORT:-"3306"}
export DST_HOST=${DST_HOST}
export DST_NAME=${DST_NAME}
export DST_USER=${DST_USER}
export DST_PASS=${DST_PASS}
export DST_PORT=${DST_PORT:-"3306"}
DUMP_OPTIONS="--single-transaction --quick --skip-lock-tables --max-allowed-packet=1000000000"
echo "Dropping and recreating destination DB"
mysql -u$DST_USER -p$DST_PASS -h$DST_HOST -P$DST_PORT --execute "DROP DATABASE IF EXISTS $DST_NAME"
mysql -u$DST_USER -p$DST_PASS -h$DST_HOST -P$DST_PORT --execute "CREATE DATABASE $DST_NAME"
echo "Dumping the source DB"
mysqldump -u$SRC_USER -p$SRC_PASS -h$SRC_HOST -P$SRC_PORT $DUMP_OPTIONS $SRC_NAME > dump.sql
echo "Importing into the destination DB"
mysql -u$DST_USER -p$DST_PASS -h$DST_HOST -P$DST_PORT $DST_NAME < dump.sql
echo "DB Dup Operation Complete!"