Constant not accepted by borgmatic validate in shell commands to be executed before/after create/prune/compact/check #741

Closed
opened 2023-08-09 09:03:27 +00:00 by gdurif · 1 comment

What I'm trying to do and why

I want to use "constant" to define a (long) command to be executed before/after create/prune/compact/check (and avoid copy-pasting it multiple times). Specifically, it is a command to notify the user that a backup is in progress (since I want to use borgmatic in a cronjob).

For instance, I defined a constant like this in the ~/.config/borgmatic/config.yaml file:

constants:
    notify: notify-send -a borgmatic -h "string:desktop-entry:org.kde.konsole"

And I want to use it like this (again in the ~/.config/borgmatic/config.yaml file):

before_backup:
    - {notify} "Starting a backup."

However, the command borgmatic config validate --config ~/.config/borgmatic/config.yaml returns an error telling me that there is an issue with the line - {notify} "Starting a backup.":

summary:
/home/xxx/sysadmin/config/borgmatic/config.yaml.try: Error parsing configuration file
An error occurred while parsing a configuration file at /home/xxx/sysadmin/config/borgmatic/config.yaml.try:
while parsing a block collection
  in "<unicode string>", line 358, column 5
did not find expected '-' indicator
  in "<unicode string>", line 358, column 16
Configuration validation failed

Need some help? https://torsion.org/borgmatic/#issues

Note: I tried with a more simple command (c.f. below) but the issue remains.

constants:
    echo: echo
before_backup:
    - {echo} "Starting a backup."

Steps to reproduce

  1. Generate a vanilla borgmatic config file:
$ borgmatic config generate -d ~/.config/borgmatic/config.yaml

Output:

Generating a configuration file at: /home/xxx/.config/borgmatic/config.yaml

This includes all available configuration options with example values, the few
required options as indicated. Please edit the file to suit your needs.

If you ever need help: https://torsion.org/borgmatic/#issues

summary:
Generate successful
  1. Edit the default borgmatic config file ~/.config/borgmatic/config.yaml with the following:
constants:
    notify: notify-send -a borgmatic -h "string:desktop-entry:org.kde.konsole"
before_backup:
    - {notify} "Starting a backup."
  1. Check the config file:
$ borgmatic config validate --config ~/.config/borgmatic/config.yaml

Output:

summary:
/home/xxx/sysadmin/config/borgmatic/config.yaml: Error parsing configuration file
An error occurred while parsing a configuration file at /home/xxx/sysadmin/config/borgmatic/config.yaml:
while parsing a block collection
  in "<unicode string>", line 358, column 5
did not find expected '-' indicator
  in "<unicode string>", line 358, column 16
Configuration validation failed

Need some help? https://torsion.org/borgmatic/#issues

Actual behavior

borgmatic config validate does not accept "constant" being used in shell commands to be executed before/after create/prune/compact/check in borgmatic config file.

Expected behavior

"constant" can be used in shell commands to be executed before/after create/prune/compact/check in borgmatic config file.

Other notes / implementation ideas

No response

borgmatic version

1.8.0

borgmatic installation method

extra/borgmatic 1.8.0-1 ArchLinux package

Borg version

1.2.4

Python version

3.11.3

Database version (if applicable)

No response

Operating system and version

ArchLinux

### What I'm trying to do and why I want to use "constant" to define a (long) command to be executed before/after create/prune/compact/check (and avoid copy-pasting it multiple times). Specifically, it is a command to notify the user that a backup is in progress (since I want to use borgmatic in a cronjob). For instance, I defined a constant like this in the `~/.config/borgmatic/config.yaml` file: ``` constants: notify: notify-send -a borgmatic -h "string:desktop-entry:org.kde.konsole" ``` And I want to use it like this (again in the `~/.config/borgmatic/config.yaml` file): ``` before_backup: - {notify} "Starting a backup." ``` However, the command `borgmatic config validate --config ~/.config/borgmatic/config.yaml` returns an error telling me that there is an issue with the line `- {notify} "Starting a backup."`: ``` summary: /home/xxx/sysadmin/config/borgmatic/config.yaml.try: Error parsing configuration file An error occurred while parsing a configuration file at /home/xxx/sysadmin/config/borgmatic/config.yaml.try: while parsing a block collection in "<unicode string>", line 358, column 5 did not find expected '-' indicator in "<unicode string>", line 358, column 16 Configuration validation failed Need some help? https://torsion.org/borgmatic/#issues ``` **Note**: I tried with a more simple command (c.f. below) but the issue remains. ``` constants: echo: echo ``` ``` before_backup: - {echo} "Starting a backup." ``` ### Steps to reproduce 1. Generate a vanilla borgmatic config file: ``` $ borgmatic config generate -d ~/.config/borgmatic/config.yaml ``` Output: ``` Generating a configuration file at: /home/xxx/.config/borgmatic/config.yaml This includes all available configuration options with example values, the few required options as indicated. Please edit the file to suit your needs. If you ever need help: https://torsion.org/borgmatic/#issues summary: Generate successful ``` 2. Edit the default borgmatic config file `~/.config/borgmatic/config.yaml` with the following: ``` constants: notify: notify-send -a borgmatic -h "string:desktop-entry:org.kde.konsole" ``` ``` before_backup: - {notify} "Starting a backup." ``` 3. Check the config file: ``` $ borgmatic config validate --config ~/.config/borgmatic/config.yaml ``` Output: ``` summary: /home/xxx/sysadmin/config/borgmatic/config.yaml: Error parsing configuration file An error occurred while parsing a configuration file at /home/xxx/sysadmin/config/borgmatic/config.yaml: while parsing a block collection in "<unicode string>", line 358, column 5 did not find expected '-' indicator in "<unicode string>", line 358, column 16 Configuration validation failed Need some help? https://torsion.org/borgmatic/#issues ``` ### Actual behavior `borgmatic config validate` does not accept "constant" being used in shell commands to be executed before/after create/prune/compact/check in borgmatic config file. ### Expected behavior "constant" can be used in shell commands to be executed before/after create/prune/compact/check in borgmatic config file. ### Other notes / implementation ideas _No response_ ### borgmatic version 1.8.0 ### borgmatic installation method extra/borgmatic 1.8.0-1 ArchLinux package ### Borg version 1.2.4 ### Python version 3.11.3 ### Database version (if applicable) _No response_ ### Operating system and version ArchLinux
Owner

I believe this is actually a YAML limitation. The { at the start of the before_backup value is confusing the YAML parser because that's how you start an inline mapping value (key/value pairs all on one line). So to specify a constant at the start of a value without confusing YAML is to quote it. For instance:

before_backup:
    - "{notify} 'Starting a backup'"

Note that the inner quotes are single quotes in that example. Let me know if that works for you!

What I can do though is clarify this limitation in the documentation.

I believe this is actually a YAML limitation. The `{` at the start of the `before_backup` value is confusing the YAML parser because that's how you start an inline mapping value (key/value pairs all on one line). So to specify a constant at the start of a value without confusing YAML is to quote it. For instance: ``` before_backup: - "{notify} 'Starting a backup'" ``` Note that the inner quotes are _single_ quotes in that example. Let me know if that works for you! What I can do though is clarify this limitation in the documentation.
witten added the
question / support
label 2023-08-10 06:04:50 +00:00
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#741
No description provided.