prune --list-kept/--list-pruned, fixes #7511

use this to only list the kept (or pruned) archives.
--list-pruned and --list-kept also work in a additive way.

implied logging: support multiple prune options activating same logger

if any of --list / --list-kept / --list-pruned is used,
it should put the borg.output.list logger to INFO level,
otherwise to WARN level.
This commit is contained in:
Thomas Waldmann 2023-04-07 21:17:06 +02:00
parent 48f3161248
commit 02b28882b3
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
2 changed files with 15 additions and 2 deletions

View File

@ -441,7 +441,6 @@ class Archiver(
"""turn on INFO level logging for args that imply that they will produce output"""
# map of option name to name of logger for that option
option_logger = {
"output_list": "borg.output.list",
"show_version": "borg.output.show-version",
"show_rc": "borg.output.show-rc",
"stats": "borg.output.stats",
@ -451,6 +450,10 @@ class Archiver(
option_set = args.get(option, False)
logging.getLogger(logger_name).setLevel("INFO" if option_set else "WARN")
# special-case --list / --list-kept / --list-pruned as they all work on same logger
options = [args.get(name, False) for name in ("output_list", "list_kept", "list_pruned")]
logging.getLogger("borg.output.list").setLevel("INFO" if any(options) else "WARN")
def _setup_topic_debugging(self, args):
"""Turn on DEBUG level logging for specified --debug-topics."""
for topic in args.debug_topics:

View File

@ -163,7 +163,11 @@ class PruneMixIn:
log_message = "Keeping archive (rule: {rule} #{num}):".format(
rule=kept_because[archive.id][0], num=kept_because[archive.id][1]
)
if args.output_list:
if (
args.output_list
or (args.list_pruned and archive in to_delete)
or (args.list_kept and archive not in to_delete)
):
list_logger.info(f"{log_message:<40} {formatter.format_item(archive)}")
pi.finish()
if sig_int:
@ -265,6 +269,12 @@ class PruneMixIn:
"--list", dest="output_list", action="store_true", help="output verbose list of archives it keeps/prunes"
)
subparser.add_argument("--short", dest="short", action="store_true", help="use a less wide archive part format")
subparser.add_argument(
"--list-pruned", dest="list_pruned", action="store_true", help="output verbose list of archives it prunes"
)
subparser.add_argument(
"--list-kept", dest="list_kept", action="store_true", help="output verbose list of archives it keeps"
)
subparser.add_argument(
"--format",
metavar="FORMAT",