From 10d545ad7753e9ce129593cd8d5a6f4483587b63 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 29 Oct 2008 21:24:59 -0400 Subject: [PATCH] more detail on migration: moving db entries svn path=/trunk/scripts/; revision=1437 --- xvm-migrate-machine | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/xvm-migrate-machine b/xvm-migrate-machine index d8c729e..f14c1b2 100644 --- a/xvm-migrate-machine +++ b/xvm-migrate-machine @@ -1,19 +1,30 @@ -##!/bin/bash +#!/bin/python # Migrates the machine named $1 from the dev cluster. # To be run on the prod cluster. ## The present version is NOT A REAL SCRIPT. ## Things may not even be tested. Copy and paste. +not_ready_yet_do_not_run_me -## dump from dev db; save info well -#echo "\\a \\t \\\\ select * from machines where name = '$MACHINE';" \ -# | psql -h xvm -U sipb-xen sipb_xen -q -## 581|fsck|256|price|price|2ab6638f-3f65-2b32-3fd3-c16b74a9b7fe|linux|f|1|price|test|f -## watch out for funny characters in description; better (non-)quoting needed -## also disks, nics +from invirt import database + +dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen' + +def take_data(machine_name): +## dump from dev db; save info well + database.connect(dev_db_uri) + database.session.begin() + machine = database.Machine.query().get_by(name=machine_name) + disks = database.Disk.query().filter_by(machine=machine).all() + nics = database.NIC.query().filter_by(machine=machine).all() ## remove from dev db; ideally atomic with dump + for r in disks + nics + [machine]: + database.session.delete(r) + database.session.commit() + return machine, disks, nics + ## shut down if up #remctl remote control $MACHINE destroy @@ -26,5 +37,14 @@ ssh t-i dd if=/dev/xenvg/"$lvname" of=/dev/stdout bs=1M \ | dd if=/dev/stdin of=/dev/xenvg/"$lvname" bs=1M ## add to dev db +def restore_data(machine, disks, nics): + database.connect() # to prod DB + database.session.begin() + ## now copy machine, disks, nics to new ORM objects (yuck, oh well) + ## and database.session.save(those) + database.session.commit() + ## power on if desired + + -- 1.7.9.5