Systemd timers configuration in Gentoo

Yesterday I configured backups with duplicity on a couple of servers using a 3rd party service,, as the backup destination; since I am a little paranoid with backups I also wanted to schedule a daily task on my computer at home to mirror the backups from that service to a local directory, just in case. I could have used cron for this but since I use Gentoo with systemd now I wanted to try systemd timers.

Cron does seem to be a lot easier to use, but there are some advantages to using systemd timers. For example – from what I have read/understood so far:

  • all the events are logged in the systemd journal, so you can easily check for example when a timer last ran and if the task was successful – this is very helpful when debugging;
  • systemd timers are basically services, and as such they are more flexible than cron jobs; among other things you can specify IO scheduling priority, niceness, timeouts, etc. (see this);
  • a timer can be triggered in various ways, even -for example- by hardware state changes;
  • a timer can be configured to depend on another service, for example to mount some remote filesystem before executing the scheduled task.

Configuring systemd timers

So here’s how to configure a simple timer with systemd. In this example I want to mirror a remote directory to a local directory daily at 4am. For starters, you need to create a .timer file under /etc/systemd/system which looks like this:

You also need to create a second file with same name but with .service extension in the same location:

To have systemd pick up these files you need to run:

Then, to enable the scheduled task now and at startup:

To list the timers:

To trigger the task manually:

To check the log for the task status:

Or you can check the status of both the timer and the service directly:

These are just the basics for a daily task which runs at a given time, but systemd timers are really flexible and powerful, I’d suggest you check the man pages for more info.


About the author

Vito Botta

I am a passionate web developer based in Espoo, Finland. Besides computing, I love boxing and good food!

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen + five =