Schedule backups with different triggers (systemd) and parameter? #496
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#496
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
I setup a borgmatic configuration with per-application configuration and use
systemd
timer units to trigger the backup. I would like to manage different time slots for specific backup configuration.First scenario
Create user home backup archive every hour but database backup only every four hours.
Second scenario
Running
borgmatic prune
only once a day in opposite toborgmatic create
every hour.Thrid scenario
Combination of the scenarios above.
Is there any best practice available to handle these kind of scenarios using
systemd
.Environment
borgmatic version: 1.5.21
borgmatic installation method: Fedora dnf package
Borg version: 1.1.17
Python version: 3.10.2
Database version (if applicable): n/a
operating system and version: Linux 5.16.5-200.fc35.x86_64
Great question!
borgmatic
has an optional--config
flag that allows you to specify a particular per-application configuration file to use instead of picking up all application config files. Something like:borgmatic --config /etc/borgmatic.d/myapp.yaml
(And if you only ever invoke them separately like that, they wouldn't have to reside in
/etc/borgmatic.d
.)So with that approach, you could create separate pairs of systemd services and timers, one per application you want backed up. Each service could invoke borgmatic with a separate config file via
--config
.As for your second/third scenarios, a similar setup could work: One systemd service file and timer that invokes
borgmatic prune
at your desired schedule. And then addcreate
(and optionallycheck
) to the borgmatic command-line for each individual application above so thatprune
isn't run for them.If you want to run
prune
per-application as well (for instance if you're using separate archive prefixes per-application), then you could make separateprune
services/timers per application as well, although that might get a bit onerous.Please let me know if this helps for your use cases!
Thanks for your proposal and ideas. I have started to experiment with systemd template file. I took the
borgmatic.service
andborgmatic.timer
files, rename it intoborgmatic@.service
andborgmatic@.timer
to enable different timer for specific commands. For exampleborgmatic@create.timer
to create a new backup archive using the defined configuration.This works well and reduce the among of systemd unit files. Taken your thoughts I will try to extend my first steps and will keep you informed.
But it has one big pitfall. The dependency between the scheduled service files and backup repository. In some circumstances (e.g. overlapping timer schedules) and using the same repository it can provoke a locking issue.
Maybe you have a good idea to handle it. I am not a systemd or borg expert, maybe it is possible to define circular dependencies between each unit definitions to prevent parallel started services.
I'm not a systemd expert by any means, but my understanding is that you can chain systemd services via dependencies, specifically by the
Wants
options. This might also mean that you'd only need a single timer per chain of dependent services. Additionally, there areBefore
andAfter
options that may allow you to sequence service runs to avoid lock contention on a common repository.Hope this helps. I'll close the ticket for now, but feel free to post additional thoughts here.