mirror of https://github.com/borgbackup/borg.git
Merge pull request #43 from jdchristensen/prune-dry-run
Add --dry-run option to prune.
This commit is contained in:
commit
ea70050cf4
|
@ -331,8 +331,11 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
for archive in keep:
|
for archive in keep:
|
||||||
self.print_verbose('Keeping archive "%s"' % archive.name)
|
self.print_verbose('Keeping archive "%s"' % archive.name)
|
||||||
for archive in to_delete:
|
for archive in to_delete:
|
||||||
self.print_verbose('Pruning archive "%s"', archive.name)
|
if args.dry_run:
|
||||||
archive.delete(cache)
|
self.print_verbose('Would prune "%s"' % archive.name)
|
||||||
|
else:
|
||||||
|
self.print_verbose('Pruning archive "%s"' % archive.name)
|
||||||
|
archive.delete(cache)
|
||||||
return self.exit_code
|
return self.exit_code
|
||||||
|
|
||||||
helptext = {}
|
helptext = {}
|
||||||
|
@ -561,6 +564,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
description=self.do_prune.__doc__,
|
description=self.do_prune.__doc__,
|
||||||
epilog=prune_epilog)
|
epilog=prune_epilog)
|
||||||
subparser.set_defaults(func=self.do_prune)
|
subparser.set_defaults(func=self.do_prune)
|
||||||
|
subparser.add_argument('-n', '--dry-run', dest='dry_run',
|
||||||
|
default=False, action='store_true',
|
||||||
|
help='do not change repository')
|
||||||
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,
|
||||||
|
|
|
@ -253,10 +253,16 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
||||||
self.attic('init', self.repository_location)
|
self.attic('init', self.repository_location)
|
||||||
self.attic('create', self.repository_location + '::test1', src_dir)
|
self.attic('create', self.repository_location + '::test1', src_dir)
|
||||||
self.attic('create', self.repository_location + '::test2', src_dir)
|
self.attic('create', self.repository_location + '::test2', src_dir)
|
||||||
self.attic('prune', self.repository_location, '--daily=2')
|
output = self.attic('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
|
||||||
|
self.assert_in('Keeping archive "test2"', output)
|
||||||
|
self.assert_in('Would prune "test1"', output)
|
||||||
output = self.attic('list', self.repository_location)
|
output = self.attic('list', self.repository_location)
|
||||||
assert 'test1' not in output
|
self.assert_in('test1', output)
|
||||||
assert 'test2' in output
|
self.assert_in('test2', output)
|
||||||
|
self.attic('prune', self.repository_location, '--keep-daily=2')
|
||||||
|
output = self.attic('list', self.repository_location)
|
||||||
|
self.assert_not_in('test1', output)
|
||||||
|
self.assert_in('test2', output)
|
||||||
|
|
||||||
def test_usage(self):
|
def test_usage(self):
|
||||||
self.assert_raises(SystemExit, lambda: self.attic())
|
self.assert_raises(SystemExit, lambda: self.attic())
|
||||||
|
|
Loading…
Reference in New Issue