source: trunk/scripts/xvm-migrate-machine @ 1437

Last change on this file since 1437 was 1437, checked in by price, 16 years ago

more detail on migration: moving db entries

File size: 1.4 KB
RevLine 
[1437]1#!/bin/python
[1429]2# Migrates the machine named $1 from the dev cluster.
3# To be run on the prod cluster.
4
5## The present version is NOT A REAL SCRIPT.
6## Things may not even be tested.  Copy and paste.
[1437]7not_ready_yet_do_not_run_me
[1429]8
9
[1437]10from invirt import database
[1429]11
[1437]12dev_db_uri = 'postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen'
13
14
15def take_data(machine_name):
16## 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()
[1429]22## remove from dev db; ideally atomic with dump
[1437]23  for r in disks + nics + [machine]:
24    database.session.delete(r)
25  database.session.commit()
26  return machine, disks, nics
[1429]27
[1437]28
[1429]29## shut down if up
30#remctl remote control $MACHINE destroy
31
32## copy disk image... copy, copy...
33## for each disk:
34lvname="d_${MACHINE}_${guest_device_name}"
35lvcreate xenvg -n "$lvname" -L "${size}"M
36ssh t-i dd if=/dev/xenvg/"$lvname" of=/dev/stdout bs=1M \
37 | dd if=/dev/stdin of=/dev/xenvg/"$lvname" bs=1M
38
39## add to dev db
[1437]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()
[1429]46
[1437]47
[1429]48## power on if desired
[1437]49
50
Note: See TracBrowser for help on using the repository browser.