Living Your Best Life With SystemD Timers


Here is a simple SystemD timer which implements a backup for your trusty Fedora laptop.

There are two files involved as shown below. It’s necessary that fedorabackup.service and fedorabackup.timer have the same name before their .{service,timer} suffixes.

File #1: /etc/systemd/system/fedorabackup.timer.

Description=fedora backup job

OnCalendar=*-*-* *:00:00


File #2: /etc/systemd/system/fedorabackup.service.

Description=fedora backup service

ExecStart=/usr/bin/bash /home/janie/.local/bin/backup

The contents of /home/janie/.local/bin/backup are as follows- notice the -e argument I had to pass to rsync to get it to work.

/usr/bin/rsync -av -e '/usr/bin/ssh -i /home/janie/.ssh/id_ed25519' \
        --exclude Downloads \
        /home/janie/ janie@

Finally, enable the service with sudo systemctl enable fedorabackup.timer and sudo systemctl start fedorabackup.timer.

End result

We end up with a job which executes our fedorabackup.sh script every hour on the hour.

This is quicker to do with cron, but our friend SystemD timers give us the following improvements over cron:

SELinux considerations

Compare the labels of your files /etc/systemd/system/fedorabackup.{service,timer} to other files in their directory per usual.

I had to use setsebool to enable the SELinux booleans rsync_client and rsync_export_all_ro to get rsync to work in this setup.