Before everything hook running twice with include directive #1124

Closed
opened 2025-07-31 15:33:48 +00:00 by dot-mike · 4 comments

What I'm trying to do and why

I'm trying to have separate repository config for an application-backup. To take backup I need to generate the backup first, so I implemented a before-hook for everything.

The issue is that the before-hook for everything runs twice, for each config-file as defined in .config/borgmatic.d/

Steps to reproduce

Use config files below, replace the variables as necessary

Common config file not used by borgmatic directly, only included
$ cat .config/borgmatic/gitea-common.yaml

verbosity: 2

commands:
  - before: everything
    when: [create]
    run:
      - "bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)'"
  - after: everything
    states: [finish]
    run:
      - "bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)'"
keep_within: '7d'
keep_daily:   7
keep_weekly:  4
keep_monthly: 6

borgmatic.d config files:

cat .config/borgmatic.d/gitea-local.yaml

<<: !include /var/services/homes/backup/.config/borgmatic/gitea-common.yaml

remote_path: /usr/local/bin/borg

repositories:
  - path: ssh://backupseerver/volume1/borgbackup/gitea-app
    label: localbackup

cat .config/borgmatic.d/gitea-remote.yaml

<<: !include /var/services/homes/backup/.config/borgmatic/gitea-common.yaml

encryption_passphrase: <secret>

repositories:
  - path: ssh://remoteserver/./borg-app-gitea
    label: remoteserver

Actual behavior

See that prepare_ is created twice, one for each config file.

backup@server:~$ borgmatic
Running before create everything command hook
PGDATA=*** bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)'
Running before create everything command hook
PGDATA=*** bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)'

Expected behavior

Only one prepare file should be created as we use everything for the hook. As stated in the docs:

everything runs before or after all configuration files. Errors here do not trigger error hooks or the fail state in monitoring hooks. This replaces the deprecated before_everything and after_everything.

Other notes / implementation ideas

No response

borgmatic version

2.0.3

borgmatic installation method

pip

Borg version

borg 1.4.1

Python version

Python 3.12.11

Database version (if applicable)

No response

Operating system and version

N/A

### What I'm trying to do and why I'm trying to have separate repository config for an application-backup. To take backup I need to generate the backup first, so I implemented a before-hook for everything. The issue is that the before-hook for everything runs twice, for each config-file as defined in `.config/borgmatic.d/` ### Steps to reproduce Use config files below, replace the variables as necessary Common config file not used by borgmatic directly, only included $ cat .config/borgmatic/gitea-common.yaml ```bash verbosity: 2 commands: - before: everything when: [create] run: - "bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)'" - after: everything states: [finish] run: - "bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)'" keep_within: '7d' keep_daily: 7 keep_weekly: 4 keep_monthly: 6 ``` borgmatic.d config files: cat .config/borgmatic.d/gitea-local.yaml ``` <<: !include /var/services/homes/backup/.config/borgmatic/gitea-common.yaml remote_path: /usr/local/bin/borg repositories: - path: ssh://backupseerver/volume1/borgbackup/gitea-app label: localbackup ``` cat .config/borgmatic.d/gitea-remote.yaml ``` <<: !include /var/services/homes/backup/.config/borgmatic/gitea-common.yaml encryption_passphrase: <secret> repositories: - path: ssh://remoteserver/./borg-app-gitea label: remoteserver ``` ### Actual behavior See that `prepare_` is created twice, one for each config file. backup@server:~$ borgmatic Running before create everything command hook PGDATA=*** bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)' Running before create everything command hook PGDATA=*** bash -c 'touch /tmp/borg-repro/prepare_$(date +%Y%m%d%H%M%S%N)' ### Expected behavior Only one prepare file should be created as we use `everything` for the hook. As stated in the docs: > `everything` runs before or after all configuration files. Errors here do not trigger error hooks or the fail state in monitoring hooks. This replaces the deprecated before_everything and after_everything. ### Other notes / implementation ideas _No response_ ### borgmatic version 2.0.3 ### borgmatic installation method pip ### Borg version borg 1.4.1 ### Python version Python 3.12.11 ### Database version (if applicable) _No response_ ### Operating system and version N/A
dot-mike changed title from Before everything hook running twice to Before everything hook running twice with include directive 2025-07-31 16:02:47 +00:00
Author

Looks like I've hit this issue: #1080 (comment) and should be solved in 2.0.4

Looks like I've hit this issue: https://projects.torsion.org/borgmatic-collective/borgmatic/issues/1080#issuecomment-11030 and should be solved in 2.0.4
Owner

Yup, good sleuthing! If upgrading to 2.0.4+ doesn't do it for you, please let me know.

Yup, good sleuthing! If upgrading to 2.0.4+ doesn't do it for you, please let me know.
Author

2.0.4+ solved it, thanks!

2.0.4+ solved it, thanks!
Owner

Glad to hear it!

Glad to hear it!
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#1124
No description provided.