diff --git a/NEWS b/NEWS index c1bc591d..e868bd5e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,9 @@ 2.1.7.dev0 * #1309: Add support for the "--quick-stats" flag and the "quick_statistics" option to the "prune" action. Borg >= 1.4.5 and < 2 only. + * #1317: Add an "--archive-hostname" flag and corresponding "archive_hostname" option for + overriding the hostname used when creating an archive, e.g. via the "{hostname}" placeholder in + the "archive_name_format" option. * #1319: Fix the ZFS hook's overzealous unmounting of snapshot paths when a source dataset is at "/". * #1322: Fix for the "restore" action sometimes failing to find a database dump that was dumped diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 1ed7b4dd..88f62d3a 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -199,6 +199,7 @@ def make_base_create_command( # noqa: PLR0912 list_filter_flags = flags.make_list_filter_flags(local_borg_version, dry_run) files_changed = config.get('files_changed') files_cache = config.get('files_cache') + archive_hostname = config.get('archive_hostname') archive_name_format = ( config.get('archive_name_format', flags.get_default_archive_name_format(local_borg_version)) + archive_suffix @@ -250,6 +251,7 @@ def make_base_create_command( # noqa: PLR0912 + noflags_flags + (('--files-changed', files_changed) if files_changed else ()) + (('--files-cache', files_cache) if files_cache else ()) + + (('--hostname', archive_hostname) if archive_hostname else ()) + (('--remote-path', remote_path) if remote_path else ()) + (('--umask', str(umask)) if umask else ()) + (('--lock-wait', str(lock_wait)) if lock_wait else ()) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index da5c1eae..6e936ab4 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -511,6 +511,13 @@ properties: info, or check, borgmatic automatically tries to match only archives created with this name format. example: "{hostname}-documents-{now}" + archive_hostname: + type: string + description: | + Hostname to use when creating an archive, e.g. via the "{hostname}" + placeholder in "archive_name_format". Defaults to the system + hostname. (This option is supported for Borg 1.4.5+ only.) + example: example.org match_archives: type: string description: | diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index d9063583..04030272 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -518,6 +518,7 @@ def test_make_base_create_command_with_store_config_false_omits_config_files(): ('flags', False, False, ('--nobsdflags',)), ('files_changed', 'mtime', True, ('--files-changed', 'mtime')), ('files_cache', 'ctime,size', True, ('--files-cache', 'ctime,size')), + ('archive_hostname', 'example.org', True, ('--hostname', 'example.org')), ('umask', 740, True, ('--umask', '740')), ('lock_wait', 5, True, ('--lock-wait', '5')), ),