Merge "OOM changes to support PE https"
[oom.git] / kubernetes / portal / docker / init / mariadb-client / db_migrate.sh
1 # Copyright © 2018 Amdocs, Bell Canada, AT&T
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #!/bin/sh -x
16 SQL_DEST_DIR=${SQL_DEST_DIR:-/tmp/sql}
17 DB_PORT=${DB_PORT:-3306}
18
19 [[ -z "$SQL_SRC_DIR" ]] && { echo "Error: SQL_SRC_DIR must be provided as an environment variable"; exit 1; }
20 [[ -z "$DB_USER" ]] && { echo "Error: DB_USER must be provided as an environment variable"; exit 1; }
21 [[ -z "$DB_PASS" ]] && { echo "Error: DB_PASS must be provided as an environment variable"; exit 1; }
22 [[ -z "$DB_HOST" ]] && { echo "Error: DB_HOST must be provided as an environment variable"; exit 1; }
23
24 mkdir -p $SQL_DEST_DIR
25
26 #Find all sql files and copy them to the destination directory
27 find "/onap-sources/$SQL_SRC_DIR" -type f -iname "*.sql" | awk -v dest="$SQL_DEST_DIR" '{n=split($1,a,"/"); system(sprintf( "cp %s %s", $1, dest"/"a[n])) }'
28
29
30 #Not needed right now?
31 #--database=$DB_NAME
32
33 #--force to deal with duplicate records in absense of "insert ignore"
34 ##ERROR 1062 (23000) at line 382: Duplicate entry '2' for key 'PRIMARY'
35
36 cd $SQL_DEST_DIR
37 cat *.sql | mysql -vv --user=$DB_USER --password=$DB_PASS --host=$DB_HOST --port=$DB_PORT --force