Best way to run Borgmatic with caffeinate
#338
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#338
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 thecaffeinate
utility:I'd like to integrate this into my
borgmatic
configuration so that I can't forget to usecaffeinate
and have backups unexpectedly terminated.before_everything
/after_everything
seems like the right way to go about this, but to do so, I'd need either:before_everything
command to access the PID ofborgmatic
to pass tocaffeinate -w [PID]
, which waits for the given process to terminate and then stopscaffeinate
.before_everything
toafter_everything
in order to killcaffeinate
inafter_everything
.Another option would be doing just this:
While this should work for my case, it's not ideal: if a user is
caffeinate
ing their computer for other reasons, aborgmatic
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 sincebefore_everything
only runs under those circumstances. Ideally, aborgmatic prune
ought to run undercaffeinate
too.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 tocreate
commands? I'm sure a better name could be found.Environment
macOS
Thank you for filing this! Interesting problem. The current way this is solved is in borgmatic's sample systemd configuration. The last line (
systemd-inhibit
specifically) takes out a lock that prevents shutdown.Given that you're on macOS, I'm guessing that you're using launchd. If so, there might be a way to do something comparable and take out a lock to prevent shutdown. Or are you only running borgmatic manually on the command-line?
In any case, if
caffeinate
is the right solution, I'll have to think through the hooks as you described.The great thing about
borgmatic
is that these are the only sorts of small issues I've been facing, so thank you.While I assume that you're right and there is some way to prevent sleep through
launchd
, I'm not seeing anything in the man page forlaunchd.plist
files. But more importantly, I'm runningborgmatic
manually in this case, so I would prefer to not be depdendent on a scheduledlaunchd
job.Late for the party… but maybe it helps someone:
If you can tolerate an icon in taskbar/menubar, have a look at amphetamine (Mac) or caffeinate-ng (Linux).
Well, it's been a while.. But here's an idea. Once borgmatic is already executing, it can't really run itself with a different program wrapping it. (I suppose it could try to re-run itself, but that sounds kind of fragile.) So how about borgmatic running Borg with caffeinate or whatever other program you want to wrap it with?
The obvious way to do that would be to specify a Borg local path in borgmatic's existing configuration file like:
Unfortunately this won't work as-is today, because borgmatic would look for an executable called
caffeinate borg
and try (and fail) to run that. But it would be a pretty simple change to make borgmatic realize that the executable to run is onlycaffeinate
andborg
is just a parameter to it.Does something like that sound like it would work for you? Assuming this is still a need.
I'm closing this ticket due to inactivity, but if this is still a need for anyone, please chime in and I'd be happy to reopen it.