Skip to content

Commit 15e2501

Browse files
committed
add copy-all-script to move all contents of one fossildb into another
1 parent 9bdefac commit 15e2501

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

client/copy-all-script

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import grpc
5+
import sys
6+
7+
import fossildbapi_pb2 as proto
8+
import fossildbapi_pb2_grpc as proto_rpc
9+
10+
11+
def main():
12+
verbose = False
13+
14+
collections = ['skeletons', 'volumes', 'volumeData', 'skeletonUpdates']
15+
16+
srcPort = 7156
17+
dstPort = 7155
18+
19+
listKeysBatchSize = 2
20+
21+
22+
23+
24+
srcChannel = grpc.insecure_channel('localhost:{}'.format(srcPort))
25+
srcStub = proto_rpc.FossilDBStub(srcChannel)
26+
27+
dstChannel = grpc.insecure_channel('localhost:{}'.format(dstPort))
28+
dstStub = proto_rpc.FossilDBStub(dstChannel)
29+
30+
testHealth(srcStub, 'source fossildb at {}'.format(srcPort))
31+
testHealth(dstStub, 'destination fossildb at {}'.format(dstPort))
32+
33+
putCount = 0
34+
35+
for collection in collections:
36+
print('copying collection ' + collection)
37+
lastKey = ''
38+
while True:
39+
listKeysReply = srcStub.ListKeys(proto.ListKeysRequest(collection=collection, limit=listKeysBatchSize, startAfterKey=lastKey))
40+
assertSuccess(listKeysReply)
41+
if len(listKeysReply.keys) == 0:
42+
break
43+
if verbose:
44+
print(' copying key batch ', listKeysReply.keys)
45+
for key in listKeysReply.keys:
46+
if verbose:
47+
print(' copying key ', key)
48+
getMultipleVersionsReply = srcStub.GetMultipleVersions(proto.GetMultipleVersionsRequest(collection=collection, key=key))
49+
assertSuccess(getMultipleVersionsReply)
50+
for versionValueTuple in zip(getMultipleVersionsReply.versions, getMultipleVersionsReply.values):
51+
if verbose:
52+
print(' copying version ', versionValueTuple[0])
53+
putReply = dstStub.Put(proto.PutRequest(collection=collection, key=key, version=versionValueTuple[0], value=versionValueTuple[1]))
54+
assertSuccess(putReply)
55+
putCount += 1
56+
if (verbose and putCount % 10 == 0) or putCount % 10000 == 0:
57+
print("total put count:", putCount)
58+
59+
lastKey = listKeysReply.keys[-1]
60+
print("total put count:", putCount)
61+
62+
def testHealth(stub, label):
63+
try:
64+
reply = stub.Health(proto.HealthRequest())
65+
assertSuccess(reply)
66+
print('successfully connected to ' + label)
67+
except Exception as e:
68+
print('failed to connect to ' + label + ': ' + str(e))
69+
sys.exit(1)
70+
71+
def assertSuccess(reply):
72+
if not reply.success:
73+
raise Exception("reply.success failed: " + reply.errorMessage)
74+
75+
if __name__ == '__main__':
76+
main()

0 commit comments

Comments
 (0)