From 4c4018e1d702bbecbe23f34a82cfa52988dab699 Mon Sep 17 00:00:00 2001 From: Dan Christensen Date: Mon, 24 Feb 2014 19:32:18 -0500 Subject: [PATCH 1/2] Update prune documentation to use new command line options, and also to say that the time that matters is the time each backup completes. --- attic/archiver.py | 7 ++++--- docs/usage.rst | 18 +++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/attic/archiver.py b/attic/archiver.py index f3d3463bb..425f90a83 100644 --- a/attic/archiver.py +++ b/attic/archiver.py @@ -548,11 +548,12 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") backups. As an example, "-d 7" means to keep the latest backup on each day for 7 days. Days without backups do not count towards the total. The rules are applied from hourly to yearly, and backups selected by previous rules do - not count towards those of later rules. Dates and times are interpreted in + not count towards those of later rules. The time that each backup completes + is used for pruning purposes. Dates and times are interpreted in the local timezone, and weeks go from Monday to Sunday. Specifying a negative number of archives to keep means that there is no limit. - The "--within" option takes an argument of the form "", - where char is "H", "d", "w", "m", "y". For example, "--within 2d" means + The "--keep-within" option takes an argument of the form "", + where char is "H", "d", "w", "m", "y". For example, "--keep-within 2d" means to keep all archives that were created within the past 48 hours. "1m" is taken to mean "31d". The archives kept with this option do not count towards the totals specified by any other options. If a diff --git a/docs/usage.rst b/docs/usage.rst index 1491e831e..f67813403 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -131,15 +131,19 @@ Examples ~~~~~~~~ :: - # Keep 7 end of day and 4 additional end of week archives - $ attic prune /data/myrepo --daily=7 --weekly=4 + # Keep 7 end of day and 4 additional end of week archives: + $ attic prune /data/myrepo --keep-daily=7 --keep-weekly=4 - # Same as above but only apply to archive names starting with "foo" - $ attic prune /data/myrepo --daily=7 --weekly=4 --prefix=foo + # Same as above but only apply to archive names starting with "foo": + $ attic prune /data/myrepo --keep-daily=7 --keep-weekly=4 --prefix=foo - # Keep 7 end of day, 4 additional end of week archives, and an - # end of month archive for every month: - $ attic prune /data/myrepo --daily=7 --weekly=4 --monthly=-1 + # Keep 7 end of day, 4 additional end of week archives, + # and an end of month archive for every month: + $ attic prune /data/myrepo --keep-daily=7 --keep-weekly=4 --monthly=-1 + + # Keep all backups in the last 10 days, 4 additional end of week archives, + # and an end of month archive for every month: + $ attic prune /data/myrepo --keep-within=10d --keep-weekly=4 --monthly=-1 .. include:: usage/info.rst.inc From 78c2ef6a13e53bc48f7f7df3151250f0878d9dcf Mon Sep 17 00:00:00 2001 From: Dan Christensen Date: Mon, 24 Feb 2014 19:46:56 -0500 Subject: [PATCH 2/2] When -v is specified with prune, also show the timestamp of each archive, which is helpful for debugging. Unify this with the formatting done by "attic list". The spacing is chosen so that the attic prune output is 79 characters wide when the archive names are at most 36 characters. --- attic/archiver.py | 10 +++++----- attic/helpers.py | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/attic/archiver.py b/attic/archiver.py index 425f90a83..6020571e7 100644 --- a/attic/archiver.py +++ b/attic/archiver.py @@ -14,7 +14,7 @@ from attic.key import key_creator from attic.helpers import Error, location_validator, format_time, \ format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, \ get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \ - Manifest, remove_surrogates, update_excludes + Manifest, remove_surrogates, update_excludes, format_archive from attic.remote import RepositoryServer, RemoteRepository @@ -277,7 +277,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") remove_surrogates(item[b'path']), extra)) else: for archive in sorted(Archive.list_archives(repository, key, manifest), key=attrgetter('ts')): - print('%-20s %s' % (archive.metadata[b'name'], to_localtime(archive.ts).strftime('%c'))) + print(format_archive(archive)) return self.exit_code def do_info(self, args): @@ -329,12 +329,12 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") to_delete = [a for a in archives if a not in keep] for archive in keep: - self.print_verbose('Keeping archive "%s"' % archive.name) + self.print_verbose('Keeping archive: %s' % format_archive(archive)) for archive in to_delete: if args.dry_run: - self.print_verbose('Would prune "%s"' % archive.name) + self.print_verbose('Would prune: %s' % format_archive(archive)) else: - self.print_verbose('Pruning archive "%s"' % archive.name) + self.print_verbose('Pruning archive: %s' % format_archive(archive)) archive.delete(cache) return self.exit_code diff --git a/attic/helpers.py b/attic/helpers.py index 9ef2f7c62..80ab77a3b 100644 --- a/attic/helpers.py +++ b/attic/helpers.py @@ -288,6 +288,10 @@ def format_file_size(v): return '%d B' % v +def format_archive(archive): + return '%-36s %s' % (archive.name, to_localtime(archive.ts).strftime('%c')) + + class IntegrityError(Error): """Data integrity error"""