Using constants in a config for placeholders in an included file. #788

Closed
opened 2023-11-14 00:39:40 +00:00 by shadow7412 · 2 comments

What I'm trying to do and why

I have a common yaml file that is imported by all of my backup configs.

This contains all my common settings (like upload limit, retention, repo passphrase and locations).

In the actual config, I'm importing this then defining the specifics (where this application lives for example).

<<: !include /mnt/[...]/common-includes.yaml
source_directories:
  - /path/to/application

I also had the healthchecks url and archive format in here - but I want to move to using a constant to "generate" these two values, as this will lighten this file a bit (and also mitigate copy-paste fails when creating a new config).

Steps to reproduce

This is an example common.yaml file

archive_name_format: "{prefix}_{now}"
healthchecks:
  ping_url: "https://hc-ping.com/[redacted]/{prefix}"

Inside each config, I set the prefix constant.

constants:
  prefix: "name_of_backup"

I thought this should work, but it looks like prefix isn't being recognised as a valid placeholder.

Actual behavior

When the backups run, I get the following message;

Summary:
/etc/borgmatic.d/homeassistant.yaml: An error occurred
local: Error running actions for repository
Invalid placeholder "prefix" in string: /mnt/borg-repository::{prefix}_{now}

Expected behavior

The prefix constant should resolve.

Other notes / implementation ideas

No response

borgmatic version

1.8.4

borgmatic installation method

docker

Borg version

1.2.6

Python version

3.11.5

Database version (if applicable)

N/A

Operating system and version

Alpine docker image, on an unraid server

### What I'm trying to do and why I have a common yaml file that is imported by all of my backup configs. This contains all my common settings (like upload limit, retention, repo passphrase and locations). In the actual config, I'm importing this then defining the specifics (where this application lives for example). ``` <<: !include /mnt/[...]/common-includes.yaml source_directories: - /path/to/application ``` I also had the healthchecks url and archive format in here - but I want to move to using a constant to "generate" these two values, as this will lighten this file a bit (and also mitigate copy-paste fails when creating a new config). ### Steps to reproduce This is an example common.yaml file ``` archive_name_format: "{prefix}_{now}" healthchecks: ping_url: "https://hc-ping.com/[redacted]/{prefix}" ``` Inside each config, I set the `prefix` constant. ``` constants: prefix: "name_of_backup" ``` I thought this should work, but it looks like `prefix` isn't being recognised as a valid placeholder. ### Actual behavior When the backups run, I get the following message; ``` Summary: /etc/borgmatic.d/homeassistant.yaml: An error occurred local: Error running actions for repository Invalid placeholder "prefix" in string: /mnt/borg-repository::{prefix}_{now} ``` ### Expected behavior The `prefix` constant should resolve. ### Other notes / implementation ideas _No response_ ### borgmatic version 1.8.4 ### borgmatic installation method docker ### Borg version 1.2.6 ### Python version 3.11.5 ### Database version (if applicable) N/A ### Operating system and version Alpine docker image, on an unraid server
Author

In case prefix was a reserved one, I tried renaming it to slug and got the same result.

In case `prefix` was a reserved one, I tried renaming it to `slug` and got the same result.
Owner

Thanks for filing this. Unfortunately this is a documented limitation of constants currently:

Constants don't work across includes or separate configuration files though.

I do think your use case is a valuable one, and so it's worth revising the feature to work across includes. There is already a ticket covering this work: #745. So I encourage you to follow along there. Thanks again for taking the time to write up a ticket on this! It helps me understand what pain points folks are hitting with borgmatic.

Thanks for filing this. Unfortunately this is a [documented](https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#constant-interpolation) limitation of constants currently: > Constants don't work across includes or separate configuration files though. I do think your use case is a valuable one, and so it's worth revising the feature to work across includes. There is already a ticket covering this work: #745. So I encourage you to follow along there. Thanks again for taking the time to write up a ticket on this! It helps me understand what pain points folks are hitting with borgmatic.
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#788
No description provided.