1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 08:16:54 +00:00

Merge pull request #1892 from Abogical/sync-progress

Add cache.sync progress display
This commit is contained in:
TW 2016-11-29 21:52:07 +01:00 committed by GitHub
commit 99c38e8fc0
2 changed files with 16 additions and 5 deletions

View file

@ -95,7 +95,8 @@ def wrapper(self, args, **kwargs):
kwargs['manifest'], kwargs['key'] = Manifest.load(repository)
if cache:
with Cache(repository, kwargs['key'], kwargs['manifest'],
do_files=getattr(args, 'cache_files', False), lock_wait=self.lock_wait) as cache_:
do_files=getattr(args, 'cache_files', False),
progress=getattr(args, 'progress', False), lock_wait=self.lock_wait) as cache_:
return method(self, args, repository=repository, cache=cache_, **kwargs)
else:
return method(self, args, repository=repository, **kwargs)
@ -341,7 +342,8 @@ def create_inner(archive, cache):
dry_run = args.dry_run
t0 = datetime.utcnow()
if not dry_run:
with Cache(repository, key, manifest, do_files=args.cache_files, lock_wait=self.lock_wait) as cache:
with Cache(repository, key, manifest, do_files=args.cache_files, progress=args.progress,
lock_wait=self.lock_wait) as cache:
archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
create=True, checkpoint_interval=args.checkpoint_interval,
numeric_owner=args.numeric_owner, noatime=args.noatime, noctime=args.noctime,
@ -795,7 +797,7 @@ def _delete_archives(self, args, repository):
if args.stats:
log_multi(DASHES, STATS_HEADER, logger=stats_logger)
with Cache(repository, key, manifest, lock_wait=self.lock_wait) as cache:
with Cache(repository, key, manifest, progress=args.progress, lock_wait=self.lock_wait) as cache:
for i, archive_name in enumerate(archive_names, 1):
logger.info('Deleting {} ({}/{}):'.format(archive_name, i, len(archive_names)))
archive = Archive(repository, key, manifest, archive_name, cache=cache)

View file

@ -18,7 +18,8 @@
from .helpers import decode_dict, int_to_bigint, bigint_to_int, bin_to_hex
from .helpers import format_file_size
from .helpers import yes
from .helpers import ProgressIndicatorMessage
from .helpers import remove_surrogates
from .helpers import ProgressIndicatorPercent, ProgressIndicatorMessage
from .item import Item, ArchiveItem
from .key import PlaintextKey
from .locking import Lock
@ -169,7 +170,7 @@ def destroy(repository, path=None):
shutil.rmtree(path)
def __init__(self, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True,
lock_wait=None):
progress=False, lock_wait=None):
"""
:param do_files: use file metadata cache
:param warn_if_unencrypted: print warning if accessing unknown unencrypted repository
@ -183,6 +184,7 @@ def __init__(self, repository, key, manifest, path=None, sync=True, do_files=Fal
self.repository = repository
self.key = key
self.manifest = manifest
self.progress = progress
self.path = path or os.path.join(get_cache_dir(), repository.id_str)
self.security_manager = SecurityManager(repository)
self.hostname_is_unique = yes(env_var_override='BORG_HOSTNAME_IS_UNIQUE', prompt=False, env_msg=None)
@ -465,8 +467,13 @@ def create_master_idx(chunk_idx):
cleanup_outdated(cached_ids - archive_ids)
if archive_ids:
chunk_idx = None
if self.progress:
pi = ProgressIndicatorPercent(total=len(archive_ids), step=0.1,
msg='%3.0f%% Syncing chunks cache. Processing archive %s')
for archive_id in archive_ids:
archive_name = lookup_name(archive_id)
if self.progress:
pi.show(info=[remove_surrogates(archive_name)])
if archive_id in cached_ids:
archive_chunk_idx_path = mkpath(archive_id)
logger.info("Reading cached archive chunk index for %s ..." % archive_name)
@ -482,6 +489,8 @@ def create_master_idx(chunk_idx):
chunk_idx = archive_chunk_idx
else:
chunk_idx.merge(archive_chunk_idx)
if self.progress:
pi.finish()
logger.info('Done.')
return chunk_idx