Variable '{hostname}' is not supported in after error hook #1075

Closed
opened 2025-04-17 12:41:19 +00:00 by kimheino · 3 comments
Contributor

What I'm trying to do and why

I want borgmatic to email me if something went wrong. This error has been there for ages...

Steps to reproduce

My config file has:

repositories:
    - path: ssh://XXX@baz-jemma.foobar.fi:23/./borg
      label: baz-jemma

...

commands:
    - after: error
      run:
          - (echo "{error}"; echo; echo "{output}") | s-nail -S sendwait -s "Backup failed on $(hostname)" root

Actual behavior

Running "borgmatic create" and then killing borg+ssh I get:

baz-jemma: Error running actions for repository
baz-jemma: Command 'borg create --patterns-from /run/user/0/borgmatic/tmpvuzna3yw --exclude-if-present .nobackup --compression zstd,10 --debug --show-rc ssh://XXX@baz-jemma.foobar.fi:23/./borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' died with <Signals.SIGKILL: 9>.
/etc/borgmatic.d/baz-jemma.yaml: Error running configuration
/etc/borgmatic.d/baz-jemma.yaml: Variable '{hostname}' is not supported in after error hook
/etc/borgmatic.d/baz-jemma.yaml: Running after error command hook
/etc/borgmatic.d/baz-jemma.yaml: (echo "'Command '"'"'borg create --patterns-from /run/user/0/borgmatic/tmpvuzna3yw --exclude-if-present .nobackup --compression zstd,10 --debug --show-rc ssh://XXX@baz-jemma.foobar.fi:23/./borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'"'"' died with <Signals.SIGKILL: 9>.'"; echo; echo "'... Remote: 33 self tests completed in 0.08 seconds Remote: using builtin fallback logging configuration Remote: Initialized logging system for JSON-based protocol Remote: Resolving repository path b'"'"'/./borg'"'"' Remote: Resolved repository path to '"'"'/home/borg'"'"' Remote: Verified integrity of /home/borg/index.12123 TAM-verified manifest Killed stale lock risa.bbbs.net@95541176135.622966-0. Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0. Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0. security: read previous location '"'"'ssh://XXX@baz-jemma.foobar.fi:23/./borg'"'"' security: read ...
/etc/borgmatic.d/baz-jemma.yaml: An error occurred

summary:
/etc/borgmatic.d/baz-jemma.yaml: Loading configuration file
An error occurred
Error running actions for repository
...
Remote: 33 self tests completed in 0.08 seconds
Remote: using builtin fallback logging configuration
Remote: Initialized logging system for JSON-based protocol
Remote: Resolving repository path b'/./borg'
Remote: Resolved repository path to '/home/borg'
Remote: Verified integrity of /home/borg/index.12123
TAM-verified manifest
Killed stale lock risa.bbbs.net@95541176135.622966-0.
Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0.
Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0.
security: read previous location 'ssh://XXX@baz-jemma.foobar.fi:23/./borg'
security: read manifest timestamp '2025-04-16T23:46:02.810382'
security: determined newest manifest timestamp as 2025-04-16T23:46:02.810382
security: repository checks ok, allowing access
Creating archive at "ssh://XXX@baz-jemma.foobar.fi:23/./borg::risa-2025-04-17T15:32:41.937466"
Verified integrity of /root/.cache/borg/84d24efbe725850649bc83556a307876ef9260d02e1ace77e8740f175f23da38/chunks
Reading files cache ...
Verified integrity of /root/.cache/borg/84d24efbe725850649bc83556a307876ef9260d02e1ace77e8740f175f23da38/files
security: read previous location 'ssh://XXX@baz-jemma.foobar.fi:23/./borg'
security: read manifest timestamp '2025-04-16T23:46:02.810382'
security: determined newest manifest timestamp as 2025-04-16T23:46:02.810382
security: repository checks ok, allowing access
Processing files ...
Remote: Cleaned up 1 uncommitted segment files (== everything after segment 12123).
Remote: Verified integrity of /home/borg/hints.12123
Command 'borg create --patterns-from /run/user/0/borgmatic/tmpvuzna3yw --exclude-if-present .nobackup --compression zstd,10 --debug --show-rc ssh://XXX@baz-jemma.foobar.fi:23/./borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' died with <Signals.SIGKILL: 9>.
Error running configuration

Expected behavior

There should be no " Variable '{hostname}' is not supported in after error hook" error to console.

...or some other way to email me error+output?

Other notes / implementation ideas

No response

borgmatic version

2.0.3

borgmatic installation method

No response

Borg version

1.2.7

Python version

3.9.21

Database version (if applicable)

No response

Operating system and version

Foobar Linux 9 (Centos stream 9)

### What I'm trying to do and why I want borgmatic to email me if something went wrong. This error has been there for ages... ### Steps to reproduce My config file has: ``` repositories: - path: ssh://XXX@baz-jemma.foobar.fi:23/./borg label: baz-jemma ... commands: - after: error run: - (echo "{error}"; echo; echo "{output}") | s-nail -S sendwait -s "Backup failed on $(hostname)" root ``` ### Actual behavior Running "borgmatic create" and then killing borg+ssh I get: ``` baz-jemma: Error running actions for repository baz-jemma: Command 'borg create --patterns-from /run/user/0/borgmatic/tmpvuzna3yw --exclude-if-present .nobackup --compression zstd,10 --debug --show-rc ssh://XXX@baz-jemma.foobar.fi:23/./borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' died with <Signals.SIGKILL: 9>. /etc/borgmatic.d/baz-jemma.yaml: Error running configuration /etc/borgmatic.d/baz-jemma.yaml: Variable '{hostname}' is not supported in after error hook /etc/borgmatic.d/baz-jemma.yaml: Running after error command hook /etc/borgmatic.d/baz-jemma.yaml: (echo "'Command '"'"'borg create --patterns-from /run/user/0/borgmatic/tmpvuzna3yw --exclude-if-present .nobackup --compression zstd,10 --debug --show-rc ssh://XXX@baz-jemma.foobar.fi:23/./borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'"'"' died with <Signals.SIGKILL: 9>.'"; echo; echo "'... Remote: 33 self tests completed in 0.08 seconds Remote: using builtin fallback logging configuration Remote: Initialized logging system for JSON-based protocol Remote: Resolving repository path b'"'"'/./borg'"'"' Remote: Resolved repository path to '"'"'/home/borg'"'"' Remote: Verified integrity of /home/borg/index.12123 TAM-verified manifest Killed stale lock risa.bbbs.net@95541176135.622966-0. Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0. Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0. security: read previous location '"'"'ssh://XXX@baz-jemma.foobar.fi:23/./borg'"'"' security: read ... /etc/borgmatic.d/baz-jemma.yaml: An error occurred summary: /etc/borgmatic.d/baz-jemma.yaml: Loading configuration file An error occurred Error running actions for repository ... Remote: 33 self tests completed in 0.08 seconds Remote: using builtin fallback logging configuration Remote: Initialized logging system for JSON-based protocol Remote: Resolving repository path b'/./borg' Remote: Resolved repository path to '/home/borg' Remote: Verified integrity of /home/borg/index.12123 TAM-verified manifest Killed stale lock risa.bbbs.net@95541176135.622966-0. Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0. Removed stale exclusive roster lock for host risa.bbbs.net@95541176135 pid 622966 thread 0. security: read previous location 'ssh://XXX@baz-jemma.foobar.fi:23/./borg' security: read manifest timestamp '2025-04-16T23:46:02.810382' security: determined newest manifest timestamp as 2025-04-16T23:46:02.810382 security: repository checks ok, allowing access Creating archive at "ssh://XXX@baz-jemma.foobar.fi:23/./borg::risa-2025-04-17T15:32:41.937466" Verified integrity of /root/.cache/borg/84d24efbe725850649bc83556a307876ef9260d02e1ace77e8740f175f23da38/chunks Reading files cache ... Verified integrity of /root/.cache/borg/84d24efbe725850649bc83556a307876ef9260d02e1ace77e8740f175f23da38/files security: read previous location 'ssh://XXX@baz-jemma.foobar.fi:23/./borg' security: read manifest timestamp '2025-04-16T23:46:02.810382' security: determined newest manifest timestamp as 2025-04-16T23:46:02.810382 security: repository checks ok, allowing access Processing files ... Remote: Cleaned up 1 uncommitted segment files (== everything after segment 12123). Remote: Verified integrity of /home/borg/hints.12123 Command 'borg create --patterns-from /run/user/0/borgmatic/tmpvuzna3yw --exclude-if-present .nobackup --compression zstd,10 --debug --show-rc ssh://XXX@baz-jemma.foobar.fi:23/./borg::{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' died with <Signals.SIGKILL: 9>. Error running configuration ``` ### Expected behavior There should be no " Variable '{hostname}' is not supported in after error hook" error to console. ...or some other way to email me error+output? ### Other notes / implementation ideas _No response_ ### borgmatic version 2.0.3 ### borgmatic installation method _No response_ ### Borg version 1.2.7 ### Python version 3.9.21 ### Database version (if applicable) _No response_ ### Operating system and version Foobar Linux 9 (Centos stream 9)
Owner

Thanks for filing this. I am able to repro this behavior, although I'm not yet sure exactly what's going on. I can tell you that Variable '{hostname}' is not supported in after error hook is a warning, and shouldn't impact anything downstream. To answer your question, there isn't yet a built-in borgmatic hook for sending email directly, but there are a number of monitoring hooks, some of which can send email as a side effect. And of course there's always the option to add a command hook to send email manually as you're doing here.

Thanks for filing this. I am able to repro this behavior, although I'm not yet sure exactly what's going on. I can tell you that `Variable '{hostname}' is not supported in after error hook` is a warning, and shouldn't impact anything downstream. To answer your question, there isn't yet a built-in borgmatic hook for sending email directly, but there are a number of [monitoring hooks](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/), some of which can send email as a side effect. And of course there's always the option to add a command hook to send email manually as you're doing here.
witten added the bug label 2025-04-19 06:31:01 +00:00
Owner

This is fixed in main and will be part of the next release! The solution I went with was to suppress this warning when a variable matches a Borg placeholder (with the idea that Borg will handle the variable) but still show the warning otherwise for an unknown variable.

This is fixed in main and will be part of the next release! The solution I went with was to suppress this warning when a variable matches a [Borg placeholder](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-placeholders) (with the idea that Borg will handle the variable) but still show the warning otherwise for an unknown variable.
Owner

Released in borgmatic 2.0.4!

Released in borgmatic 2.0.4!
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#1075