-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_import.sh
46 lines (43 loc) · 1.08 KB
/
db_import.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
# Old servers
#Its the old/live db server name. Either put ip address or server name configured in SSH config
OLD_DBSERVER=""
#By default SSH port is used.
SSHPORT=""
#SSH user name
SSHUN=""
#Database name in old server.
DATABASES=""
#Sometime db is not present on dbserver. In that case, give the name/ip of server where db is presesnt.
DBHOST=""
#mysql db username
DBUN=""
#mysql db user's password.
DBPW=""
# TO ENABLE DRY RUN DO DRY_RUN="--dry-run". It wont sync the db actually but will only show output of whats it gonna do.
DRY_RUN=""
# Print the command
echo ssh -p ${SSHPORT} -C ${SSHUN}@${OLD_DBSERVER} \
"mysqldump \
--host=${DBHOST} \
--user=${DBUN} \
--password=${DBPW} \
--routines \
--triggers \
--single-transaction \
--skip-tz-utc \
--databases ${DATABASES}"
if [ "$DRY_RUN" != "" ]; then
echo "Dry run is on"
else
# Do the db dump
ssh -p ${SSHPORT} -C ${SSHUN}@${OLD_DBSERVER} \
"mysqldump \
--host=${DBHOST} \
--user=${DBUN} \
--password=${DBPW} \
--routines \
--triggers \
--single-transaction \
--skip-tz-utc \
--databases ${DATABASES}" | mysql
fi