mirror of
https://github.com/borgbackup/borg.git
synced 2024-09-11 12:36:12 +03:00
fix "all archives" stats considering part files, fixes #4329
archives with borg 1.2 metadata: quick, we have precomputed size data in archive metadata and just need to sum up for all archives. archives without borg 1.2 metadata: expensive, need to read all archives' items metadata streams and sum up for all items.
This commit is contained in:
parent
4f0ad3124d
commit
61b9283567
@ -157,7 +157,8 @@ def wrapper(self, args, **kwargs):
|
||||
if cache:
|
||||
with Cache(repository, kwargs['key'], kwargs['manifest'],
|
||||
progress=getattr(args, 'progress', False), lock_wait=self.lock_wait,
|
||||
cache_mode=getattr(args, 'files_cache_mode', DEFAULT_FILES_CACHE_MODE)) as cache_:
|
||||
cache_mode=getattr(args, 'files_cache_mode', DEFAULT_FILES_CACHE_MODE),
|
||||
consider_part_files=getattr(args, 'consider_part_files', False)) as cache_:
|
||||
return method(self, args, repository=repository, cache=cache_, **kwargs)
|
||||
else:
|
||||
return method(self, args, repository=repository, **kwargs)
|
||||
|
@ -358,15 +358,17 @@ def destroy(repository, path=None):
|
||||
shutil.rmtree(path)
|
||||
|
||||
def __new__(cls, repository, key, manifest, path=None, sync=True, warn_if_unencrypted=True,
|
||||
progress=False, lock_wait=None, permit_adhoc_cache=False, cache_mode=DEFAULT_FILES_CACHE_MODE):
|
||||
progress=False, lock_wait=None, permit_adhoc_cache=False, cache_mode=DEFAULT_FILES_CACHE_MODE,
|
||||
consider_part_files=False):
|
||||
|
||||
def local():
|
||||
return LocalCache(repository=repository, key=key, manifest=manifest, path=path, sync=sync,
|
||||
warn_if_unencrypted=warn_if_unencrypted, progress=progress,
|
||||
lock_wait=lock_wait, cache_mode=cache_mode)
|
||||
lock_wait=lock_wait, cache_mode=cache_mode, consider_part_files=consider_part_files)
|
||||
|
||||
def adhoc():
|
||||
return AdHocCache(repository=repository, key=key, manifest=manifest, lock_wait=lock_wait)
|
||||
return AdHocCache(repository=repository, key=key, manifest=manifest, lock_wait=lock_wait,
|
||||
consider_part_files=consider_part_files)
|
||||
|
||||
if not permit_adhoc_cache:
|
||||
return local()
|
||||
@ -402,8 +404,24 @@ def __str__(self):
|
||||
'total_chunks'])
|
||||
|
||||
def stats(self):
|
||||
from .archive import Archive
|
||||
# XXX: this should really be moved down to `hashindex.pyx`
|
||||
stats = self.Summary(*self.chunks.summarize())._asdict()
|
||||
total_size, total_csize, unique_size, unique_csize, total_unique_chunks, total_chunks = self.chunks.summarize()
|
||||
# the above values have the problem that they do not consider part files,
|
||||
# thus the total_size and total_csize might be too high (chunks referenced
|
||||
# by the part files AND by the complete file).
|
||||
# since borg 1.2 we have new archive metadata telling the total size and
|
||||
# csize per archive, so we can just sum up all archives to get the "all
|
||||
# archives" stats:
|
||||
total_size, total_csize = 0, 0
|
||||
for archive_name in self.manifest.archives:
|
||||
archive = Archive(self.repository, self.key, self.manifest, archive_name,
|
||||
consider_part_files=self.consider_part_files)
|
||||
stats = archive.calc_stats(self, want_unique=False)
|
||||
total_size += stats.osize
|
||||
total_csize += stats.csize
|
||||
stats = self.Summary(total_size, total_csize, unique_size, unique_csize,
|
||||
total_unique_chunks, total_chunks)._asdict()
|
||||
return stats
|
||||
|
||||
def format_tuple(self):
|
||||
@ -422,7 +440,7 @@ class LocalCache(CacheStatsMixin):
|
||||
"""
|
||||
|
||||
def __init__(self, repository, key, manifest, path=None, sync=True, warn_if_unencrypted=True,
|
||||
progress=False, lock_wait=None, cache_mode=DEFAULT_FILES_CACHE_MODE):
|
||||
progress=False, lock_wait=None, cache_mode=DEFAULT_FILES_CACHE_MODE, consider_part_files=False):
|
||||
"""
|
||||
:param warn_if_unencrypted: print warning if accessing unknown unencrypted repository
|
||||
:param lock_wait: timeout for lock acquisition (int [s] or None [wait forever])
|
||||
@ -434,6 +452,7 @@ def __init__(self, repository, key, manifest, path=None, sync=True, warn_if_unen
|
||||
self.manifest = manifest
|
||||
self.progress = progress
|
||||
self.cache_mode = cache_mode
|
||||
self.consider_part_files = consider_part_files
|
||||
self.timestamp = None
|
||||
self.txn_active = False
|
||||
|
||||
@ -992,10 +1011,11 @@ class AdHocCache(CacheStatsMixin):
|
||||
Unique chunks Total chunks
|
||||
Chunk index: {0.total_unique_chunks:20d} unknown"""
|
||||
|
||||
def __init__(self, repository, key, manifest, warn_if_unencrypted=True, lock_wait=None):
|
||||
def __init__(self, repository, key, manifest, warn_if_unencrypted=True, lock_wait=None, consider_part_files=False):
|
||||
self.repository = repository
|
||||
self.key = key
|
||||
self.manifest = manifest
|
||||
self.consider_part_files = consider_part_files
|
||||
self._txn_active = False
|
||||
|
||||
self.security_manager = SecurityManager(repository)
|
||||
|
Loading…
Reference in New Issue
Block a user