[systemd-devel] Scheduling 3 periodic jobs using systemd

Dan Nicholson dbn at endlessos.org
Mon Jul 15 19:01:44 UTC 2024


FWIW, I had to implement a monthly/weekly/daily backup scheme a while
back and determined that the most reliable way to do it was to handle
it myself rather than trying to encode it all through systemd units.
The script does this basically:

#!/usr/bin/env python3

from datetime import datetime

now = datetime.now()

if now.day == 1:  # Monthly backups on the first of the month
    monthly_backup()
if now.weekday() == 6:  # Weekly backups on Sunday
    weekly_backup()
daily_backup()  # Always perform daily backups

This is triggered from a daily systemd timer.

--
Dan Nicholson  |  Endless OS Foundation

--
Dan Nicholson  |  Endless OS Foundation


On Fri, Jul 12, 2024 at 2:50 AM <t.schneider at disroot.org> wrote:
>
> There's no script (or whatsoever) in this backup functionality.
> It's only rsnapshot (https://wiki.archlinux.org/title/Rsnapshot) and systemd-timer involved.
>
>
> Am 2024-07-12 10:35, schrieb Barry Scott:
>
>
>
> On 12 Jul 2024, at 08:34, t.schneider at disroot.org wrote:
>
> Setting the time of day requires detailed knowledge about the runtime of each job.
>
> But this forecast is not accurate and this means any setting could result in same error.
>
> Agreed that is a problem with this approach.
>
> Or you have the code that locks wait for the lock to be freed does that help?
> Are you using flock in the script, then its a easy change.
>
> You still cannot ensure the order, but you can ensure that they will all run sequentially.
>
> Personally I encode the rules for my incremental vs. full backup into my hourly backups script.
> So I only have one timer.
>
> Barry
>


More information about the systemd-devel mailing list