ONE_DB-migrate-1.2to1.4.sh

Bash script for the migration of a 1.2 DB to a 1.4 schema - Marlon Nerling, 12/08/2009 06:20 pm

Download (2 kB)

 
1
#!/bin/bash
2
3
4
DB_pre="/var/lib/one/one.db"
5
DB_post="/var/lib/one/one-1.4.db"
6
7
rm -f $DB_post
8
9
## host_pool
10
echo "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY,host_name TEXT,state INTEGER,im_mad TEXT,vm_mad TEXT,tm_mad TEXT,last_mon_time INTEGER);" | tee | sqlite3 $DB_post 
11
12
sqlite3 $DB_pre 'SELECT * FROM host_pool;' | awk -F'|' '{print "INSERT INTO host_pool VALUES( \"" $1 "\", \"" $2 "\", \"" $3 "\", \"" $4 "\", \"" $5 "\", \"" $6 "\", \"" $7 "\" );"}' | tee |sqlite3 $DB_post 
13
14
## vm_pool
15
echo 'CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY,uid INTEGER,name TEXT,last_poll INTEGER, template_id INTEGER,state INTEGER,lcm_state INTEGER,stime INTEGER,etime INTEGER,deploy_id TEXT,memory INTEGER,cpu INTEGER,net_tx INTEGER,net_rx INTEGER);' | tee | sqlite3 $DB_post 
16
17
18
echo 'select v.*,a.value from vm_pool v , vm_attributes a where a.id=v.oid and a.name='"'NAME';" | sqlite3 $DB_pre | awk -F'|' '{print "INSERT INTO vm_pool VALUES( \"" $1 "\", \"" $2 "\", \"" $14 "\", \"" $3 "\", \"" $4 "\", \"" $5 "\", \"" $6 "\", \"" $7 "\", \"" $8 "\", \"" $9 "\", \"" $10 "\", \"" $11 "\", \"" $12 "\", \"" $13 "\" );"}' | tee |sqlite3 $DB_post
19
20
21
##host_shares
22
echo 'CREATE TABLE host_shares (hid INTEGER PRIMARY KEY,disk_usage INTEGER, mem_usage INTEGER, cpu_usage INTEGER,max_disk  INTEGER,  max_mem   INTEGER, max_cpu   INTEGER,free_disk INTEGER,  free_mem  INTEGER, free_cpu  INTEGER,used_disk INTEGER,  used_mem  INTEGER, used_cpu  INTEGER,running_vms INTEGER);' | sqlite3 $DB_post
23
24
echo 'SELECT * FROM host_shares;' | sqlite3 $DB_pre  | awk -F'|' '{print "INSERT INTO host_shares VALUES( \"" $1 "\", \"" $3 "\", \"" $4 "\", \"" $5 "\", \"" $6 "\", \"" $7 "\", \"" $8 "\", 0, 0, 0, 0 ,0 , 0, \"" $9"\");"  }' | sqlite3 $DB_post 
25
26
##user_pool
27
echo 'CREATE TABLE user_pool (oid INTEGER,user_name TEXT,password TEXT,enabled INTEGER, PRIMARY KEY(oid,user_name), UNIQUE(user_name));' | tee | sqlite3 $DB_post
28
29
##all other
30
31
for table in history host_attributes leases network_pool vm_attributes vn_template 
32
do
33
	echo ".dump $table" | sqlite3 $DB_pre | tee | sqlite3 $DB_post
34
done
35
36