mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 01:37:20 +00:00
calc_stats: deduplicated size now, was deduplicated csize
also: remove pre12_meta cache
This commit is contained in:
parent
19dfbe5c5c
commit
49adb77157
2 changed files with 23 additions and 22 deletions
|
@ -629,18 +629,31 @@ def save(self, name=None, comment=None, timestamp=None, stats=None, additional_m
|
||||||
self.cache.commit()
|
self.cache.commit()
|
||||||
|
|
||||||
def calc_stats(self, cache, want_unique=True):
|
def calc_stats(self, cache, want_unique=True):
|
||||||
# caching wrapper around _calc_stats which is rather slow for archives made with borg < 1.2
|
if not want_unique:
|
||||||
have_borg12_meta = self.metadata.get('nfiles') is not None
|
unique_size = 0
|
||||||
try:
|
else:
|
||||||
stats = Statistics.from_raw_dict(**cache.pre12_meta[self.fpr])
|
def add(id):
|
||||||
except KeyError: # not in pre12_meta cache
|
entry = cache.chunks[id]
|
||||||
stats = self._calc_stats(cache, want_unique=want_unique)
|
archive_index.add(id, 1, entry.size)
|
||||||
if not have_borg12_meta:
|
|
||||||
cache.pre12_meta[self.fpr] = stats.as_raw_dict()
|
archive_index = ChunkIndex()
|
||||||
return stats
|
sync = CacheSynchronizer(archive_index)
|
||||||
|
add(self.id)
|
||||||
|
# we must escape any % char in the archive name, because we use it in a format string, see #6500
|
||||||
|
arch_name_escd = self.name.replace('%', '%%')
|
||||||
|
pi = ProgressIndicatorPercent(total=len(self.metadata.items),
|
||||||
|
msg='Calculating statistics for archive %s ... %%3.0f%%%%' % arch_name_escd,
|
||||||
|
msgid='archive.calc_stats')
|
||||||
|
for id, chunk in zip(self.metadata.items, self.repository.get_many(self.metadata.items)):
|
||||||
|
pi.show(increase=1)
|
||||||
|
add(id)
|
||||||
|
data = self.key.decrypt(id, chunk)
|
||||||
|
sync.feed(data)
|
||||||
|
unique_size = archive_index.stats_against(cache.chunks)[1]
|
||||||
|
pi.finish()
|
||||||
|
|
||||||
def _calc_stats(self, cache, want_unique=True):
|
|
||||||
stats = Statistics(iec=self.iec)
|
stats = Statistics(iec=self.iec)
|
||||||
|
stats.usize = unique_size # the part files use same chunks as the full file
|
||||||
stats.nfiles = self.metadata.nfiles
|
stats.nfiles = self.metadata.nfiles
|
||||||
stats.osize = self.metadata.size
|
stats.osize = self.metadata.size
|
||||||
if self.consider_part_files:
|
if self.consider_part_files:
|
||||||
|
|
|
@ -413,7 +413,6 @@ class CacheStatsMixin:
|
||||||
|
|
||||||
def __init__(self, iec=False):
|
def __init__(self, iec=False):
|
||||||
self.iec = iec
|
self.iec = iec
|
||||||
self.pre12_meta = {} # here we cache archive metadata for borg < 1.2
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.str_format.format(self.format_tuple())
|
return self.str_format.format(self.format_tuple())
|
||||||
|
@ -511,8 +510,6 @@ def create(self):
|
||||||
os.makedirs(os.path.join(self.path, 'chunks.archive.d'))
|
os.makedirs(os.path.join(self.path, 'chunks.archive.d'))
|
||||||
with SaveFile(os.path.join(self.path, files_cache_name()), binary=True):
|
with SaveFile(os.path.join(self.path, files_cache_name()), binary=True):
|
||||||
pass # empty file
|
pass # empty file
|
||||||
with SaveFile(os.path.join(self.path, 'pre12-meta'), binary=False) as fd:
|
|
||||||
json.dump(self.pre12_meta, fd, indent=4)
|
|
||||||
|
|
||||||
def _do_open(self):
|
def _do_open(self):
|
||||||
self.cache_config.load()
|
self.cache_config.load()
|
||||||
|
@ -523,11 +520,6 @@ def _do_open(self):
|
||||||
self.files = None
|
self.files = None
|
||||||
else:
|
else:
|
||||||
self._read_files()
|
self._read_files()
|
||||||
try:
|
|
||||||
with open(os.path.join(self.path, 'pre12-meta')) as fd:
|
|
||||||
self.pre12_meta = json.load(fd)
|
|
||||||
except (FileNotFoundError, json.JSONDecodeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if not os.path.isdir(self.path):
|
if not os.path.isdir(self.path):
|
||||||
|
@ -536,9 +528,6 @@ def open(self):
|
||||||
self.rollback()
|
self.rollback()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
# save the pre12_meta cache in any case
|
|
||||||
with open(os.path.join(self.path, 'pre12-meta'), 'w') as fd:
|
|
||||||
json.dump(self.pre12_meta, fd, indent=4)
|
|
||||||
if self.cache_config is not None:
|
if self.cache_config is not None:
|
||||||
self.cache_config.close()
|
self.cache_config.close()
|
||||||
self.cache_config = None
|
self.cache_config = None
|
||||||
|
@ -1037,7 +1026,6 @@ def __init__(self, repository, key, manifest, warn_if_unencrypted=True, lock_wai
|
||||||
self.security_manager = SecurityManager(repository)
|
self.security_manager = SecurityManager(repository)
|
||||||
self.security_manager.assert_secure(manifest, key, lock_wait=lock_wait)
|
self.security_manager.assert_secure(manifest, key, lock_wait=lock_wait)
|
||||||
|
|
||||||
self.pre12_meta = {}
|
|
||||||
logger.warning('Note: --no-cache-sync is an experimental feature.')
|
logger.warning('Note: --no-cache-sync is an experimental feature.')
|
||||||
|
|
||||||
# Public API
|
# Public API
|
||||||
|
|
Loading…
Reference in a new issue