From: Thierry Parmentelat Date: Sun, 2 Nov 2008 02:55:48 +0000 (+0000) Subject: support for moving across different releases of postgresql X-Git-Tag: PLCAPI-4.3-2~18 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=64067a7706de8395457bcba908c91c4f57c4a5e4;hp=31a47cb82e66d1623dcac7e8ae3bb58ac1447c37;p=plcapi.git support for moving across different releases of postgresql (typical use will be from f8/pgsql-8.2 down to centos5/pgsql-8.1) to this end, pull planetlab4 database through a pgsql client --- diff --git a/migrations/v4-to-v5/migrate.sh b/migrations/v4-to-v5/migrate.sh index cfe76f2..6c1389d 100755 --- a/migrations/v4-to-v5/migrate.sh +++ b/migrations/v4-to-v5/migrate.sh @@ -16,7 +16,7 @@ SCHEMA_SQL=$UPUP/planetlab5.sql DATE=$(date +%Y-%m-%d-%H-%M) DATE_=$(date +%Y_%m_%d_%H_%M) LOG=${DIRNAME}/${DATE}.log -DUMP=${DIRNAME}/${DATE}-pl4.sql +DUMP=${DIRNAME}/pl4.sql RESTORE=${DIRNAME}/${DATE}-pl5.sql FAKE=${DIRNAME}/input-pl4.sql VIEWS_SQL=$DIRNAME/${DATE}-views5.sql @@ -29,6 +29,22 @@ PGM_NODEGROUPS=$DIRNAME/parse-site-nodegroups.py # load config . /etc/planetlab/plc_config +function run () { + message=$1; shift + + if [ -n "$DEBUG" ] ; then + echo -n "Type enter to run next step XXX $message XXX ... " + read _answer_ + fi + + echo -n "$message " + echo "==================================================" >> $LOG + echo $message >> $LOG + echo "$@" >> $LOG + "$@" >> $LOG 2>&1 + echo Done +} + # return 0 (yes) or 1 (no) whether the database exists function check_for_database () { dbname=$1; shift @@ -39,13 +55,15 @@ function check_for_database () { # when 'service plc start' gets run, the planetlab5 DB gets created # so this script will drop the planetlab5 DB and re-create it from scratch # with the contents of the planetlab4 DB that is epxected to exist -function warning () { +function confirm_nodegroups () { echo "========================================" echo "$COMMAND" echo "This script is designed to ease the migration from myplc 4.2 to 5.0" echo "It attempts to (re)create the planetlab5 database from planetlab4" echo "" - echo "You might wish to edit/review $NODEGROUPS_DEF to finetune your migration" + echo "You might wish to edit/review" + echo " $NODEGROUPS_DEF" + echo " to finetune your migration" echo "" echo "Please refer to http://svn.planet-lab.org/wiki/Migration4to5" echo "========================================" @@ -57,40 +75,39 @@ function warning () { esac } -function check () { +function check_env () { [ -f $MIGRATION_SED ] || { echo $MIGRATION_SED not found - exiting ; exit 1; } [ -f $MIGRATION_SQL ] || { echo $MIGRATION_SQL not found - exiting ; exit 1; } [ -f $SCHEMA_SQL ] || { echo $SCHEMA_SQL not found - exiting ; exit 1; } [ -f $NODEGROUPS_DEF ] || { echo $NODEGROUPS_DEF not found - exiting ; exit 1; } } -function run () { - message=$1; shift +# connect to the former myplc, performs a local dump of planetlab4 and creates is locally +function get_planetlab4 () { - if [ -n "$DEBUG" ] ; then - echo -n "Type enter to run next step XXX $message XXX ... " - read _answer_ - fi + # for faster tests .. + if [ -f $FAKE ] ; then + echo '' + echo 'xxxx WARNING WARNING WARNING WARNING WARNING xxx' + echo '' + echo Using fake input for tests $FAKE + echo '' + echo 'xxxx WARNING WARNING WARNING WARNING WARNING xxx' + echo '' + DUMP=$FAKE + elif [ -f $DUMP ] ; then + echo "Using planetlab4 from $DUMP" + else - echo -n "$message " - echo "==================================================" >> $LOG - echo $message >> $LOG - echo "$@" >> $LOG - "$@" >> $LOG 2>&1 - echo Done + echo -n "Enter the hostname for the former DB service : " + read hostname + echo "Running pg_dump on $hostname.." + pg_dump --ignore-version --host=$hostname --user=$PLC_DB_USER planetlab4 -f ${DUMP} + DUMP=$DUMP + fi } -function migrate () { - set -e - cd $DIRNAME - - # check that planetlab4 exists - if check_for_database planetlab4 ; then - echo "OK : FOUND db planetlab4" - else - echo "ERROR : planetlab4 NOT FOUND - bye" - exit 1 - fi +function prepare_planetlab5 () { # check if planetlab5 exists if check_for_database planetlab5 ; then @@ -117,25 +134,17 @@ function migrate () { if check_for_database planetlab5 ; then echo "ERROR : FOUND planetlab5 - should not happen - exiting" exit 1 - else - echo "OK, we're clear, let's go" fi +} + + + +function migrate () { + set -e + cd $DIRNAME # dump planetlab4 - if [ ! -f $FAKE ] ; then - run "Dumping planetlab4 in $DUMP" pg_dump --user=$PLC_DB_USER -f $DUMP planetlab4 - else - echo '' - echo 'xxxx WARNING WARNING WARNING WARNING WARNING xxx' - echo '' - echo Using fake input for tests $FAKE - echo '' - echo 'xxxx WARNING WARNING WARNING WARNING WARNING xxx' - echo '' - DUMP=$FAKE - fi - run "Copying into $RESTORE" cp $DUMP $RESTORE run "Renaming identifiers in $RESTORE" sed -f $MIGRATION_SED -i $RESTORE @@ -174,11 +183,17 @@ function links () { function main () { - check - warning + check_env + confirm_nodegroups + echo "OK, we're clear, let's go" set -e + get_planetlab4 + prepare_planetlab5 migrate links + echo "See logfile $LOG for detailed log" + echo "Checking for 'error' in the logfile" + grep -i error $LOG } diff --git a/migrations/v4-to-v5/migrate.sql b/migrations/v4-to-v5/migrate.sql index c02390f..37a36fe 100644 --- a/migrations/v4-to-v5/migrate.sql +++ b/migrations/v4-to-v5/migrate.sql @@ -227,8 +227,11 @@ drop table nodegroup_node; ---------------------------------------- -- boot states ---------------------------------------- -INSERT INTO boot_states (boot_state) - VALUES ('safeboot'), ('failboot'), ('disabled'), ('install'), ('reinstall'); +INSERT INTO boot_states (boot_state) VALUES ('safeboot'); +INSERT INTO boot_states (boot_state) VALUES ('failboot'); +INSERT INTO boot_states (boot_state) VALUES ('disabled'); +INSERT INTO boot_states (boot_state) VALUES ('install'); +INSERT INTO boot_states (boot_state) VALUES ('reinstall'); -- xxx need checking --