What I’m trying to do and why
To prevent my Mac from sleeping while a long
borgmatic operation is running, I run it with the
caffeinate -i borgmatic
I’d like to integrate this into my
borgmatic configuration so that I can’t forget to use
caffeinate and have backups unexpectedly terminated.
after_everything seems like the right way to go about this, but to do so, I’d need either:
- A way for the
before_everythingcommand to access the PID of
borgmaticto pass to
caffeinate -w [PID], which waits for the given process to terminate and then stops
- A way to pass state (the PID of caffeinate) from
after_everythingin order to kill
Another option would be doing just this:
before_everything: - caffeinate -i after_everything: - killall caffeinate
While this should work for my case, it’s not ideal: if a user is
caffeinateing their computer for other reasons, a
borgmatic run shouldn’t interfere with that.
Another issue with any of these solutions is that they will only run if a
create command is present since
before_everything only runs under those circumstances. Ideally, a
borgmatic prune ought to run under
Other notes / implementation ideas
If there’s an optimial method, it might be worth adding to the documentation.
Possibly add a “
before_absolutely_everything” hook that is not specific to
create commands? I’m sure a better name could be found.