forked from pinterest/teletraan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploydb.sh
executable file
·76 lines (67 loc) · 1.6 KB
/
deploydb.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
#!/bin/bash
# Exit upon any errors
set -e
# Set defaults
HOST=
PORT=
USER=root
PASSWORD=
SQLFILE=/var/teletraan/sql/deploy.sql
DRYRUN=false
usage() {
echo "Usage: deploydb [-H|--host HOST] [-P|--port PORT]"
echo " [-u|--user USERNAME] [-p|--password PASSWORD]"
echo " [-f|--file FILE]"
echo " [-h|--help]"
echo "optional arguments:"
echo "-h, --help show this help message and exit"
echo "-H, --host HOST DB server host name, default is localhost"
echo "-P, --port HOST DB server port number, default is 3306"
echo "-u, --user USERNAME DB server user name, default is root"
echo "-p, --password PASSWORD DB server password, default is empty"
echo "-f, --file SQL file to execute, default is /var/teletraan/sql/deploy.sql"
}
while [[ $# -ge 1 ]]
do
key="$1"
case $key in
-H|--host)
HOST="$2"
shift # past argument
;;
-P|--port)
PORT="$2"
shift # past argument
;;
-u|--user)
USER="$2"
shift # past argument
;;
-p|--password)
PASSWORD="$2"
shift # past argument
;;
-d|--database)
DATABASE="$2"
shift # past argument
;;
-f|--file)
SQLFILE="$2"
shift # past argument
;;
-h|--help)
usage #unknown option
exit 0
;;
*)
echo "Unknown option $1"
usage #unknown option
exit 1
;;
esac
shift # past argument or value
done
[ ! -z "$HOST" ] && HOST="--host=$HOST"
[ ! -z "$PORT" ] && PORT="--port=$PORT"
[ ! -z "$PASSWORD" ] && PASSWORD="--password=$PASSWORD"
mysql $HOST $PORT -u $USER $PASSWORD < $SQLFILE