| Option | Description |
|---|---|
OnCalendar | Defines a real-time schedule for the timer (e.g., daily, weekly). |
OnBootSec | Specifies a delay after system boot before the timer activates. |
OnUnitActiveSec | Sets a timer based on the last activation of the associated service. |
OnUnitInactiveSec | Triggers the timer based on the last deactivation of the associated service. |
Persistent | Ensures the timer runs immediately if the system was off during the scheduled time. |
To create a timer, you need two files: a service file and a timer file. For instance, to run a backup script daily at 1 AM, you would create:
Backup Service File (/etc/systemd/system/backup.service):
[Unit] Description=Daily Backup Service [Service] ExecStart=/path/to/backup.sh Type=oneshot
Backup Timer File (/etc/systemd/system/backup.timer):
[Unit] Description=Daily Backup Timer [Timer] OnCalendar=*-*-* 01:00:00 Persistent=true [Install] WantedBy=timers.target