Skip to content

Instantly share code, notes, and snippets.

@etskinner
Last active May 16, 2018 18:39
Show Gist options
  • Save etskinner/a6d109838f3674360b5c73e6bbd9ca3b to your computer and use it in GitHub Desktop.
Save etskinner/a6d109838f3674360b5c73e6bbd9ca3b to your computer and use it in GitHub Desktop.
rsnapshot systemd timers
# systemd list-timers
----------------------
NEXT LEFT LAST PASSED UNIT ACTIVATES
Sat 2016-05-14 21:00:00 EDT 2min 56s ago Sat 2016-05-14 21:00:00 EDT 2min 56s ago rsnapshot-hourly.timer [email protected]
Sat 2016-05-14 23:50:00 EDT 2h 47min left Fri 2016-05-13 23:50:00 EDT 21h ago rsnapshot-daily.timer [email protected]
...
Sun 2016-05-15 23:40:00 EDT 1 day 2h left n/a n/a rsnapshot-weekly.timer [email protected]
Sun 2016-06-05 23:30:00 EDT 3 weeks 1 days left n/a n/a rsnapshot-monthly.timer [email protected]
[email protected]
------------------
[Unit]
Description=rsnapshot (%I) backup
[Service]
Type=oneshot
Nice=19
IOSchedulingClass=3
ExecStart=/usr/bin/rsnapshot %I
rsnapshot-hourly.timer
----------------------
[Unit]
Description=rsnapshot hourly backup
[Timer]
OnCalendar=hourly
Persistent=true
[email protected]
[Install]
WantedBy=timers.target
rsnapshot-daily.timer
---------------------
[Unit]
Description=rsnapshot daily backup
[Timer]
OnCalendar=23:50
Persistent=true
[email protected]
[Install]
WantedBy=timers.target
rsnapshot-weekly.timer
----------------------
[Unit]
Description=rsnapshot weekly backup
[Timer]
OnCalendar=Sun, 23:40
Persistent=true
[email protected]
[Install]
WantedBy=timers.target
rsnapshot-monthly.timer
-----------------------
[Unit]
Description=rsnapshot monthly backup
[Timer]
OnCalendar=Sun *-*-1,2,3,4,5,6,7 23:30
Persistent=true
[email protected]
[Install]
WantedBy=timers.target
@opensiriusfox
Copy link

For anyone who comes across this as I did, I wanted to note something helpful for those duplicating your example.

Firstly, ranges were added at some point the last couple of years for date strings. So the monthly OnCalendar string can be reduced to the following: Sun *-*-1..7 23:30.

Personally, I fought with the OnCalendar spec to make things behave exactly as I wanted. There is a tool to ease testing of OnCalendar strings, systemd-analyze. For example, in testing a quarterly timer I can run the following:

$ systemd-analyze calendar "Sun *-1,4,7,10-1..7 23:01:00"
  Original form: Sun *-1,4,7,10-1..7 23:01:00
Normalized form: Sun *-01,04,07,10-01..07 23:01:00
    Next elapse: Sun 2018-07-01 23:01:00 PDT
       (in UTC): Mon 2018-07-02 06:01:00 UTC
       From now: 1 months 16 days left
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment