Setting tag plcapi-5.4-2
[plcapi.git] / tools / planetlab3_dump.sh
1 #!/bin/bash
2 #
3 # Dumps the planetlab3 database on zulu, fixing a few things on the way
4 #
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2007 The Trustees of Princeton University
7 #
8 # $Id$
9 #
10
11 tables=(
12 node_bootstates
13 nodes
14 nodenetworks
15 node_nodenetworks
16 nodegroups
17 nodegroup_nodes
18 override_bootscripts
19 pod_hash
20 conf_file
21 conf_assoc
22 address_types
23 addresses
24 organizations
25 sites
26 roles
27 capabilities
28 persons
29 person_roles
30 person_capabilities
31 person_address
32 key_types
33 keys
34 person_keys
35 person_site
36 node_root_access
37 authorized_subnets
38 site_authorized_subnets
39 event_classes
40 dslice03_states
41 dslice03_attributetypes
42 dslice03_slices
43 dslice03_attributes
44 dslice03_sliceattribute
45 dslice03_slicenode
46 dslice03_sliceuser
47 dslice03_siteinfo
48 pcu
49 pcu_ports
50 join_request
51 whatsnew
52 node_hostnames
53 blacklist
54 dslice03_initscripts
55 dslice03_defaultattribute
56 peered_mas
57 sessions
58 )
59
60 # Dump tables
61 for table in "${tables[@]}" ; do
62     pg_dump -U postgres -t $table planetlab3
63 done |
64
65 # Do some manual cleanup
66 sed -f <(cat <<EOF
67 # Swap person_id=1 (kfall@cs.berkeley.edu) with person_id=1303 (maint@planet-lab.org)
68 /^COPY \(persons\|person_roles\|person_capabilities\|person_address\|person_keys\|person_site\|node_root_access\)/,/^\\\./{
69 s/^1\t/1303\t/
70 t
71 s/^1303\t/1\t/
72 t
73 }
74 /^COPY dslice03_sliceuser/,/^\\\./{
75 s/\t1$/\t1303/
76 t
77 s/\t1303$/\t1/
78 t
79 }
80
81 # Swap person_id=2 (nakao@cs.princeton.edu) with person_id=13342 (root@planet-lab.org)
82 /^COPY \(persons\|person_roles\|person_capabilities\|person_address\|person_keys\|person_site\|node_root_access\)/,/^\\\./{
83 s/^2\t/13342\t/
84 t
85 s/^13342\t/2\t/
86 t
87 }
88 /^COPY dslice03_sliceuser/,/^\\\./{
89 s/\t2$/\t13342/
90 t
91 s/\t13342$/\t2/
92 t
93 }
94
95 # Swap site_id=1 (gt) with site_id=90 (pl)
96 /^COPY \(sites\|site_authorized_subnets\|dslice03_siteinfo\)/,/^\\\./{
97 s/^1\t/90\t/
98 t
99 s/^90\t/1\t/
100 t
101 }
102 /^COPY \(person_site\|pcu\)/,/^\\\./{
103 s/\([^\t]*\t\)1\t/\190\t/
104 t
105 s/\([^\t]*\t\)90\t/\11\t/
106 t
107 }
108 /^COPY \(dslice03_slices\)/,/^\\\./{
109 s/\([^\t]*\t[^\t]*\t\)1\t/\190\t/
110 t
111 s/\([^\t]*\t[^\t]*\t\)90\t/\11\t/
112 t
113 }
114 EOF
115 )
116
117 # Dump events and api_log schema only
118 pg_dump -U postgres -s -t events planetlab3
119 pg_dump -U postgres -s -t api_log planetlab3