Ignore:
Timestamp:
Oct 29, 2008, 9:24:59 PM (16 years ago)
Author:
price
Message:

more detail on migration: moving db entries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/xvm-migrate-machine

    r1429 r1437  
    1 ##!/bin/bash
     1#!/bin/python
    22# Migrates the machine named $1 from the dev cluster.
    33# To be run on the prod cluster.
     
    55## The present version is NOT A REAL SCRIPT.
    66## Things may not even be tested.  Copy and paste.
     7not_ready_yet_do_not_run_me
    78
     9
     10from invirt import database
     11
     12dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen'
     13
     14
     15def take_data(machine_name):
    816## dump from dev db; save info well
     17  database.connect(dev_db_uri)
     18  database.session.begin()
     19  machine = database.Machine.query().get_by(name=machine_name)
     20  disks = database.Disk.query().filter_by(machine=machine).all()
     21  nics = database.NIC.query().filter_by(machine=machine).all()
     22## remove from dev db; ideally atomic with dump
     23  for r in disks + nics + [machine]:
     24    database.session.delete(r)
     25  database.session.commit()
     26  return machine, disks, nics
    927
    10 #echo "\\a \\t \\\\ select * from machines where name = '$MACHINE';" \
    11 # | psql -h xvm -U sipb-xen sipb_xen -q
    12 ## 581|fsck|256|price|price|2ab6638f-3f65-2b32-3fd3-c16b74a9b7fe|linux|f|1|price|test|f
    13 ## watch out for funny characters in description; better (non-)quoting needed
    14 ## also disks, nics
    15 
    16 ## remove from dev db; ideally atomic with dump
    1728
    1829## shut down if up
     
    2738
    2839## add to dev db
     40def restore_data(machine, disks, nics):
     41  database.connect() # to prod DB
     42  database.session.begin()
     43  ## now copy machine, disks, nics to new ORM objects (yuck, oh well)
     44  ## and database.session.save(those)
     45  database.session.commit()
     46
    2947
    3048## power on if desired
     49
     50
Note: See TracChangeset for help on using the changeset viewer.