[docs suggestion] Include examples for notifications #416

Closed
opened 2021-05-07 14:07:48 +00:00 by lasimik · 2 comments

In the hooks section of the sample config, and in the docs, include a line how to do notifications, both for running borgmatic as a user or as root. e.g.

after_backup:
    # running borgmatic manually
    # - echo "Finished a backup."
    # running borgmatic as user
    # - notify-send --urgency=normal 'Borgmatic' 'Finished backup.'
    # running borgmatic as root, get USER and USER_ID from userdbctl
    # - sudo -u USER DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/USER_ID/bus notify-send --urgency=normal 'Borgmatic' 'Finished backup.\nEverything is fine.'

Using single quotes so \n will work.
Crude examples, can be improved...

EDITED TO ADD:
The notify-send… only work when root borgmatic is run manually (sudo -i then borgmatic).

If borgmatic is started by systemd, they run into problems with sudo. Ditto storing the date of last backup into a file in /etc/borgmatic. require that in borgmatic.service two capabilities are added: CAP_SETUID and CAP_SETGID.

NOT SURE ABOUT THE SECURITY IMPLICATIONS if capabilites are

CapabilityBoundingSet=CAP_DAC_READ_SEARCH CAP_NET_RAW CAP_SETUID CAP_SETGID

EDIT2: A different path (besides repo-specific files?) would be better to allow multiple dates for multiple repos.

EDIT3: If borgmatic could evaluate its own {repository}, it would allow to easily store something (such as the datetime of the last successful backup) alongside the local repo files, e.g. in /root/{repository}. Currently this path needs to be set manually inside the config.yaml, because {repository} is not evaluated in a script called from the after_backup hook.

In the hooks section of the sample config, and in the docs, include a line how to do notifications, both for running borgmatic as a user or as root. e.g. ``` after_backup: # running borgmatic manually # - echo "Finished a backup." # running borgmatic as user # - notify-send --urgency=normal 'Borgmatic' 'Finished backup.' # running borgmatic as root, get USER and USER_ID from userdbctl # - sudo -u USER DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/USER_ID/bus notify-send --urgency=normal 'Borgmatic' 'Finished backup.\nEverything is fine.' ``` Using single quotes so `\n` will work. Crude examples, can be improved... EDITED TO ADD: The `notify-send…` only work when root borgmatic is run *manually* (`sudo -i` then `borgmatic`). If borgmatic is started by systemd, they ~~run into problems with `sudo`. Ditto storing the date of last backup into a file in `/etc/borgmatic`.~~ require that in `borgmatic.service` two capabilities are added: `CAP_SETUID` and `CAP_SETGID`. NOT SURE ABOUT THE SECURITY IMPLICATIONS if capabilites are ``` CapabilityBoundingSet=CAP_DAC_READ_SEARCH CAP_NET_RAW CAP_SETUID CAP_SETGID ``` ~~EDIT2: A different path (besides repo-specific files?) would be better to allow multiple dates for multiple repos.~~ EDIT3: If borgmatic could evaluate its own `{repository}`, it would allow to easily store something (such as the datetime of the last successful backup) alongside the local repo files, e.g. in `/root/{repository}`. Currently this path needs to be set manually inside the `config.yaml`, because {repository} is not evaluated in a script called from the `after_backup` hook.
Author

A workaround is here.

A workaround is [here](https://projects.torsion.org/lasimik/borgmatic_notifications/src/branch/master/Readme.md).
Owner

Sorry again for the delay here. My take is that such an example is outside the scope of the borgmatic docs, given how different notifications would have to be for different Linux systems. I know that notify-send in particular can be pretty finnicky. But it looks like you've done a fair amount of work documenting how to get it working on your system, which is great!

And as mentioned in #420, the {respository} variable in action hook commands now works.

Sorry again for the delay here. My take is that such an example is outside the scope of the borgmatic docs, given how different notifications would have to be for different Linux systems. I know that `notify-send` in particular can be pretty finnicky. But it looks like you've done a fair amount of work documenting how to get it working on your system, which is great! And as mentioned in #420, the `{respository}` variable in action hook commands now works.
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#416
No description provided.