Add a cache around getpwuid/getgrgid to avoid repeated calls.
[cumulus.git] / cumulus-sync
1 #!/usr/bin/python
2 #
3 # Tool for copying cumulus archives from one source to another.
4
5 import os, sys
6
7 # Automatically set Python path, based on script directory.  This should be
8 # removed if the tools are properly installed somewhere.
9 script_directory = os.path.dirname(sys.argv[0])
10 sys.path.append(os.path.join(script_directory, 'python'))
11
12 import cumulus
13 import cumulus.store
14
15 store1 = cumulus.store.open(sys.argv[1])
16 store2 = cumulus.store.open(sys.argv[2])
17
18 source = cumulus.ObjectStore(cumulus.LowlevelDataStore(store1))
19
20 filter = set()
21 for s in sys.argv[3:]:
22     filter.add(s)
23     d = cumulus.parse_full(source.load_snapshot(s))
24     filter.update(d['Segments'].split())
25
26 for ty in ('segments', 'checksums', 'snapshots'):
27     for f in sorted(store1.list(ty)):
28         m = cumulus.store.type_patterns[ty].match(f)
29         if not m: continue
30         if filter and m.group(1) not in filter:
31             continue
32
33         print ty, f
34         try:
35             store2.stat(ty, f)
36         except cumulus.store.NotFoundError:
37             store2.put(ty, f, store1.get(ty, f))
38             print "    [sent]"