Institution doesn't appear to work in include filenames #674

Closed
opened 2023-04-10 21:59:53 +00:00 by alsoeric · 2 comments

What I'm trying to do and why

Trying to work around the deep versus shallow merge issue with a include pathname hack

Steps to reproduce (if a bug)

ceate three configuration files. Topmost with fields that are deep merged. Template common with include path with the constant substitution field, and the configuration file with fields that are imported via the calculated pathname in the template common. See below for examples.

Topmost config

constants:
  incl_name: home

<<: !include /etc/borgmatic/pw-common.yaml
location:
  atime: true
  ...

master template fragment

location:
    <<: !include {incl_name}/location.yaml
    

home/location.yaml

source_directories:
  - /home
  - /etc
repositories:
  - path: 7909@usw-s007.rsync.net:pw-home
    label: backupserver

Actual behavior (if a bug)

(borg-env) root@lake:~# validate-borgmatic-config -c home.yaml
home.yaml: Error parsing configuration file
An error occurred while parsing a configuration file at home.yaml:
while parsing a block mapping
  in "<unicode string>", line 17, column 5
did not find expected key
  in "<unicode string>", line 17, column 29
    

Expected behavior (if a bug)

If the constant substitution occurred in the filename then the directory specified in the top level configuration file would be imported into the core template fragment effectively replacing that part of the configuration file and simulating a shallow merge.

While this example is is a hack around the lack of a shallow merge, I believe it would also be useful in general to calculate pathnames for different fig file fragments.

Other notes / implementation ideas

Environment

borgmatic version: [1.7.11]

Use sudo borgmatic --version or sudo pip show borgmatic | grep ^Version

borgmatic installation method: [pip3 into virtual environment]

Borg version: [1.2.4]

Use sudo borg --version

Python version: [3.10.6]

Use python3 --version

Database version (if applicable): [version here]

Use psql --version or mysql --version on client and server.

operating system and version: [Ubuntu 22.04]

#### What I'm trying to do and why Trying to work around the deep versus shallow merge issue with a include pathname hack #### Steps to reproduce (if a bug) ceate three configuration files. Topmost with fields that are deep merged. Template common with include path with the constant substitution field, and the configuration file with fields that are imported via the calculated pathname in the template common. See below for examples. Topmost config ``` constants: incl_name: home <<: !include /etc/borgmatic/pw-common.yaml location: atime: true ... ``` master template fragment ``` location: <<: !include {incl_name}/location.yaml ``` home/location.yaml ``` source_directories: - /home - /etc repositories: - path: 7909@usw-s007.rsync.net:pw-home label: backupserver ``` #### Actual behavior (if a bug) ``` (borg-env) root@lake:~# validate-borgmatic-config -c home.yaml home.yaml: Error parsing configuration file An error occurred while parsing a configuration file at home.yaml: while parsing a block mapping in "<unicode string>", line 17, column 5 did not find expected key in "<unicode string>", line 17, column 29 ``` #### Expected behavior (if a bug) If the constant substitution occurred in the filename then the directory specified in the top level configuration file would be imported into the core template fragment effectively replacing that part of the configuration file and simulating a shallow merge. While this example is is a hack around the lack of a shallow merge, I believe it would also be useful in general to calculate pathnames for different fig file fragments. #### Other notes / implementation ideas #### Environment **borgmatic version:** [1.7.11] Use `sudo borgmatic --version` or `sudo pip show borgmatic | grep ^Version` **borgmatic installation method:** [pip3 into virtual environment] **Borg version:** [1.2.4] Use `sudo borg --version` **Python version:** [3.10.6] Use `python3 --version` **Database version (if applicable):** [version here] Use `psql --version` or `mysql --version` on client and server. **operating system and version:** [Ubuntu 22.04]
Owner

Thanks for filing this. Constants not working across includes is a known/documented limitation that was put in place for simplicity of implementation and use, although I see why you'd want that limitation lifted for your use case.

If this were to be implemented, I think the way to do it would be to accumulate constants as each successive file is included (potentially replacing constants if they've already been defined at a higher include level), and doing the interpolation on each file as it's included.

I'm not sure though whether this is a "better" idea than just implementing #672, since this ticket (#674) is a work-around for not having that feature.

Thanks for filing this. Constants not working across includes is a [known/documented limitation](https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#constant-interpolation) that was put in place for simplicity of implementation and use, although I see why you'd want that limitation lifted for your use case. If this were to be implemented, I think the way to do it would be to accumulate constants as each successive file is included (potentially replacing constants if they've already been defined at a higher include level), and doing the interpolation on each file as it's included. I'm not sure though whether this is a "better" idea than just implementing #672, since this ticket (#674) is a work-around for not having that feature.
Author

Implementing #672 is a better idea. ok to close this

Implementing https://projects.torsion.org/borgmatic-collective/borgmatic/issues/672 is a better idea. ok to close this
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#674
No description provided.