borg prune -v --list enables the keep/prune list output, fixes #658

so one can also have --stats without that.
This commit is contained in:
Thomas Waldmann 2016-02-18 23:44:23 +01:00
parent a44c1f5092
commit 63ce999229
2 changed files with 12 additions and 6 deletions

View File

@ -528,11 +528,14 @@ class Archiver:
stats = Statistics() stats = Statistics()
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, lock_wait=self.lock_wait) as cache:
for archive in keep: for archive in keep:
if args.output_list:
logger.info('Keeping archive: %s' % format_archive(archive)) logger.info('Keeping archive: %s' % format_archive(archive))
for archive in to_delete: for archive in to_delete:
if args.dry_run: if args.dry_run:
if args.output_list:
logger.info('Would prune: %s' % format_archive(archive)) logger.info('Would prune: %s' % format_archive(archive))
else: else:
if args.output_list:
logger.info('Pruning archive: %s' % format_archive(archive)) logger.info('Pruning archive: %s' % format_archive(archive))
Archive(repository, key, manifest, archive.name, cache).delete(stats) Archive(repository, key, manifest, archive.name, cache).delete(stats)
if to_delete and not args.dry_run: if to_delete and not args.dry_run:
@ -1184,6 +1187,9 @@ class Archiver:
subparser.add_argument('-s', '--stats', dest='stats', subparser.add_argument('-s', '--stats', dest='stats',
action='store_true', default=False, action='store_true', default=False,
help='print statistics for the deleted archive') help='print statistics for the deleted archive')
subparser.add_argument('--list', dest='output_list',
action='store_true', default=False,
help='output verbose list of archives it keeps/prunes')
subparser.add_argument('--keep-within', dest='within', type=str, metavar='WITHIN', subparser.add_argument('--keep-within', dest='within', type=str, metavar='WITHIN',
help='keep all archives within this time interval') help='keep all archives within this time interval')
subparser.add_argument('-H', '--keep-hourly', dest='hourly', type=int, default=0, subparser.add_argument('-H', '--keep-hourly', dest='hourly', type=int, default=0,

View File

@ -835,7 +835,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.cmd('init', self.repository_location) self.cmd('init', self.repository_location)
self.cmd('create', self.repository_location + '::test1', src_dir) self.cmd('create', self.repository_location + '::test1', src_dir)
self.cmd('create', self.repository_location + '::test2', src_dir) self.cmd('create', self.repository_location + '::test2', src_dir)
output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2') output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2')
self.assert_in('Keeping archive: test2', output) self.assert_in('Keeping archive: test2', output)
self.assert_in('Would prune: test1', output) self.assert_in('Would prune: test1', output)
output = self.cmd('list', self.repository_location) output = self.cmd('list', self.repository_location)
@ -850,7 +850,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.cmd('init', self.repository_location) self.cmd('init', self.repository_location)
self.cmd('create', self.repository_location + '::test1', src_dir) self.cmd('create', self.repository_location + '::test1', src_dir)
self.cmd('create', self.repository_location + '::test2', src_dir) self.cmd('create', self.repository_location + '::test2', src_dir)
output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2') output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2')
self.assert_in('Keeping archive: test2', output) self.assert_in('Keeping archive: test2', output)
self.assert_in('Would prune: test1', output) self.assert_in('Would prune: test1', output)
output = self.cmd('list', self.repository_location) output = self.cmd('list', self.repository_location)
@ -867,7 +867,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
self.cmd('create', self.repository_location + '::foo-2015-08-12-20:00', src_dir) self.cmd('create', self.repository_location + '::foo-2015-08-12-20:00', src_dir)
self.cmd('create', self.repository_location + '::bar-2015-08-12-10:00', src_dir) self.cmd('create', self.repository_location + '::bar-2015-08-12-10:00', src_dir)
self.cmd('create', self.repository_location + '::bar-2015-08-12-20:00', src_dir) self.cmd('create', self.repository_location + '::bar-2015-08-12-20:00', src_dir)
output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2', '--prefix=foo-') output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2', '--prefix=foo-')
self.assert_in('Keeping archive: foo-2015-08-12-20:00', output) self.assert_in('Keeping archive: foo-2015-08-12-20:00', output)
self.assert_in('Would prune: foo-2015-08-12-10:00', output) self.assert_in('Would prune: foo-2015-08-12-10:00', output)
output = self.cmd('list', self.repository_location) output = self.cmd('list', self.repository_location)