-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-db.sh
executable file
·46 lines (31 loc) · 1.12 KB
/
sync-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
#!/usr/bin/env bash
HOST=abryrath.com
USER=abry
ENV_FILE=caitlinandabry-com/.env
DUMP_FILE=/tmp/caitlinandabry-com.prod.sql
SSH_OPTS="${USER}@${HOST}"
DEBUG=0
if [[ ! -z "$1" ]]; then
DEBUG=1
fi
debug() {
[ $DEBUG -eq 1 ] && {
echo "$1"
}
}
db_user=$(ssh "${SSH_OPTS}" grep -e "DB_USER" "${ENV_FILE}" | cut -d "\"" -f 2)
debug "Got user: ${db_user}"
db_pass=$(ssh "${SSH_OPTS}" grep -e "DB_PASSWORD" "${ENV_FILE}" | cut -d "\"" -f 2)
debug "Got pass: ${db_pass}"
db_name=$(ssh "${SSH_OPTS}" grep -e "DB_DATABASE" "${ENV_FILE}" | cut -d "\"" -f 2)
debug "Got database: ${db_name}"
ssh "${SSH_OPTS}" mysqldump -u"${db_user}" -p"\"${db_pass}\"" "${db_name}" > "${DUMP_FILE}"
debug "Got SQL file"
local_user=$(grep -e "DB_USER" .env | cut -d "\"" -f 2)
debug "Got local user"
local_pass=$(grep -e "DB_PASSWORD" .env | cut -d "\"" -f 2)
debug "Got local pass"
local_name=$(grep -e "DB_DATABASE" .env | cut -d "\"" -f 2)
debug "Got local db"
debug "mysql -u\"${local_user}\" -p\"${local_pass}\" \"${local_name}\" < \"${DUMP_FILE}\""
eval mysql -u"${local_user}" -p"${local_pass}" "${local_name}" < "${DUMP_FILE}"