4 # Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
5 # This file is part of openmano
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
26 * Copyright 2017 Telefonica Investigacion y Desarrollo, S.A.U.
27 * This file is part of openmano
28 * All Rights Reserved.
30 * Licensed under the Apache License, Version 2.0 (the "License"); you may
31 * not use this file except in compliance with the License. You may obtain
32 * a copy of the License at
34 * http://www.apache.org/licenses/LICENSE-2.0
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
38 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
39 * License for the specific language governing permissions and limitations
42 * For those usages not covered by the Apache License, Version 2.0 please
43 * contact with: nfvlabs@tid.es
57 DIRNAME
=`dirname $(readlink -f $0)`
60 echo -e "Usage: $0 OPTIONS"
61 echo -e " Dumps openmano database content"
63 echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails"
64 echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails"
65 echo -e " -P PORT database port. '$DBPORT' by default"
66 echo -e " -h HOST database host. '$DBHOST' by default"
67 echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
68 echo -e " --help shows this help"
71 while getopts ":u:p:P:h:-:" o
; do
89 [ "${OPTARG}" == "help" ] && usage
&& exit 0
90 echo "Invalid option: --$OPTARG" >&2 && usage
>&2
94 echo "Invalid option: -$OPTARG" >&2 && usage
>&2
98 echo "Option -$OPTARG requires an argument." >&2 && usage
>&2
109 #check and ask for database user password
112 [ -n "$DBPASS" ] && DBPASS_
="-p$DBPASS"
115 while ! echo ";" | mysql
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev
/null
2>&1
117 [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
118 [ -z "$logintry" ] && echo -e "\nProvide database name and credentials"
119 read -e -p "mysql database name($DBNAME): " KK
120 [ -n "$KK" ] && DBNAME
="$KK"
121 read -e -p "mysql user($DBUSER): " KK
122 [ -n "$KK" ] && DBUSER
="$KK" && DBUSER_
="-u$DBUSER"
123 read -e -s -p "mysql password: " DBPASS
124 [ -n "$DBPASS" ] && DBPASS_
="-p$DBPASS"
125 [ -z "$DBPASS" ] && DBPASS_
=""
131 #echo structure, including the content of schema_version
132 echo "$LICENSE_HEAD" > ${DIRNAME}/${DBNAME}_structure.sql
133 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --no-data --add-drop-table --add-drop-database --routines --databases $DBNAME >> ${DIRNAME}/${DBNAME}_structure.sql
134 echo -e "\n\n\n\n" >> ${DIRNAME}/${DBNAME}_structure.sql
135 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --no-create-info $DBNAME --tables schema_version
2>/dev
/null
>> ${DIRNAME}/${DBNAME}_structure.sql
136 echo " ${DIRNAME}/${DBNAME}_structure.sql"
139 echo "$LICENSE_HEAD" > ${DIRNAME}/${DBNAME}_data.sql
#copy my own header
140 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --no-create-info $DBNAME >> ${DIRNAME}/${DBNAME}_data.sql
141 echo " ${DIRNAME}/${DBNAME}_data.sql"
144 echo "$LICENSE_HEAD" > ${DIRNAME}/${DBNAME}_all.sql
#copy my own header
145 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --add-drop-table --add-drop-database --routines --databases $DBNAME >> ${DIRNAME}/${DBNAME}_all.sql
146 echo " ${DIRNAME}/${DBNAME}_all.sql"