Jelajahi Sumber

info/delete/prune: allow positional NAME argument

so if one works with backup series, one can just do:

borg prune --keep-daily 30 seriesname

seriesname will then do a precise match on the archive names
and select that series.
Thomas Waldmann 8 bulan lalu
induk
melakukan
81a27c1dbe

+ 9 - 3
src/borg/archiver/delete_cmd.py

@@ -3,7 +3,7 @@ import logging
 
 from ._common import with_repository
 from ..constants import *  # NOQA
-from ..helpers import format_archive, CommandError, bin_to_hex
+from ..helpers import format_archive, CommandError, bin_to_hex, archivename_validator
 from ..manifest import Manifest
 
 from ..logger import create_logger
@@ -18,11 +18,14 @@ class DeleteMixIn:
         self.output_list = args.output_list
         dry_run = args.dry_run
         manifest = Manifest.load(repository, (Manifest.Operation.DELETE,))
-        archive_infos = manifest.archives.list_considering(args)
+        if args.name:
+            archive_infos = [manifest.archives.get_one(args.name)]
+        else:
+            archive_infos = manifest.archives.list_considering(args)
         count = len(archive_infos)
         if count == 0:
             return
-        if args.match_archives is None and args.first == 0 and args.last == 0:
+        if not args.name and args.match_archives is None and args.first == 0 and args.last == 0:
             raise CommandError(
                 "Aborting: if you really want to delete all archives, please use -a 'sh:*' "
                 "or just delete the whole repository (might be much faster)."
@@ -85,3 +88,6 @@ class DeleteMixIn:
             "--list", dest="output_list", action="store_true", help="output verbose list of archives"
         )
         define_archive_filters_group(subparser)
+        subparser.add_argument(
+            "name", metavar="NAME", nargs="?", type=archivename_validator, help="specify the archive name"
+        )

+ 8 - 2
src/borg/archiver/info_cmd.py

@@ -5,7 +5,7 @@ from datetime import timedelta
 from ._common import with_repository
 from ..archive import Archive
 from ..constants import *  # NOQA
-from ..helpers import format_timedelta, json_print, basic_json_data
+from ..helpers import format_timedelta, json_print, basic_json_data, archivename_validator
 from ..manifest import Manifest
 
 from ..logger import create_logger
@@ -18,7 +18,10 @@ class InfoMixIn:
     def do_info(self, args, repository, manifest, cache):
         """Show archive details such as disk space used"""
 
-        archive_infos = manifest.archives.list_considering(args)
+        if args.name:
+            archive_infos = [manifest.archives.get_one(args.name)]
+        else:
+            archive_infos = manifest.archives.list_considering(args)
 
         output_data = []
 
@@ -83,3 +86,6 @@ class InfoMixIn:
         subparser.set_defaults(func=self.do_info)
         subparser.add_argument("--json", action="store_true", help="format output as JSON")
         define_archive_filters_group(subparser)
+        subparser.add_argument(
+            "name", metavar="NAME", nargs="?", type=archivename_validator, help="specify the archive name"
+        )

+ 7 - 1
src/borg/archiver/prune_cmd.py

@@ -10,6 +10,7 @@ from ..archive import Archive
 from ..cache import Cache
 from ..constants import *  # NOQA
 from ..helpers import ArchiveFormatter, interval, sig_int, ProgressIndicatorPercent, CommandError, Error
+from ..helpers import archivename_validator
 from ..manifest import Manifest
 
 from ..logger import create_logger
@@ -90,7 +91,9 @@ class PruneMixIn:
             format = os.environ.get("BORG_PRUNE_FORMAT", "{archive:<36} {time} [{id}]")
         formatter = ArchiveFormatter(format, repository, manifest, manifest.key, iec=args.iec)
 
-        archives = manifest.archives.list(match=args.match_archives, sort_by=["ts"], reverse=True)
+        match = args.name if args.name else args.match_archives
+        archives = manifest.archives.list(match=match, sort_by=["ts"], reverse=True)
+
         keep = []
         # collect the rule responsible for the keeping of each archive in this dict
         # keys are archive ids, values are a tuple
@@ -299,3 +302,6 @@ class PruneMixIn:
             help="number of yearly archives to keep",
         )
         define_archive_filters_group(subparser, sort_by=False, first_last=False)
+        subparser.add_argument(
+            "name", metavar="NAME", nargs="?", type=archivename_validator, help="specify the archive name"
+        )