From: Marc Fiuczynski Date: Thu, 24 Jan 2008 23:14:04 +0000 (+0000) Subject: Ability to checkpoint and the restore a myplc configuration. This will checkpoint... X-Git-Tag: myplc-4.2-2~16 X-Git-Url: http://git.onelab.eu/?p=myplc.git;a=commitdiff_plain;h=0848c69c93c8d59501324d3ebe3c24104d857604 Ability to checkpoint and the restore a myplc configuration. This will checkpoint the db state (both plc and drupal) as well as grab a copy of /etc/planetlab. The resulting checkpoint file is then given tot he restore functionality, which updates the plc&drupal dbs with the data and copies over the checkpointed content of /etc/planetlab. This *should* be enough to bring the state of an stopped plc over to another instance of plc. --- diff --git a/guest.init b/guest.init index 8a49394..938a31e 100755 --- a/guest.init +++ b/guest.init @@ -188,6 +188,30 @@ case "$command" in reload force ;; + checkpoint) + cpfile=$1 + [ -z "$cpfile" ] && cpfile=/var/tmp/plc_checkpoint.$(date +"%Y-%m-%d-%H-%M-%S") + cpdir=$(mktemp -d tmp.XXXXXX) + cd $cpdir + mkdir -p ./etc/planetlab/ + rsync -av /etc/planetlab ./etc/planetlab/ + /etc/plc.d/db checkpoint ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint + tar cjf $cpfile etc + cd - + rm -rf $cpdir + ;; + + restore) + cpfile=$1 + cpdir=$(mktemp -d tmp.XXXXXX) + cd $cpdir + tar xjf $cpfile + rsync -av ./etc/planetlab/ /etc/planetlab + /etc/plc.d/db restore ./etc/planetlab/plc_db.checkpoint ./etc/planetlab/plc_drupal.checkpoint + cd - + rm -rf $cpdir + ;; + steps) echo "${steps[@]}" >&4 ;; diff --git a/plc.d/db b/plc.d/db index 1502b31..8c0a290 100755 --- a/plc.d/db +++ b/plc.d/db @@ -51,19 +51,55 @@ function migrate_db() done } +function checkpoint_planetlab_db() +{ + dumpfile=$1 + pg_dump -U $PLC_DB_USER $PLC_DB_NAME > $dumpfile + check +} + +function restore_planetlab_db() +{ + dumpfile=$1 + if [ -n "$dumpfile" ] ; then + [ -f "$dumpfile" ] && psql -a -U $PLC_DB_USER $PLC_DB_NAME < $dumpfile + check + else + # XXX set error + fi +} + +# use a single date of this script invocation for the dump_*_db functions. +DATE=$(date +"%Y-%m-%d-%H-%M-%S") + # Dumps the database - optional argument to specify filename suffix function dump_planetlab_db() { if [ -n "$1" ] ; then suffix="-$1" ; else suffix="" ; fi - dump=/var/lib/pgsql/backups/$(date +"$PLC_DB_NAME.%Y-%m-%d-%H-%M-%S${suffix}.sql") - pg_dump -U $PLC_DB_USER $PLC_DB_NAME > $dump + dumpfile=/var/lib/pgsql/backups/$(date +"${PLC_DB_NAME}.${DATE}${suffix}.sql") + checkpoint_planetlab_db $dumpfile +} + +function restore_drupal_db() +{ + dumpfile=$1 + if [ -n "$dumpfile" ] ; then + [ -f "$dumpfile" ] && psql -a -U $PLC_DB_USER drupal < $1 + check + fi +} + +function checkpoint_drupal_db() +{ + dumpfile=$1 + pg_dump -U $PLC_DB_USER drupal > $dumpfile check } function dump_drupal_db() { - dump=/var/lib/pgsql/backups/$(date +"drupal.%Y-%m-%d-%H-%M-%S.sql") - pg_dump -U $PLC_DB_USER drupal > $dump + dumpfile=/var/lib/pgsql/backups/$(date +"drupal.${DATE}.sql") + checkpoint_drupal_db $dumpfile check } @@ -123,6 +159,18 @@ EOF result "$MESSAGE" ;; + checkpoint) + MESSAGE=$"Checkpointing the databases" + checkpoint_planetlab_db $2 + checkpoint_drupal_db $3 + ;; + + restore) + MESSAGE=$"Restoring the databases from checkpoint files" + restore_planetlab_db $2 + restore_drupal_db $3 + ;; + clean-dump) MESSAGE=$"Cleaning old database dumps" dialog "$MESSAGE"