mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 05:35:58 +00:00
More accurate archive stats display
This commit is contained in:
parent
ddd32effba
commit
3d89bf7eac
1 changed files with 21 additions and 6 deletions
|
@ -45,12 +45,18 @@ def stats(self, cache):
|
|||
total_osize = 0
|
||||
total_csize = 0
|
||||
total_usize = 0
|
||||
chunk_count = {}
|
||||
for item in self.items:
|
||||
if item['type'] == 'FILE':
|
||||
total_osize += item['size']
|
||||
for id, sum, csize, osize in self.chunks:
|
||||
for idx in item['chunks']:
|
||||
id = self.chunk_idx[idx]
|
||||
chunk_count.setdefault(id, 0)
|
||||
chunk_count[id] += 1
|
||||
for id, c in chunk_count.items():
|
||||
count, sum, csize, osize = cache.chunkmap[id]
|
||||
total_csize += csize
|
||||
if cache.seen_chunk(id) == 1:
|
||||
if c == count:
|
||||
total_usize += csize
|
||||
return dict(osize=total_osize, csize=total_csize, usize=total_usize)
|
||||
|
||||
|
@ -81,7 +87,6 @@ def verify(self):
|
|||
for item in self.items:
|
||||
if item['type'] == 'FILE':
|
||||
print item['path'], '...',
|
||||
print self.chunk_idx[0].encode('hex')
|
||||
for chunk in item['chunks']:
|
||||
id = self.chunk_idx[chunk]
|
||||
data = self.store.get(NS_CHUNKS, id)
|
||||
|
@ -134,6 +139,16 @@ def process_file(self, path, cache):
|
|||
|
||||
class Archiver(object):
|
||||
|
||||
def pretty_size(self, v):
|
||||
if v > 1024 * 1024 * 1024:
|
||||
return '%.2f GB' % (v / 1024. / 1024. / 1024.)
|
||||
elif v > 1024 * 1024:
|
||||
return '%.2f MB' % (v / 1024. / 1024.)
|
||||
elif v > 1024:
|
||||
return '%.2f kB' % (v / 1024.)
|
||||
else:
|
||||
return str(v)
|
||||
|
||||
def create_archive(self, name, paths):
|
||||
archive = Archive(self.store)
|
||||
archive.create(name, paths, self.cache)
|
||||
|
@ -162,9 +177,9 @@ def extract_archive(self, archive_name):
|
|||
def archive_stats(self, archive_name):
|
||||
archive = Archive(self.store, archive_name)
|
||||
stats = archive.stats(self.cache)
|
||||
print 'Original size:', stats['osize']
|
||||
print 'Compressed size:', stats['csize']
|
||||
print 'Unique data:', stats['usize']
|
||||
print 'Original size:', self.pretty_size(stats['osize'])
|
||||
print 'Compressed size:', self.pretty_size(stats['csize'])
|
||||
print 'Unique data:', self.pretty_size(stats['usize'])
|
||||
|
||||
def run(self):
|
||||
parser = OptionParser()
|
||||
|
|
Loading…
Reference in a new issue