Overriding hostname constant doesn't affect default archive_name_format #763

Closed
opened 2023-10-02 18:27:11 +00:00 by Daniel · 4 comments

What I'm trying to do and why

The sample config file has this section at the top:

# Constants to use in the configuration file. All occurrences of the
# constant name within curly braces will be replaced with the value.
# For example, if you have a constant named "hostname" with the value
# "myhostname", then the string "{hostname}" will be replaced with
# "myhostname" in the configuration file.
# constants:
    # hostname: myhostname
    # prefix: myprefix

This implies that if I set a hostname constant, everywhere that uses {hostname} will use it instead of the default value (the actual hostname).

Docker containers don't have useful hostnames, so I'm trying to set hostname to a different value.

Steps to reproduce

Sanitized config:

constants:
    hostname: homenas

source_directories:
    - /mnt/data/foo
    - /mnt/data/bar

repositories:
    - path: ssh://backup-{hostname}@backups01.d.sb/data/backup/{hostname}/

exclude_if_present:
    - .nobackup

encryption_passphrase: "...."
compression: zstd

keep_daily: 7
keep_weekly: 4
keep_monthly: -1
keep_yearly: -1

# TODO: Add this when healthchecks server is up and running again
# healthchecks:
    # ping_url: https://hc-ping.com/your-uuid-here

Actual behavior

{hostname} in the path works fine - The path expands to ssh://backup-homenas@backups01.example.com/data/backup/homenas/`.

However, the archive_name_format, which is supposed to default to {hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}, still uses the actual hostname.

If I explicitly set the format in my config file:

archive_name_format: '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'

it works fine.

Expected behavior

The default archive_name_format should observe any custom value of the {hostname} constant.

Other notes / implementation ideas

No response

borgmatic version

1.8.3

borgmatic installation method

Docker ghcr.io/borgmatic-collective/borgmatic:1.8.3

Borg version

1.2.6

Python version

3.11.5

Database version (if applicable)

No response

Operating system and version

Alpine Linux v3.18 Docker container on unRAID host

### What I'm trying to do and why The sample config file has this section at the top: ``` # Constants to use in the configuration file. All occurrences of the # constant name within curly braces will be replaced with the value. # For example, if you have a constant named "hostname" with the value # "myhostname", then the string "{hostname}" will be replaced with # "myhostname" in the configuration file. # constants: # hostname: myhostname # prefix: myprefix ``` This implies that if I set a `hostname` constant, **everywhere** that uses `{hostname}` will use it instead of the default value (the actual hostname). Docker containers don't have useful hostnames, so I'm trying to set `hostname` to a different value. ### Steps to reproduce Sanitized config: ``` constants: hostname: homenas source_directories: - /mnt/data/foo - /mnt/data/bar repositories: - path: ssh://backup-{hostname}@backups01.d.sb/data/backup/{hostname}/ exclude_if_present: - .nobackup encryption_passphrase: "...." compression: zstd keep_daily: 7 keep_weekly: 4 keep_monthly: -1 keep_yearly: -1 # TODO: Add this when healthchecks server is up and running again # healthchecks: # ping_url: https://hc-ping.com/your-uuid-here ``` ### Actual behavior `{hostname} in the path works fine - The path expands to `ssh://backup-homenas@backups01.example.com/data/backup/homenas/`. However, the `archive_name_format`, which is supposed to default to `{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}`, still uses the actual hostname. If I explicitly set the format in my config file: ``` archive_name_format: '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' ``` it works fine. ### Expected behavior The default `archive_name_format` should observe any custom value of the `{hostname}` constant. ### Other notes / implementation ideas _No response_ ### borgmatic version 1.8.3 ### borgmatic installation method Docker `ghcr.io/borgmatic-collective/borgmatic:1.8.3` ### Borg version 1.2.6 ### Python version 3.11.5 ### Database version (if applicable) _No response_ ### Operating system and version Alpine Linux v3.18 Docker container on unRAID host
Owner

Thanks for filing this! What's going on here is that, confusingly, {hostname} can actually be substituted in two different places:

  1. If you declare a borgmatic hostname constant as you did here, {hostname} will get replaced anywhere it exists explicitly in the config file.
  2. If you don't declare a hostname constant and/or there's a default pattern containing {hostname} that doesn't appear directly in the config file (as is the case with archive_name_format), then the actual {hostname} string gets passed to Borg itself, which applies its own placeholder logic.

So one option for solving this discrepancy would be to do a first pass on default patterns like archive_name_format to apply borgmatic constants to them before passing them to Borg. Or: A work-around would be to set your own explicit archive_name_format.

In any case, I'm thinking I should probably change the example quoted to not set a constant named hostname, as that's confusing in relation to Borg's built-in placeholders.

Let me know your thoughts!

Thanks for filing this! What's going on here is that, confusingly, `{hostname}` can actually be substituted in two different places: 1. If you declare a borgmatic `hostname` constant as you did here, `{hostname}` will get replaced anywhere it exists explicitly in the config file. 2. If you don't declare a `hostname` constant and/or there's a default pattern containing `{hostname}` that doesn't appear directly in the config file (as is the case with `archive_name_format`), then the actual `{hostname}` string gets passed to Borg itself, which applies [its *own* placeholder logic](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-placeholders). So one option for solving this discrepancy would be to do a first pass on default patterns like `archive_name_format` to apply borgmatic constants to them before passing them to Borg. Or: A work-around would be to set your own explicit `archive_name_format`. In any case, I'm thinking I should probably change the example quoted to not set a constant named `hostname`, as that's confusing in relation to Borg's built-in placeholders. Let me know your thoughts!
Author

Ahh, I see. Now I understand. In that case, it's confusing that Borgmatic and Borgbackup both use the same syntax for their placeholder tokens.

would be to do a first pass on default patterns like archive_name_format to apply borgmatic constants to them before passing them to Borg

This seems like a good idea to me.

I'm thinking I should probably change the example quoted to not set a constant named hostname

Yeah. Maybe just having the {prefix} example is fine?

Ahh, I see. Now I understand. In that case, it's confusing that Borgmatic and Borgbackup both use the same syntax for their placeholder tokens. > would be to do a first pass on default patterns like archive_name_format to apply borgmatic constants to them before passing them to Borg This seems like a good idea to me. > I'm thinking I should probably change the example quoted to not set a constant named hostname Yeah. Maybe just having the `{prefix}` example is fine?
Owner

I did want to illustrate in particular that you could have multiple constants, so I think I'll just change the first example from hostname to something else. And in fact prefix is deprecated, so maybe I'll change the second example too. Then I'll document the fact that the two types of placeholders are indeed different. Finally, I'll see if constants can be applied to archive_name_format.

I did want to illustrate in particular that you could have multiple constants, so I think I'll just change the first example from `hostname` to something else. And in fact `prefix` is deprecated, so maybe I'll change the second example too. Then I'll document the fact that the two types of placeholders are indeed different. Finally, I'll see if constants can be applied to `archive_name_format`.
Owner

These changes have been made in main and will be part of the next release! Although I'll note that archive_name_format supporting a hostname constant may already have been done since borgmatic 1.8.5 due to #745. Thanks again for bringing this to my attention!

These changes have been made in main and will be part of the next release! Although I'll note that `archive_name_format` supporting a `hostname` constant may already have been done since borgmatic 1.8.5 due to #745. Thanks again for bringing this to my attention!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#763
No description provided.