mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-01 01:06:59 +00:00
borg upgrade - move some code to convert_repo_index
it was a bit confusing to have repo-related code in a method called "convert_cache". also fixed a typo "index index".
This commit is contained in:
parent
7acda553ff
commit
cd804e72b7
1 changed files with 18 additions and 11 deletions
|
@ -52,6 +52,7 @@ def upgrade(self, dryrun=True, inplace=False):
|
|||
self.lock = UpgradableLock(os.path.join(self.path, 'lock'),
|
||||
exclusive=True).acquire()
|
||||
try:
|
||||
self.convert_repo_index(dryrun)
|
||||
self.convert_cache(dryrun)
|
||||
self.convert_segments(segments, dryrun=dryrun, inplace=inplace)
|
||||
self.borg_readme()
|
||||
|
@ -150,8 +151,8 @@ def convert_keyfiles(keyfile, dryrun):
|
|||
with open(keyfile, 'w') as f:
|
||||
f.write(data)
|
||||
|
||||
def convert_cache(self, dryrun):
|
||||
"""convert caches from attic to borg
|
||||
def convert_repo_index(self, dryrun):
|
||||
"""convert some repo files
|
||||
|
||||
those are all hash indexes, so we need to
|
||||
`s/ATTICIDX/BORG_IDX/` in a few locations:
|
||||
|
@ -161,6 +162,21 @@ def convert_cache(self, dryrun):
|
|||
should probably update, with a lock, see
|
||||
`Repository.open()`, which i'm not sure we should use
|
||||
because it may write data on `Repository.close()`...
|
||||
"""
|
||||
transaction_id = self.get_index_transaction_id()
|
||||
if transaction_id is None:
|
||||
logger.warning('no index file found for repository %s' % self.path)
|
||||
else:
|
||||
index = os.path.join(self.path, 'index.%d' % transaction_id).encode('utf-8')
|
||||
logger.info("converting repo index %s" % index)
|
||||
if not dryrun:
|
||||
AtticRepositoryUpgrader.header_replace(index, b'ATTICIDX', b'BORG_IDX')
|
||||
|
||||
def convert_cache(self, dryrun):
|
||||
"""convert caches from attic to borg
|
||||
|
||||
those are all hash indexes, so we need to
|
||||
`s/ATTICIDX/BORG_IDX/` in a few locations:
|
||||
|
||||
* the `files` and `chunks` cache (in `$ATTIC_CACHE_DIR` or
|
||||
`$HOME/.cache/attic/<repoid>/`), which we could just drop,
|
||||
|
@ -168,15 +184,6 @@ def convert_cache(self, dryrun):
|
|||
`Cache.open()`, edit in place and then `Cache.close()` to
|
||||
make sure we have locking right
|
||||
"""
|
||||
transaction_id = self.get_index_transaction_id()
|
||||
if transaction_id is None:
|
||||
logger.warning('no index file found for repository %s' % self.path)
|
||||
else:
|
||||
index = os.path.join(self.path, 'index.%d' % transaction_id).encode('utf-8')
|
||||
logger.info("converting index index %s" % index)
|
||||
if not dryrun:
|
||||
AtticRepositoryUpgrader.header_replace(index, b'ATTICIDX', b'BORG_IDX')
|
||||
|
||||
# copy of attic's get_cache_dir()
|
||||
attic_cache_dir = os.environ.get('ATTIC_CACHE_DIR',
|
||||
os.path.join(os.path.expanduser('~'),
|
||||
|
|
Loading…
Reference in a new issue