From 0213164d461e58e6c86c73737339d292a344496b Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 16 Jan 2016 20:32:24 +0100 Subject: [PATCH 1/2] implement --progress option for borg upgrade, fixes #291 --- borg/archiver.py | 5 ++++- borg/upgrader.py | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 588fe3954..c56023d66 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -520,7 +520,7 @@ def do_upgrade(self, args): # XXX: should auto-detect if it is an attic repository here repo = AtticRepositoryUpgrader(args.location.path, create=False) try: - repo.upgrade(args.dry_run, inplace=args.inplace) + repo.upgrade(args.dry_run, inplace=args.inplace, progress=args.progress) except NotImplementedError as e: print("warning: %s" % e) return self.exit_code @@ -1156,6 +1156,9 @@ def build_parser(self, args=None, prog=None): epilog=upgrade_epilog, formatter_class=argparse.RawDescriptionHelpFormatter) subparser.set_defaults(func=self.do_upgrade) + subparser.add_argument('-p', '--progress', dest='progress', + action='store_true', default=False, + help="""show progress display while upgrading the repository""") subparser.add_argument('-n', '--dry-run', dest='dry_run', default=False, action='store_true', help='do not change repository') diff --git a/borg/upgrader.py b/borg/upgrader.py index 3bd5400f6..bb47429eb 100644 --- a/borg/upgrader.py +++ b/borg/upgrader.py @@ -20,7 +20,7 @@ def __init__(self, *args, **kw): kw['lock'] = False # do not create borg lock files (now) in attic repo super().__init__(*args, **kw) - def upgrade(self, dryrun=True, inplace=False): + def upgrade(self, dryrun=True, inplace=False, progress=False): """convert an attic repository to a borg repository those are the files that need to be upgraded here, from most @@ -54,7 +54,7 @@ def upgrade(self, dryrun=True, inplace=False): try: self.convert_cache(dryrun) self.convert_repo_index(dryrun=dryrun, inplace=inplace) - self.convert_segments(segments, dryrun=dryrun, inplace=inplace) + self.convert_segments(segments, dryrun=dryrun, inplace=inplace, progress=progress) self.borg_readme() finally: self.lock.release() @@ -68,7 +68,7 @@ def borg_readme(self): fd.write('This is a Borg repository\n') @staticmethod - def convert_segments(segments, dryrun=True, inplace=False): + def convert_segments(segments, dryrun=True, inplace=False, progress=False): """convert repository segments from attic to borg replacement pattern is `s/ATTICSEG/BORG_SEG/` in files in @@ -80,12 +80,14 @@ def convert_segments(segments, dryrun=True, inplace=False): segment_count = len(segments) pi = ProgressIndicatorPercent(total=segment_count, msg="Converting segments %3.0f%%", same_line=True) for i, filename in enumerate(segments): - pi.show(i) + if progress: + pi.show(i) if dryrun: time.sleep(0.001) else: AtticRepositoryUpgrader.header_replace(filename, ATTIC_MAGIC, MAGIC, inplace=inplace) - pi.finish() + if progress: + pi.finish() @staticmethod def header_replace(filename, old_magic, new_magic, inplace=True): From 9198f6962cedfa7981d03e09bd654cf61ce00a1d Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 16 Jan 2016 20:46:49 +0100 Subject: [PATCH 2/2] implement --progress option for borg delete --- borg/archive.py | 13 +++++++++---- borg/archiver.py | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/borg/archive.py b/borg/archive.py index aba029f62..0aa92b4dc 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -18,7 +18,7 @@ from . import xattr from .helpers import parse_timestamp, Error, uid2user, user2uid, gid2group, group2gid, format_timedelta, \ Manifest, Statistics, decode_dict, make_path_safe, StableDict, int_to_bigint, bigint_to_int, \ - st_atime_ns, st_ctime_ns, st_mtime_ns + st_atime_ns, st_ctime_ns, st_mtime_ns, ProgressIndicatorPercent from .platform import acl_get, acl_set from .chunker import Chunker from .hashindex import ChunkIndex @@ -418,16 +418,21 @@ def rename(self, name): self.cache.chunk_decref(self.id, self.stats) del self.manifest.archives[self.name] - def delete(self, stats): + def delete(self, stats, progress=False): unpacker = msgpack.Unpacker(use_list=False) - for items_id, data in zip(self.metadata[b'items'], self.repository.get_many(self.metadata[b'items'])): + items_ids = self.metadata[b'items'] + pi = ProgressIndicatorPercent(total=len(items_ids), msg="Decrementing references %3.0f%%", same_line=True) + for (i, (items_id, data)) in enumerate(zip(items_ids, self.repository.get_many(items_ids))): + if progress: + pi.show(i) unpacker.feed(self.key.decrypt(items_id, data)) self.cache.chunk_decref(items_id, stats) for item in unpacker: if b'chunks' in item: for chunk_id, size, csize in item[b'chunks']: self.cache.chunk_decref(chunk_id, stats) - + if progress: + pi.finish() self.cache.chunk_decref(self.id, stats) del self.manifest.archives[self.name] diff --git a/borg/archiver.py b/borg/archiver.py index c56023d66..9cb7e3d1e 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -338,7 +338,7 @@ def do_delete(self, args): if args.location.archive: archive = Archive(repository, key, manifest, args.location.archive, cache=cache) stats = Statistics() - archive.delete(stats) + archive.delete(stats, progress=args.progress) manifest.write() repository.commit(save_space=args.save_space) cache.commit() @@ -982,6 +982,9 @@ def build_parser(self, args=None, prog=None): epilog=delete_epilog, formatter_class=argparse.RawDescriptionHelpFormatter) subparser.set_defaults(func=self.do_delete) + subparser.add_argument('-p', '--progress', dest='progress', + action='store_true', default=False, + help="""show progress display while deleting a single archive""") subparser.add_argument('-s', '--stats', dest='stats', action='store_true', default=False, help='print statistics for the deleted archive')