Repository: borgbackup/borg

Issue:
Support placeholders in archive comment
It would be useful and more consistent, if the placeholders that can be used in archive names could also be used in archive comments.
Use case being to record information that could be useful to have at some point without making the archive name unnecessary long, e.g. `borg create --comment='Created using borg {borgversion} on {fqdn}' /path/to/repo::{hostname}-{now}`.


Discussion:

Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -50,7 +50,7 @@
     from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR
     from .helpers import Error, NoManifestError, set_ec
     from .helpers import positive_int_validator, location_validator, archivename_validator, ChunkerParams, Location
-    from .helpers import PrefixSpec, SortBySpec, HUMAN_SORT_KEYS, FilesCacheMode
+    from .helpers import PrefixSpec, GlobSpec, CommentSpec, SortBySpec, HUMAN_SORT_KEYS, FilesCacheMode
     from .helpers import BaseFormatter, ItemFormatter, ArchiveFormatter
     from .helpers import format_timedelta, format_file_size, parse_file_size, format_archive
     from .helpers import safe_encode, remove_surrogates, bin_to_hex, prepare_dump_dict
@@ -2336,8 +2336,8 @@ def do_break_lock(self, args, repository):
                 # don't backup the other home directories
                 - /home/*\n\n''')
     helptext['placeholders'] = textwrap.dedent('''
-        Repository (or Archive) URLs, ``--prefix`` and ``--remote-path`` values support these
-        placeholders:
+        Repository (or Archive) URLs, ``--prefix``, ``--glob-archives``, ``--comment``
+        and ``--remote-path`` values support these placeholders:
 
         {hostname}
             The (short) hostname of the machine.
@@ -2727,7 +2727,8 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
             group = filters_group.add_mutually_exclusive_group()
             group.add_argument('-P', '--prefix', metavar='PREFIX', dest='prefix', type=PrefixSpec, default='',
                                help='only consider archive names starting with this prefix.')
-            group.add_argument('-a', '--glob-archives', metavar='GLOB', dest='glob_archives', default=None,
+            group.add_argument('-a', '--glob-archives', metavar='GLOB', dest='glob_archives',
+                               type=GlobSpec, default=None,
                                help='only consider archive names matching the glob. '
                                     'sh: rules apply, see "borg help patterns". '
                                     '``--prefix`` and ``--glob-archives`` are mutually exclusive.')
@@ -3356,7 +3357,7 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
                                    'regular files. Also follows symlinks pointing to these kinds of files.')
 
         archive_group = subparser.add_argument_group('Archive options')
-        archive_group.add_argument('--comment', dest='comment', metavar='COMMENT', default='',
+        archive_group.add_argument('--comment', dest='comment', metavar='COMMENT', type=CommentSpec, default='',
                                    help='add a comment text to the archive')
         archive_group.add_argument('--timestamp', metavar='TIMESTAMP', dest='timestamp',
                                    type=timestamp, default=None,
@@ -3941,7 +3942,7 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
         archive_group.add_argument('-c', '--checkpoint-interval', dest='checkpoint_interval',
                                    type=int, default=1800, metavar='SECONDS',
                                    help='write checkpoint every SECONDS seconds (Default: 1800)')
-        archive_group.add_argument('--comment', dest='comment', metavar='COMMENT', default=None,
+        archive_group.add_argument('--comment', dest='comment', metavar='COMMENT', type=CommentSpec, default=None,
                                    help='add a comment text to the archive')
         archive_group.add_argument('--timestamp', metavar='TIMESTAMP', dest='timestamp',
                                    type=timestamp, default=None,
diff --git a/src/borg/helpers.py b/src/borg/helpers.py
--- a/src/borg/helpers.py
+++ b/src/borg/helpers.py
@@ -685,6 +685,9 @@ def replace_placeholders(text):
 
 PrefixSpec = replace_placeholders
 
+GlobSpec = replace_placeholders
+
+CommentSpec = replace_placeholders
 
 HUMAN_SORT_KEYS = ['timestamp'] + list(ArchiveInfo._fields)
 HUMAN_SORT_KEYS.remove('ts')


Test patch: