substitution problems with included files #745

Closed
opened 2023-08-17 00:25:29 +00:00 by alsoeric · 4 comments

What I'm trying to do and why

I want constants defined in the backup-specific configuration file to substitute in the common configuration file. for example

in the common configuration file:
archive_name_format: '{backup_prefix}-{now:%Y-%m-%d_%H:%M}'

in the backup-specific config file

constants:
  backup_prefix: home
<<: !include /etc/borgmatic/config.yaml    

I would expect:

archive_name_format: 'home-{now:%Y-%m-%d_%H:%M}'

but get
archive_name_format: '{backup_prefix}-{now:%Y-%m-%d_%H:%M}'

Steps to reproduce

No response

Actual behavior

No response

Expected behavior

No response

Other notes / implementation ideas

No response

borgmatic version

No response

borgmatic installation method

No response

Borg version

1.8.1

Python version

Python 3.10.12

Database version (if applicable)

No response

Operating system and version

PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.3 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy

### What I'm trying to do and why I want constants defined in the backup-specific configuration file to substitute in the common configuration file. for example in the common configuration file: `archive_name_format: '{backup_prefix}-{now:%Y-%m-%d_%H:%M}'` in the backup-specific config file ``` constants: backup_prefix: home <<: !include /etc/borgmatic/config.yaml ``` I would expect: `archive_name_format: 'home-{now:%Y-%m-%d_%H:%M}'` but get `archive_name_format: '{backup_prefix}-{now:%Y-%m-%d_%H:%M}'` ### Steps to reproduce _No response_ ### Actual behavior _No response_ ### Expected behavior _No response_ ### Other notes / implementation ideas _No response_ ### borgmatic version _No response_ ### borgmatic installation method _No response_ ### Borg version 1.8.1 ### Python version Python 3.10.12 ### Database version (if applicable) _No response_ ### Operating system and version PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.3 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy
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 though, and it's probably worth revising the feature to work across includes.

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 though, and it's probably worth revising the feature to work across includes.

I have something that works with the following setup:

config.yaml

constants:
    !include common/constants.yaml

<<: !include common/common.yaml

#...more config using constants

common/constants.yaml

host: example.com
repo: myrepo

common/common.yaml

exclude_from:
    - common/excludes

ssh_command: ssh -p2023 -i ....

#...more config NOT using constants

Is it a happy accident that it works or should I be extra careful when upgrading to a future version? (currently using 1.8.2)

I have something that works with the following setup: `config.yaml` ```yaml constants: !include common/constants.yaml <<: !include common/common.yaml #...more config using constants ``` `common/constants.yaml` ```yaml host: example.com repo: myrepo ``` `common/common.yaml` ```yaml exclude_from: - common/excludes ssh_command: ssh -p2023 -i .... #...more config NOT using constants ``` Is it a happy accident that it works or should I be extra careful when upgrading to a future version? (currently using 1.8.2)
Owner

If I'm understanding correctly, common.yaml doesn't use any of your constants while config.yaml does. So it makes sense that this works currently. The only tricky part is that you're including the constants themselves, which is currently supported. As long as you don't introduce any use of constants within common.yaml or similar includes, then you should be fine!

If I'm understanding correctly, `common.yaml` doesn't use any of your constants while `config.yaml` does. So it makes sense that this works currently. The only tricky part is that you're including the constants themselves, which is currently supported. As long as you don't introduce any use of constants within `common.yaml` or similar includes, then you should be fine!
Owner

This has been implemented as part of borgmatic 1.8.5, just released. Thanks again for the suggestion!

This has been implemented as part of borgmatic 1.8.5, just released. Thanks again for the suggestion!
Sign in to join this conversation.
No Milestone
No Assignees
3 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#745
No description provided.