1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-01-31 03:31:41 +00:00

complete cache conversion code

we need to create the borg cache directory

dry run was ignored, fixed.

process cache before segment, because we want to do the faster stuff first
This commit is contained in:
Antoine Beaupré 2015-10-01 16:24:28 -04:00
parent 28a033d1d3
commit 55f79b4999

View file

@ -17,7 +17,11 @@ def convert(self, dryrun=True):
those are the files that need to be converted here, from most those are the files that need to be converted here, from most
important to least important: segments, key files, and various important to least important: segments, key files, and various
caches, the latter being optional, as they will be rebuilt if caches, the latter being optional, as they will be rebuilt if
missing.""" missing.
we nevertheless do the order in reverse, as we prefer to do
the fast stuff first, to improve interactivity.
"""
print("reading segments from attic repository using borg") print("reading segments from attic repository using borg")
# we need to open it to load the configuration and other fields # we need to open it to load the configuration and other fields
self.open(self.path, exclusive=False) self.open(self.path, exclusive=False)
@ -33,8 +37,8 @@ def convert(self, dryrun=True):
self.lock = UpgradableLock(os.path.join(self.path, 'lock'), self.lock = UpgradableLock(os.path.join(self.path, 'lock'),
exclusive=True).acquire() exclusive=True).acquire()
try: try:
self.convert_segments(segments, dryrun)
self.convert_cache(dryrun) self.convert_cache(dryrun)
self.convert_segments(segments, dryrun)
finally: finally:
self.lock.release() self.lock.release()
self.lock = None self.lock = None
@ -146,12 +150,20 @@ def convert_cache(self, dryrun):
for cache in [ 'files', 'chunks' ]: for cache in [ 'files', 'chunks' ]:
attic_cache = os.path.join(attic_cache_dir, hexlify(self.id).decode('ascii'), cache) attic_cache = os.path.join(attic_cache_dir, hexlify(self.id).decode('ascii'), cache)
if os.path.exists(attic_cache): if os.path.exists(attic_cache):
borg_cache = os.path.join(get_cache_dir(), hexlify(self.id).decode('ascii'), cache) borg_cache_dir = os.path.join(get_cache_dir(), hexlify(self.id).decode('ascii'))
if not os.path.exists(borg_cache_dir):
os.makedirs(borg_cache_dir)
borg_cache = os.path.join(borg_cache_dir, cache)
print("copying attic cache from %s to %s" % (attic_cache, borg_cache))
if not dryrun:
shutil.copy(attic_cache, borg_cache) shutil.copy(attic_cache, borg_cache)
caches += [borg_cache] caches += [borg_cache]
else:
print("no %s cache found in %s" % (cache, attic_cache))
for cache in caches: for cache in caches:
print("converting cache %s" % cache) print("converting cache %s" % cache)
if not dryrun:
AtticRepositoryConverter.header_replace(cache, b'ATTICIDX', b'BORG_IDX') AtticRepositoryConverter.header_replace(cache, b'ATTICIDX', b'BORG_IDX')