Expand available variables in hooks: add location #867

Open
opened 2024-05-15 16:33:42 +00:00 by Blackstareye · 3 comments

Borgmatic uses Variable Interpolation
for hooks.

At the moment, only 3 variables can be used there (plus envs)


* configuration_filename: borgmatic configuration filename in which the hook was defined
* log_file New in version 1.7.12: path of the borgmatic log file, only set when the --log-file flag is used
* repository: path of the current repository as configured in the current borgmatic configuration file

It would be great if there would be more variables possible.
I use borgmatic in combination with my own telegram bot for logging. I backup nfs-mounts there which can sometimes be unavailable.

With the help of the Doku
i managed to deal with it and implement a healthcheck and abort if the nfs mount is not there.
Unfortunately I have to hardcode (or use constants) if I want to log the location that is having the error.

Is it possible to add {location} to the possible variables as well ? That could make my configuration a lot more reusable.

Implementation Details

Having a first look, I think that is the part of the source code that needs to be expanded. But I don't know if there are other locations as well.

Many Thanks in advance.

Have a great Day :)

Borgmatic uses [Variable Interpolation](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/#variable-interpolation) for hooks. At the moment, only 3 variables can be used there (plus envs) <hr> * configuration_filename: borgmatic configuration filename in which the hook was defined * log_file New in version 1.7.12: path of the borgmatic log file, only set when the --log-file flag is used * repository: path of the current repository as configured in the current borgmatic configuration file <hr> It would be great if there would be more variables possible. I use borgmatic in combination with my own telegram bot for logging. I backup nfs-mounts there which can sometimes be unavailable. With the help of [the Doku](https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/) i managed to deal with it and implement a healthcheck and abort if the nfs mount is not there. Unfortunately I have to hardcode (or use constants) if I want to log the location that is having the error. Is it possible to add `{location}` to the possible variables as well ? That could make my configuration a lot more reusable. ## Implementation Details Having a first look, I think that is the part of the source code that needs to be expanded. But I don't know if there are other locations as well. * https://projects.torsion.org/borgmatic-collective/borgmatic/src/commit/5752373009689b36fc88f4d60521f203f0ca9b13/borgmatic/commands/borgmatic.py#L288 Many Thanks in advance. Have a great Day :)
Blackstareye changed title from Expand available variables in hooks: to Expand available variables in hooks: add `location` 2024-05-15 16:35:16 +00:00
Owner

We can certainly add more interpolated variables if they're generally useful. When you say "location" what exactly are you referring to?

Having a first look, I think that is the part of the source code that needs to be expanded. But I don't know if there are other locations as well.

That's it, yeah. Note though that configuration_filename is tacked on within borgmatic/hooks/command.py:execute_hook() instead.

i managed to deal with it and implement a healthcheck and abort if the nfs mount is not there.

I assume you're using this feature? https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/

We can certainly add more interpolated variables if they're generally useful. When you say "location" what exactly are you referring to? > Having a first look, I think that is the part of the source code that needs to be expanded. But I don't know if there are other locations as well. That's it, yeah. Note though that `configuration_filename` is tacked on within `borgmatic/hooks/command.py:execute_hook()` instead. > i managed to deal with it and implement a healthcheck and abort if the nfs mount is not there. I assume you're using this feature? https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/
Author

I mean location.source_directories (screenshot) :)
grafik

That's it, yeah. Note though that configuration_filename is tacked on within borgmatic/hooks/command.py:execute_hook() instead.

Nice, so it's not that hard to add this feature ?

I assume you're using this feature? https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/
Yes exactly. This one to be more specific:

before_backup:
    - findmnt /mnt/removable > /dev/null || exit 75

(but with return code 1, cause i need a systemd unit failure and want a error notification)

I mean location.source_directories (screenshot) :) ![grafik](/attachments/a109e6ec-8b33-4e33-82f3-5c79fd1303e9) > That's it, yeah. Note though that configuration_filename is tacked on within borgmatic/hooks/command.py:execute_hook() instead. Nice, so it's not that hard to add this feature ? >I assume you're using this feature? https://torsion.org/borgmatic/docs/how-to/backup-to-a-removable-drive-or-an-intermittent-server/ Yes exactly. This one to be more specific: ```yaml before_backup: - findmnt /mnt/removable > /dev/null || exit 75 ``` (but with return code 1, cause i need a systemd unit failure and want a error notification)
Owner

Thanks for the explanation! However I don't think passing source_directories would work here for a couple of reasons:

  1. It's a list! Which means you'd get every source directory configured passed in via the interpolated variable rather than the particular path that is causing NFS mount issues.
  2. We'd need to come up with a way to encode that list (JSON, etc.) which wouldn't necessarily be straightforward to parse especially in something like a shell script.

Unfortunately I have to hardcode (or use constants) if I want to log the location that is having the error.

When borgmatic is run with --verbosity 2, I believe it should log the findmnt command that's erroring, and that includes the mount path. So are you hoping to log, for instance, that /mnt/removable's NFS mount wasn't available? How are you hoping to log it?

Thanks for the explanation! However I don't think passing `source_directories` would work here for a couple of reasons: 1. It's a list! Which means you'd get every source directory configured passed in via the interpolated variable rather than the particular path that is causing NFS mount issues. 2. We'd need to come up with a way to encode that list (JSON, etc.) which wouldn't necessarily be straightforward to parse especially in something like a shell script. > Unfortunately I have to hardcode (or use constants) if I want to log the location that is having the error. When borgmatic is run with `--verbosity 2`, I believe it should log the `findmnt` command that's erroring, and that includes the mount path. So are you hoping to log, for instance, that `/mnt/removable`'s NFS mount wasn't available? How are you hoping to log 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#867
No description provided.