mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-01 12:45:34 +00:00
prune --short/--format: enable users to format the list output, fixes #3238
This commit is contained in:
parent
09781e1d30
commit
a0e1110c16
1 changed files with 22 additions and 2 deletions
|
@ -9,7 +9,7 @@
|
|||
from ..archive import Archive, Statistics
|
||||
from ..cache import Cache
|
||||
from ..constants import * # NOQA
|
||||
from ..helpers import format_archive, interval, sig_int, log_multi, ProgressIndicatorPercent
|
||||
from ..helpers import ArchiveFormatter, interval, sig_int, log_multi, ProgressIndicatorPercent
|
||||
from ..manifest import Manifest
|
||||
|
||||
from ..logger import create_logger
|
||||
|
@ -82,6 +82,14 @@ def do_prune(self, args, repository, manifest):
|
|||
'"keep-weekly", "keep-monthly" or "keep-yearly" settings must be specified.'
|
||||
)
|
||||
return self.exit_code
|
||||
if args.format is not None:
|
||||
format = args.format
|
||||
elif args.short:
|
||||
format = "{archive}"
|
||||
else:
|
||||
format = "{archive:<36} {time} [{id}]"
|
||||
formatter = ArchiveFormatter(format, repository, manifest, manifest.key, json=False, iec=args.iec)
|
||||
|
||||
checkpoint_re = r"\.checkpoint(\.\d+)?"
|
||||
archives_checkpoints = manifest.archives.list(
|
||||
match=args.match_archives,
|
||||
|
@ -156,7 +164,7 @@ def checkpoint_func():
|
|||
rule=kept_because[archive.id][0], num=kept_because[archive.id][1]
|
||||
)
|
||||
if args.output_list:
|
||||
list_logger.info(f"{log_message:<40} {format_archive(archive)}")
|
||||
list_logger.info(f"{log_message:<40} {formatter.format_item(archive)}")
|
||||
pi.finish()
|
||||
if sig_int:
|
||||
# Ctrl-C / SIGINT: do not checkpoint (commit) again, we already have a checkpoint in this case.
|
||||
|
@ -227,6 +235,10 @@ def build_parser_prune(self, subparsers, common_parser, mid_common_parser):
|
|||
deleted - the "Deleted data" deduplicated size there is most interesting as
|
||||
that is how much your repository will shrink.
|
||||
Please note that the "All archives" stats refer to the state after pruning.
|
||||
|
||||
You can influence how the ``--list`` output is formatted by using the ``--short``
|
||||
option (less wide output) or by giving a custom format using ``--format`` (see
|
||||
the ``borg rlist`` description for more details about the format string).
|
||||
"""
|
||||
)
|
||||
subparser = subparsers.add_parser(
|
||||
|
@ -252,6 +264,14 @@ def build_parser_prune(self, subparsers, common_parser, mid_common_parser):
|
|||
subparser.add_argument(
|
||||
"--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(
|
||||
"--format",
|
||||
metavar="FORMAT",
|
||||
dest="format",
|
||||
action=Highlander,
|
||||
help="specify format for the archive part " '(default: "{archive:<36} {time} [{id}]")',
|
||||
)
|
||||
subparser.add_argument(
|
||||
"--keep-within",
|
||||
metavar="INTERVAL",
|
||||
|
|
Loading…
Reference in a new issue