Systemd
systemd is a common service manager used by many Linux distributions. resticprofile can create systemd timer and service files.
The type of unit created depends on the schedule-permission setting:
| Permission | Unit location |
|---|---|
system | /etc/systemd/system/ |
user | /etc/systemd/system/ (with User= field set) |
user_logged_on | ~/.config/systemd/user/ |
systemd calendars
resticprofile uses the systemd OnCalendar format to schedule events.
Test systemd calendars with systemd-analyze. It will display the next trigger time:
First time schedule
When you schedule a profile with the schedule command, resticprofile will:
- Create the unit file (type notify)
- Create the timer file
- Run
systemctl daemon-reload(ifschedule-permissionis set tosystem) - Run
systemctl enable - Run
systemctl start
Priority and CPU scheduling
resticprofile allows you to set the nice value, CPU scheduling policy, and IO nice values for the systemd service. This works properly for resticprofile >= 0.29.0.
| systemd unit option | resticprofile option |
|---|---|
| CPUSchedulingPolicy | Set to idle if priority is background, otherwise defaults to standard policy |
| Nice | nice from global section |
| IOSchedulingClass | ionice-class from global section |
| IOSchedulingPriority | ionice-level from global section |
Note
When setting CPUSchedulingPolicy to idle (by setting priority to background), the backup might never execute if all your CPU cores are always busy.
Permission
Until version v0.30.0, the user permission was actually user_logged_on unless you activated lingering for the user.
This is now fixed:
| Permission | Type of unit | Without lingering | With lingering | Requires sudo to schedule |
|---|---|---|---|---|
| system | system service | can run any time | can run any time | yes |
| user | system service with User= field defined | can run any time | can run any time | yes |
| user_logged_on | user service | runs only when user is logged on | can run any time | no |
Tip
If you want to run backups as a regular user without root privileges at scheduling time, use permission: user_logged_on. To allow the schedule to run even when the user is not logged in, enable lingering for your user:
Run after the network is up
Setting the profile option schedule-after-network-online: true ensures scheduled services wait for a network connection before running. This is achieved with an After=network-online.target entry in the service.
systemd drop-in files
You can automatically populate *.conf.d drop-in files for profiles, allowing easy overrides of generated services without modifying service templates. For example:
Where 99-drop-in-example.conf is in the same directory as profiles.toml and with the contents
Generated with the following. See systemd credentials docs for more details. This allows using a TPM-backed encrypted password outside the resticprofile config.
How to change the default systemd unit and timer file using a template
By default, resticprofile automatically generates a systemd unit and timer.
You can create custom templates to add features (e.g., sending an email on failure).
The format is a Go template. Specify your custom unit and/or timer file in the global section of the configuration to apply it to all profiles:
Here are the defaults if you don’t specify your own. I recommend using them as a starting point for your templates.
Default unit file
Default timer file
Template variables
These are available for both the unit and timer templates:
- JobDescription string
- TimerDescription string
- WorkingDirectory string
- CommandLine string
- OnCalendar array of strings
- SystemdProfile string
- Nice integer
- Environment array of strings