borgmatic-collective / docker-borgmatic

Borgmatic in Docker
GNU General Public License v3.0
313 stars 88 forks source link

on_error and Apprise causing Borgmatic to fail backups #306

Closed ericswpark closed 3 months ago

ericswpark commented 3 months ago

Here is the on_error hook I was using:

on_error:
  - apprise --title="Borgmatic" --body="An error occurred.\n{error}\n{output}" -e

It was working fine, until an update to borgmatic broke it. Now it fails with the following output:

/etc/borgmatic.d/config.yaml: Error running on-error hook
Usage: apprise [OPTIONS] SERVER_URL [SERVER_URL2 [SERVER_URL3]]
Try 'apprise -h' for help.
Error: No such option: --keep-daily
Command 'apprise --title="Borgmatic" --body="An error occurred.\n'Command '"'"'borg prune --keep-daily 7 --keep-hourly 24 --keep-monthly 6 --keep-yearly 5 --glob-archives server-1-* --stats --info --list ssh://borg@server-2/./server-1.borg'"'"' returned non-zero exit status 2.'\n'...
  File "/usr/lib/python3/dist-packages/borg/remote.py", line 368, in open
(...)

It seems like the {error} variable does some quote escaping, which manages to escape out of the --body="" quotes.

witten commented 3 months ago

This looks like a borgmatic issue and not an issue with the Docker container. I recommend filing it here instead: https://torsion.org/borgmatic/#issues

Thank you!

ericswpark commented 3 months ago

@witten just transferred, closing this issue. Thanks and sorry for filing it in the wrong place.

witten commented 3 months ago

Thank you! It's not a problem at all.

caronc commented 3 months ago

Consider not providing a --body and leverage stdin (I'm not sure if this is possible with the templating system in place?🤷‍♂️) This would eliminate the need to do any escaping at all.

witten commented 3 months ago

Currently, borgmatic hooks don't support stdin/stdout piping to/from borgmatic itself, although I suppose you could do it within a hook (e.g. echo {error} | apprise --stdin ...). However, the good news is borgmatic now supports Apprise logging natively so such work-arounds should no longer be necessary!

Also see this borgmatic ticket, which @ericswpark filed based on this docker-borgmatic issue: https://projects.torsion.org/borgmatic-collective/borgmatic/issues/839