mirror of https://github.com/borgbackup/borg.git
Added "--hourly" option to "purge" subcommand
This commit is contained in:
parent
80cbdcd8f1
commit
3a00547f28
|
@ -235,15 +235,17 @@ class Archiver(object):
|
||||||
cache = Cache(store, key)
|
cache = Cache(store, key)
|
||||||
archives = list(sorted(Archive.list_archives(store, key, cache),
|
archives = list(sorted(Archive.list_archives(store, key, cache),
|
||||||
key=attrgetter('ts'), reverse=True))
|
key=attrgetter('ts'), reverse=True))
|
||||||
if args.daily + args.weekly + args.monthly + args.yearly == 0:
|
if args.hourly + args.daily + args.weekly + args.monthly + args.yearly == 0:
|
||||||
self.print_error('At least one of the "daily", "weekly", "monthly" or "yearly" '
|
self.print_error('At least one of the "hourly", "daily", "weekly", "monthly" or "yearly" '
|
||||||
'settings must be specified')
|
'settings must be specified')
|
||||||
return 1
|
return 1
|
||||||
if args.prefix:
|
if args.prefix:
|
||||||
archives = [archive for archive in archives if archive.name.startswith(args.prefix)]
|
archives = [archive for archive in archives if archive.name.startswith(args.prefix)]
|
||||||
keep = []
|
keep = []
|
||||||
|
if args.hourly:
|
||||||
|
keep += purge_split(archives, '%Y-%m-%d %H', args.hourly)
|
||||||
if args.daily:
|
if args.daily:
|
||||||
keep += purge_split(archives, '%Y-%m-%d', args.daily)
|
keep += purge_split(archives, '%Y-%m-%d', args.daily, keep)
|
||||||
if args.weekly:
|
if args.weekly:
|
||||||
keep += purge_split(archives, '%Y-%V', args.weekly, keep)
|
keep += purge_split(archives, '%Y-%V', args.weekly, keep)
|
||||||
if args.monthly:
|
if args.monthly:
|
||||||
|
@ -352,6 +354,8 @@ class Archiver(object):
|
||||||
|
|
||||||
subparser = subparsers.add_parser('purge')
|
subparser = subparsers.add_parser('purge')
|
||||||
subparser.set_defaults(func=self.do_purge)
|
subparser.set_defaults(func=self.do_purge)
|
||||||
|
subparser.add_argument('-H', '--hourly', dest='hourly', type=int, default=0,
|
||||||
|
help='Number of hourly archives to keep')
|
||||||
subparser.add_argument('-d', '--daily', dest='daily', type=int, default=0,
|
subparser.add_argument('-d', '--daily', dest='daily', type=int, default=0,
|
||||||
help='Number of daily archives to keep')
|
help='Number of daily archives to keep')
|
||||||
subparser.add_argument('-w', '--weekly', dest='weekly', type=int, default=0,
|
subparser.add_argument('-w', '--weekly', dest='weekly', type=int, default=0,
|
||||||
|
|
13
darc/test.py
13
darc/test.py
|
@ -121,6 +121,19 @@ class Test(unittest.TestCase):
|
||||||
fd.close()
|
fd.close()
|
||||||
self.darc('verify', self.store_path + '::test', exit_code=1)
|
self.darc('verify', self.store_path + '::test', exit_code=1)
|
||||||
|
|
||||||
|
def test_purge_store(self):
|
||||||
|
src_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
|
||||||
|
self.darc('init', '-p', '', self.store_path)
|
||||||
|
self.darc('create', self.store_path + '::test1', src_dir)
|
||||||
|
self.darc('create', self.store_path + '::test2', src_dir)
|
||||||
|
self.darc('purge', self.store_path, '--daily=2')
|
||||||
|
output = self.darc('list', self.store_path)
|
||||||
|
assert 'test1' in output
|
||||||
|
assert 'test2' in output
|
||||||
|
self.darc('purge', self.store_path, '--daily=2', '--really')
|
||||||
|
output = self.darc('list', self.store_path)
|
||||||
|
assert 'test1' not in output
|
||||||
|
assert 'test2' in output
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
Loading…
Reference in New Issue