forked from cosmin/elasticpony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate_to_rds.sh
executable file
·76 lines (61 loc) · 1.39 KB
/
migrate_to_rds.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
SCRIPT_NAME=$0
usage() {
cat <<EOF
Usage: $SCRIPT_NAME OPTIONS
Required:
-H DATABASE_HOST
-D DATABASE_NAME the database name
-U DATABASE_USER the database user
-P DATABASE_PASSWORD the database password
EOF
}
die() {
message=$1
error_code=$2
echo "$SCRIPT_NAME: $message" 1>&2
usage
exit $error_code
}
while getopts "hH:D:U:P:" opt; do
case "$opt" in
h)
usage
exit 0
;;
H)
export DATABASE_HOST="$OPTARG"
;;
D)
export DATABASE_NAME="$OPTARG"
;;
U)
export DATABASE_USER="$OPTARG"
;;
P)
export DATABASE_PASSWORD="$OPTARG"
;;
[?])
die "unknown option $opt" 10
;;
esac
done
if [ -z "$DATABASE_HOST" ]; then
die "URL is required" 1
fi
if [ -z "$DATABASE_NAME" ]; then
die "DATABASE_NAME is required" 2
fi
if [ -z "$DATABASE_USER" ]; then
die "DATABASE_NAME is required" 3
fi
if [ -z "$DATABASE_PASSWORD" ]; then
die "DATABASE_PASSWORD is required" 4
fi
dump_sql() {
mysqldump --user=$DATABASE_USER --password=$DATABASE_PASSWORD $DATABASE_NAME > local_db_dump.sql
}
load_sql() {
mysql --host=$DATABASE_HOST --user=$DATABASE_USER --password=$DATABASE_PASSWORD $DATABASE_NAME < local_db_dump.sql
}
dump_sql && load_sql