-
Notifications
You must be signed in to change notification settings - Fork 3
/
dump_db.py
52 lines (44 loc) · 1.49 KB
/
dump_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Dump DB
import sys
from pprint import pprint
import json
import kazoo.client
import netaddr
db_contents = {'cassandra': {},
'zookeeper': {}}
cassandra_contents = db_contents['cassandra']
for ks_name in ['config_db_uuid',
'useragent',
#'DISCOVERY_SERVER',
'to_bgp_keyspace',
'svc_monitor_keyspace',]:
cassandra_contents[ks_name] = {}
if ks_name == 'DISCOVERY_SERVER':
stringify_col_name = True
else:
stringify_col_name = False
pool = pycassa.ConnectionPool(ks_name, [hostname], pool_timeout=120,
max_retries=-1, timeout=5)
for cf_name in SYSTEM_MANAGER.get_keyspace_column_families(ks_name):
cassandra_contents[ks_name][cf_name] = {}
cf = pycassa.ColumnFamily(pool, cf_name)
for r,c in cf.get_range(column_count=10000000, include_timestamp=True):
if stringify_col_name:
cassandra_contents[ks_name][cf_name][r] = dict((str(k),v) for k,v in c.items())
else:
cassandra_contents[ks_name][cf_name][r] = c
def get_nodes(path):
if not zk.get_children(path):
return [(path, zk.get(path))]
nodes = []
for child in zk.get_children(path):
nodes.extend(get_nodes('%s%s/' %(path, child)))
return nodes
zk = kazoo.client.KazooClient(hostname)
zk.start()
nodes = get_nodes('/')
zk.stop()
db_contents['zookeeper'] = json.dumps(nodes)
print 'contents:'
print json.dumps(db_contents)
exit()