-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-complete-migration-remote.sh
executable file
·182 lines (148 loc) · 3.75 KB
/
run-complete-migration-remote.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
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
#!/bin/bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-c)
MDM_DOCKER_CONTAINER="$2"
shift # past argument
shift # past value
;;
-m)
MC_DOCKER_CONTAINER="$2"
shift # past argument
shift # past value
;;
-d)
MDM_DATABASE="$2"
shift # past argument
shift # past value
;;
-o)
MC_DATABASE="$2"
shift # past argument
shift # past value
;;
-p)
MDM_PORT="$2"
shift # past argument
shift # past value
;;
-h)
MDM_HOST="$2"
shift # past argument
shift # past value
;;
-q)
MC_PORT="$2"
shift # past argument
shift # past value
;;
-i)
MC_HOST="$2"
shift # past argument
shift # past value
;;
--help)
USAGE=true
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
##################
if [ $USAGE ]
then
echo "Usage:: run-migration-remote.sh [--help] [-d MDM_DATABASE]"
echo
echo " -d MDM_DATABASE : Optional argument to set the mdm database inside to"
echo " the docker container execute the migration against."
echo " Default: maurodatamapper"
echo " -o MC_DATABASE : Optional argument to set the mc database inside to"
echo " the docker container execute the migration against."
echo " Default: catalogue"
echo " -h MDM_HOST : Optional argument to set the mdm database host"
echo " Default: localhost"
echo " -p MDM_PORT : Optional argument to set the mdm database port"
echo " Default: 5432"
echo " -i MC_HOST : Optional argument to set the mc database host"
echo " Default: localhost"
echo " -q MC_PORT : Optional argument to set the mc database port"
echo " Default: 5432"
echo " --help : This help"
echo
exit 0
fi
##################
echo "Performing complete non-interactive migration"
if [ -n "$MDM_DATABASE" ]
then
echo "Using database: $MDM_DATABASE"
else
MDM_DATABASE='maurodatamapper'
echo "Using default database: maurodatamapper"
fi
if [ -n "$MC_DATABASE" ]
then
echo "Using database: $MC_DATABASE"
else
MC_DATABASE='catalogue'
echo "Using default database: catalogue"
fi
MC_DB_ARGS="-U postgres"
if [ -n "$MC_HOST" ]
then
MC_DB_ARGS="$DB_ARGS -h $MC_HOST"
fi
if [ -n "$MC_PORT" ]
then
MC_DB_ARGS="$DB_ARGS -p $MC_PORT"
fi
MDM_DB_ARGS="-U postgres"
if [ -n "$MDM_HOST" ]
then
MDM_DB_ARGS="$DB_ARGS -h $MDM_HOST"
fi
if [ -n "$MDM_PORT" ]
then
MDM_DB_ARGS="$DB_ARGS -p $MDM_PORT"
fi
##################
echo
echo "<< Stage 1 >>"
echo "Extracting mc-dump.sql"
pushd mc-extraction
pg_dump -F p -n public $MC_DB_ARGS $MC_DATABASE > output/mc-dump.sql
echo "Preparing mc-dump.sql for loading into MDM"
sed 's/public\./metadatacatalogue\./g' output/mc-dump.sql | \
sed 's/CREATE SCHEMA public;/CREATE SCHEMA metadatacatalogue;/' | \
sed 's/ALTER SCHEMA public OWNER TO postgres;//' > output/mc-dump-to-load.sql
popd
echo
echo "<< Stage 2 >>"
echo "Loading mc-dump-to-load.sql"
pushd mc-extraction
cat output/mc-dump-to-load.sql | psql $MDM_DB_ARGS $MDM_DATABASE
popd
echo
echo "<< Stage 3>>"
echo " Performing SQL migration"
pushd migration
RUN_ARGS=$MDM_DATABASE
if [ -n "$MDM_HOST" ]
then
RUN_ARGS="$RUN_ARGS -h $MDM_HOST "
fi
if [ -n "$MDM_PORT" ]
then
RUN_ARGS="$RUN_ARGS -p $MDM_PORT "
fi
./run-migration-remote.sh -d $MDM_DATABASE $RUN_ARGS
popd
echo "Complete"
#################