I am currently trying to set up automated backups using borg. For that, I have written a oneshot systemd user service (called borgbackup.service) that I am planning to start via a timer.
Borg can also mount a backup repository as a virtual file system and I would like to keep my backups mounted at all times. I have written another user service for that which I called borgmount.service. However, it is impossible to create backups while the repository is mounted.
My current solution to this problem consists of these lines in my borgbackup.service to stop and restart the mounting service before and after the backup.
ExecStartPre=/usr/bin/systemctl --user stop borgmount.service ExitStart=/bin/sh -c "borg create ::$(date) --exclude-caches --keep-tag-files" ExecStopPost=/usr/bin/systemctl --user start borgmount.service
This seems very ugly and does not take into account the state that the borgmount.service unit was in when the backup was started (maybe it was stopped and disabled).
Is there a better way to do this?