Replace Repository while Merging Configs #1328

Open
opened 2026-06-25 06:51:52 +00:00 by marcohald · 3 comments

What I'm trying to do and why

I try to override the repository via an include.
But it gets added instead of replaced.

Steps to reproduce

config.yaml
<<: !include [/etc/borgmatic/common.yaml, /etc/borgmatic/custom-common.yaml, /etc/borgmatic/custom-config.yaml]
common.yaml

constants:
    fqdn: !include /etc/borgmatic/hostname
    backupserver: !include /etc/borgmatic/backupserver
#/etc/hostname

# A required list of local or remote repositories with paths and
# optional labels (which can be used with the --repository flag to
# select a repository). Tildes are expanded. Multiple repositories are
# backed up to in sequence. Borg placeholders can be used. See the
# output of "borg help placeholders" for details. See ssh_command for
# SSH options like identity file or port. If systemd service is used,
# then add local repository paths in the systemd service file to the
# ReadWritePaths list. Prior to borgmatic 1.7.10, repositories was a
# list of plain path strings.
repositories:
    - path: ssh://backupuser@{backupserver}//srv/borg/{fqdn}
      label: {backupserver}

custom-common.yaml

repositories:
    - path: ssh://backupuser@backupserver//srv/borg/fqdn/host
      label: "backupserver"
relocated_repo_access_is_ok: true

Actual behavior

borgmatic config validate --show -nc

repositories:
    - label: backupserver
      path: ssh://backupuser@backupserver//srv/borg/fqdn
    - label: backupserver
      path: ssh://backupuser@backupserver//srv/borg/fqdn/host

Expected behavior

Only the repository in custom-common.yaml should be there

repositories:
    - label: backupserver
      path: ssh://backupuser@backupserver//srv/borg/fqdn/host

Other notes / implementation ideas

No response

borgmatic version

1.8.2

borgmatic installation method

Debian package

Borg version

No response

Python version

No response

Database version (if applicable)

No response

Operating system and version

No response

### What I'm trying to do and why I try to override the repository via an include. But it gets added instead of replaced. ### Steps to reproduce config.yaml `<<: !include [/etc/borgmatic/common.yaml, /etc/borgmatic/custom-common.yaml, /etc/borgmatic/custom-config.yaml] ` common.yaml ``` constants: fqdn: !include /etc/borgmatic/hostname backupserver: !include /etc/borgmatic/backupserver #/etc/hostname # A required list of local or remote repositories with paths and # optional labels (which can be used with the --repository flag to # select a repository). Tildes are expanded. Multiple repositories are # backed up to in sequence. Borg placeholders can be used. See the # output of "borg help placeholders" for details. See ssh_command for # SSH options like identity file or port. If systemd service is used, # then add local repository paths in the systemd service file to the # ReadWritePaths list. Prior to borgmatic 1.7.10, repositories was a # list of plain path strings. repositories: - path: ssh://backupuser@{backupserver}//srv/borg/{fqdn} label: {backupserver} ``` custom-common.yaml ``` repositories: - path: ssh://backupuser@backupserver//srv/borg/fqdn/host label: "backupserver" relocated_repo_access_is_ok: true ``` ### Actual behavior borgmatic config validate --show -nc ``` repositories: - label: backupserver path: ssh://backupuser@backupserver//srv/borg/fqdn - label: backupserver path: ssh://backupuser@backupserver//srv/borg/fqdn/host ``` ### Expected behavior Only the repository in `custom-common.yaml` should be there ``` repositories: - label: backupserver path: ssh://backupuser@backupserver//srv/borg/fqdn/host ``` ### Other notes / implementation ideas _No response_ ### borgmatic version 1.8.2 ### borgmatic installation method Debian package ### Borg version _No response_ ### Python version _No response_ ### Database version (if applicable) _No response_ ### Operating system and version _No response_
Owner

Merging lists like this is borgmatic's default behavior. If, for a particular option like repositories, you'd like to retain only the local values and ignore included values, you can use the !retain tag. Here's an example:

repositories: !retain
    - path: ssh://backupuser@{backupserver}//srv/borg/{fqdn}
      label: {backupserver}

Alternatively, if you'd like to merge in some list values and omit other values, you can use the !omit tag.

Hope that helps!

Merging lists like this is borgmatic's default behavior. If, for a particular option like `repositories`, you'd like to retain only the local values and ignore included values, you can use the [`!retain` tag](https://torsion.org/borgmatic/reference/configuration/includes/#shallow-merge). Here's an example: ```yaml repositories: !retain - path: ssh://backupuser@{backupserver}//srv/borg/{fqdn} label: {backupserver} ``` Alternatively, if you'd like to merge in *some* list values and omit other values, you can use the [`!omit` tag](https://torsion.org/borgmatic/reference/configuration/includes/#list-merge). Hope that helps!
Author

Thank you for your answer, but i want to archive the opposite.
The last included file custom-common.yaml should overwrite the repositories list

Thank you for your answer, but i want to archive the opposite. The last included file `custom-common.yaml` should overwrite the repositories list
Owner

Gotcha. Unfortunately there's not currently a way for an included file's option to override an option in the file that's performing the include. From the documentation:

When there's an option collision between the local file and the merged include, the local file's option takes precedence.

One idea for a way to solve this with the existing functionality would be omit repositories entirely from your config.yaml. If it's omitted entirely but then the repositories option is pulled in via an include, then that included repositories will take effect in the merged configuration.

Another idea is to reverse the configuration file dependency order completely, such that config.yaml becomes the included file and custom-common.yaml becomes the main configuration file that performs the includes. In that case, the reposititories value from custom-common.yaml will have precedence.

Hope something like that will work for you. If not, please let me know!

Gotcha. Unfortunately there's not currently a way for an included file's option to override an option in the file that's performing the include. From [the documentation](https://torsion.org/borgmatic/reference/configuration/includes/#deep-merge): > When there's an option collision between the local file and the merged include, the local file's option takes precedence. One idea for a way to solve this with the existing functionality would be omit `repositories` entirely from your `config.yaml`. If it's omitted entirely but then the `repositories` option is pulled in via an include, then that included `repositories` will take effect in the merged configuration. Another idea is to reverse the configuration file dependency order completely, such that `config.yaml` becomes the included file and `custom-common.yaml` becomes the main configuration file that performs the includes. In that case, the `reposititories` value from `custom-common.yaml` will have precedence. Hope something like that will work for you. If not, please let me know!
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#1328
No description provided.