4 # Copyright 2015 Telefónica Investigación 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
38 echo -e "Usage: $0 OPTIONS"
39 echo -e " Dumps openmano database content"
41 echo -e " -u USER database user. '$DBUSER' by default. Prompts if DB access fails"
42 echo -e " -p PASS database password. 'No password' by default. Prompts if DB access fails"
43 echo -e " -P PORT database port. '$DBPORT' by default"
44 echo -e " -h HOST database host. '$DBHOST' by default"
45 echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
46 echo -e " --help shows this help"
49 while getopts ":u:p:P:h:-:" o
; do
67 [ "${OPTARG}" == "help" ] && usage
&& exit 0
68 echo "Invalid option: --$OPTARG" >&2 && usage
>&2
72 echo "Invalid option: -$OPTARG" >&2 && usage
>&2
76 echo "Option -$OPTARG requires an argument." >&2 && usage
>&2
87 #check and ask for database user password
90 [ -n "$DBPASS" ] && DBPASS_
="-p$DBPASS"
93 while ! echo ";" | mysql
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev
/null
2>&1
95 [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
96 [ -z "$logintry" ] && echo -e "\nProvide database name and credentials"
97 read -e -p "mysql database name($DBNAME): " KK
98 [ -n "$KK" ] && DBNAME
="$KK"
99 read -e -p "mysql user($DBUSER): " KK
100 [ -n "$KK" ] && DBUSER
="$KK" && DBUSER_
="-u$DBUSER"
101 read -e -s -p "mysql password: " DBPASS
102 [ -n "$DBPASS" ] && DBPASS_
="-p$DBPASS"
103 [ -z "$DBPASS" ] && DBPASS_
=""
109 #echo structure, including the content of schema_version
110 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --no-data --add-drop-table --add-drop-database --routines --databases $DBNAME > ${DIRNAME}/${DBNAME}_structure.sql
111 echo -e "\n\n\n\n" >> ${DIRNAME}/${DBNAME}_structure.sql
112 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --no-create-info $DBNAME --tables schema_version
2>/dev
/null
>> ${DIRNAME}/${DBNAME}_structure.sql
113 echo " ${DIRNAME}/${DBNAME}_structure.sql"
116 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --no-create-info $DBNAME > ${DIRNAME}/${DBNAME}_data.sql
117 echo " ${DIRNAME}/${DBNAME}_data.sql"
120 mysqldump
$DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ --add-drop-table --add-drop-database --routines --databases $DBNAME > ${DIRNAME}/${DBNAME}_all.sql
121 echo " ${DIRNAME}/${DBNAME}_all.sql"