-
Notifications
You must be signed in to change notification settings - Fork 0
/
cumulus-sync
executable file
·68 lines (57 loc) · 2.34 KB
/
cumulus-sync
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
#
# Cumulus: Efficient Filesystem Backup to the Cloud
# Copyright (C) 2008 The Cumulus Developers
# See the AUTHORS file for a list of contributors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Tool for copying cumulus archives from one source to another.
from __future__ import division, print_function, unicode_literals
import os, sys
# Automatically set Python path, based on script directory. This should be
# removed if the tools are properly installed somewhere.
script_directory = os.path.dirname(sys.argv[0])
sys.path.append(os.path.join(script_directory, 'python'))
import cumulus
import cumulus.store
store1 = cumulus.BackendWrapper(sys.argv[1])
store2 = cumulus.BackendWrapper(sys.argv[2])
source = cumulus.CumulusStore(store1)
items_required = set()
snapshots = sys.argv[3:]
if not snapshots:
snapshots = list(source.list_snapshots())
for s in snapshots:
items_required.add(s)
d = cumulus.parse_full(source.load_snapshot(s))
items_required.update(d['Segments'].split())
print("Required:", len(items_required))
files_present = set()
for filetype in cumulus.SEARCH_PATHS:
for (name, path) in store2.list_generic(filetype):
items_required.discard(name)
files_present.add(path)
print("Files already present:", len(sorted(files_present)))
files_required = []
items_found = set()
for filetype in cumulus.SEARCH_PATHS:
for (name, path) in store1.list_generic(filetype):
if name in items_required:
files_required.append(path)
items_found.add(name)
files_required.sort()
for i, f in enumerate(files_required):
print("[%d/%d] %s" % (i + 1, len(files_required), f))
store2.raw_backend.put(f, store1.raw_backend.get(f))