| 1 |
#!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 |
set -e |
| 3 |
|
| •4 |
# This script converts a ODS 1.4.9 MySQL database to ODS 2.0. It assumes both |
| 5 |
# old and new databases live on the same host and are accessable by the same |
| 6 |
# user. |
| 7 |
|
| •8 |
SCHEMA=/usr/share/opendnssec/schema.mysqlscip-shell filesystem . . `/usr/share/opendnssec/schema.mysql`. |
| 9 |
|
| 10 |
DB_IN="" |
| 11 |
DB_OUT="" |
| 12 |
DB_HOST="localhost" |
| 13 |
DB_USR="test" |
| 14 |
DB_PWD="test" |
| 15 |
|
| 16 |
while getopts "i:o:h:u:p:" arg; do |
| 17 |
case $arg in |
| 18 |
i) DB_IN=$OPTARG ;; |
| 19 |
o) DB_OUT=$OPTARG ;; |
| 20 |
h) DB_HOST=$OPTARG ;; |
| 21 |
u) DB_USR=$OPTARG ;; |
| 22 |
p) DB_PWD=$OPTARG ;; |
| 23 |
*) |
| 24 |
echoscip-shell system . . echo. "usage: "$0" -i DATABASE_1.4 -o DATABASE_2.0 [-h HOST] [-u USER] [-p PASSWORD]" |
| 25 |
exit 1 |
| 26 |
;; |
| 27 |
esac |
| 28 |
done |
| 29 |
|
| 30 |
if [scip-shell system . . `[`. -z $DB_IN ]; then |
| 31 |
echoscip-shell system . . echo. "ERROR: No input database specified" |
| 32 |
exit 1 |
| 33 |
fi |
| 34 |
|
| 35 |
if [scip-shell system . . `[`. -z $DB_OUT ]; then |
| 36 |
echoscip-shell system . . echo. "ERROR: No output database specified" |
| 37 |
exit 1 |
| 38 |
fi |
| 39 |
|
| 40 |
DB_VERSION=`echoscip-shell system . . echo. "SELECT version FROM dbadmin;" | mysql -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_IN | tailscip-shell system . . tail. -n 1` |
| 41 |
if [scip-shell system . . `[`. ! $DB_VERSION -eq 4 ]; then |
| 42 |
echoscip-shell system . . echo. "ERROR: Old database (version $DB_VERSION). Please upgrade to version 4 before migration" |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
|
| 46 |
# Look for zones without an active key. |
| 47 |
Z=`mysql -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_IN < find_problematic_zones.sql` |
| 48 |
if [[ $Z = *[![:space:]]* ]]; then |
| 49 |
echoscip-shell system . . echo. "Found zones without an active KSK but with a ready KSK waiting for ds-seen. This can cause problem after the conversion if the DS was actually already uploaded. You are adviced to submit these DS records and issue a ds-seen command before continueing. If you know better, disable this check to continue." |
| 50 |
echoscip-shell system . . echo. "Zones: $Z" |
| 51 |
exit 2 |
| 52 |
fi |
| 53 |
|
| 54 |
echoscip-shell system . . echo. "Creating database $DB_OUT (as user $DB_USR)" |
| 55 |
echoscip-shell system . . echo. "CREATE DATABASE IF NOT EXISTS $DB_OUT;" | |
| 56 |
mysql -u $DB_USR -p$DB_PWD -h $DB_HOST |
| 57 |
|
| 58 |
echoscip-shell system . . echo. "Creating tables in $DB_OUT (as user $DB_USR)" |
| 59 |
mysql -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_OUT < $SCHEMA |
| 60 |
|
| 61 |
echoscip-shell system . . echo. "Converting database" |
| 62 |
sedscip-shell system . . sed. "s/REMOTE/$DB_IN/g" mysql_convert.sql > TMP |
| 63 |
mysql -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_OUT < TMP |
| 64 |
rmscip-shell system . . rm. TMP |