Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·218 lines (189 loc) · 6.58 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·218 lines (189 loc) · 6.58 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env bash
set -euo pipefail
#### USAGE and ARGUMENT CHECKING
usage()
{
echo "'run.sh' helps you to run the Mongo -> SQL analytics platform
Usage:
run.sh install
run.sh restore
run.sh connector
run.sh superset
run.sh schemacrawler
run.sh stop
run.sh reset
run.sh -h|--help
Options:
-h, --help Display usage and exit
Commands:
demo Download demo data, then run 'restore', 'connector' and 'superset'
install Initiate '.env' file. Pull / build all Docker images if they have changed.
restore Download and restore dump into mongosource. Then run 'connector' and 'superset'
connector Launch synchronisatino between mongosource and postgres through mongoconnector. Then run 'superset'
superset Start Superset
schemacrawler db Extract SQL Schema of database 'db'
stop Stop services
reset [service] Reset all services, or selected service. Ie remove volumes data and containers
"
exit
}
if [ -z ${1+x} ]
then
echo "Incorrect usage."; usage
fi
case $1 in
demo|install|restore|connector|superset|schemacrawler|stop|reset ) ;; #Ok, nothing needs to be done
-h|--help ) usage;;
* ) echo "Incorrect usage."; usage ;;
esac
#### INSTALL
if [ $1 == "install" ]
then
if [ ! -f .env ]; then
echo "Create '.env' file, based on template. You should modify environment values in this file."
cp env_template .env
else
echo "'.env' file already exists. We do not modify it."
fi
docker-compose pull
docker-compose build
exit
fi
#### DEMO
if [ $1 == "demo" ]
then
docker-compose up -d mongosource
docker-compose exec -T mongosource sh -c "/home/bin/download_demo_data_dump.sh"
./run.sh restore
./run.sh connector
./run.sh superset
docker-compose exec -T superset sh -c "/etc/superset/bin/import_dashboards.py"
./run.sh schemacrawler
exit
fi
# RESTORE
if [ $1 == "restore" ]
then
echo "== Restauring data in MongoDB source"
# Ask if we want to delete existing MongoDB schema, to make mongoconnector automatically extract new ones
if [ -d volumes/mongoconnector/data ]; then
cd volumes/mongoconnector/data
if [ ! -z "$(ls | grep schema | grep -v schema_filtered)" ]; then
while true; do
echo "MongoDB schemas already exists from previous run:"
echo `ls | grep schema | grep -v schema_filtered | tr ' ' '\n'`
echo
echo "If you restore data with a different schema, we should delete existing schemas."
echo "This will force mongoconnector to automatically extract new schemas with pymongo-schema."
read -p "Do you want to delete existing MongoDB schemas? [y|n] " yn
case $yn in
[Yy]* )
echo "Delete existing schemas : ";
echo
ls | grep schema | grep -v schema_filtered
rm -rf schema_*
break;;
[Nn]* )
echo "Going on with existing schemas :";
break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
cd ../../..
fi
#TODO: Following commented lines are useless for '.json' files. To be tested with bson dumps
#docker-compose stop mongosource
#echo "Delete existing data in MongoDB source"
#rm -rf volumes/mongosource/data/db
docker-compose up -d mongosource
echo "Waiting until MongoDB accepts connexions"
connectMO="docker-compose exec -T mongosource bash -c \"curl -s -o /dev/null -w '%{http_code}' http://mongosource:27017\" | sed 's/[^0-9]*//g'"
until [[ $(eval $connectMO) -eq "200" ]] ; do
printf '.'
sleep 1
done
docker-compose exec -T mongosource sh -c "/home/bin/restore_data_dump.sh"
exit
fi
### CONNECTOR
if [ $1 == "connector" ]
then
docker-compose stop mongoconnector
echo "== Run mongo-connector : "
echo "generate config.json and mapping_{DB}.json files, destroy and init PostgreSQL target databases, then sync MongoDB source with PostgreSQL"
docker-compose up -d mongoconnector
echo "You can follow synchronization logs by running 'docker-compose logs --follow mongoconnector'"
echo "You can also look at logs in 'volumes/mongoconnector/data/mongo-connector.log'"
exit
fi
### SUPERSET
if [ $1 == "superset" ]
then
echo "== Starts and initialize Superset"
docker-compose up -d superset
docker-compose exec superset sh -c "/etc/superset/bin/init_superset.sh" > volumes/superset/data/init_logs
echo "Superset is up at : http://localhost:8088"
exit
fi
### SCHEMACRAWLER
if [ $1 == "schemacrawler" ]
then
if [ $# = 1 ]; then
echo "You should give as additional parameter the name of the database you want to extract"
exit
fi
DATABASE=${2}
echo "== Starting SchemaCrawler, to extract a relational schema for database ${DATABASE}"
docker-compose run schemacrawler /schemacrawler/bin/extract_sql_schema.sh ${2}
echo "The SQL schema is available in folder volumes/schemacrawler/data."
exit
fi
#### STOP
if [ $1 == "stop" ]
then
echo "== Stopping services of the Mongo -> SQL analytics platform..."
docker-compose stop
echo "Services are stopped. Goodbye !"
exit
fi
#### RESET
if [ $1 == "reset" ]
then
if [ $# = 1 ]; then
service=all
else
service=$2
fi
case ${service} in
all|mongosource|mongoconnector|postgres|superset|redis|schemacrawler ) ;; #Ok, nothing needs to be done
* ) echo "Incorrect usage. We can only reset one of the following service : mongosource, mongoconnector, postgres, schemacrawler, superset or redis"; exit;;
esac
while true; do
if [ ${service} == "all" ];
then
echo "This WILL DELETE ALL DATA and CONTAINERS of ALL services : mongosource, mongoconnector, postgres, schemacrawler, superset & redis."
else
echo "This WILL DELETE ALL DATA and CONTAINER of service ${service}."
fi
read -p "Are you sure? [y|n] : " yn
case $yn in
[Yy]* ) echo "yes"; break;;
[Nn]* ) echo "Abort"; exit;;
* ) echo "Please answer yes or no.";;
esac
done
if [ ${service} == "all" ];
then
docker-compose stop
cd volumes
rm -rf */data
cd ..
yes | docker-compose rm
else
docker-compose stop ${service}
rm -rf volumes/${service}/data
yes | docker-compose rm ${service}
fi
exit
fi