I wanted to be able to take backups when my computers are asleep at night, because that’s the most reliable time for me. It’s on my network, I’m not using them, I’m sure no one will disconnect the laptop to bring it outside, etc.
So after some research in documentations, I ended up with the following /etc/systemd/system/restic-backup.service
[Unit]
Description=Restic backup service
After=sleep.target
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 15
ExecStart=/bin/systemd-inhibit --why="restic-backup" restic -r sftp:xxx@yyy:restic --no-scan --verbose backup --exclude-caches --exclude=/home/.snapshots/ --tag systemd.timer /etc /home
Environment=RESTIC_PASSWORD="restic_repo_password"
Environment=HOME=/root
and /etc/systemd/system/restic-backup.timer
[Unit]
Description=Backup with restic daily
[Timer]
OnCalendar=Mon-Sun 04:00
WakeSystem=true
[Install]
WantedBy=timers.target
Then, one simply has to enable the timer with systemctl enable restic-backup.timer and check that it’s loaded :
tour:/etc/systemd/system$ sudo systemctl list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
[...]
Wed 2025-08-20 04:00:00 CEST 12h Tue 2025-08-19 04:00:32 CEST 3h 38min ago restic-backup.timer restic-backup.service
[...]
7 timers listed.
One possibility is to add the Peristent=trueentry in the [Timer]section of the timer file if you want the backup to always occur. For example, if for some reason it has been impossible to wakeup the computer. Without Peristent option, if the backup is skipped, it will be triggered the next time the trigger time is met.
systemd-inhibit is used so that no suspend/hibernate action can prevent the backup to complete. That’s useful if the backup takes a long time and the computer goes to sleep fast.
I had to add a 15s sleep before starting the backup, otherwise my network wasn’t properly working, no DNS resolution in my case. There has to be a proper way to achieve that, but I tried a lot of different network,nss-lookup,network-online targets, but nothing works.
One last interesting option if your backup take quite some time is to add ConditionACPower=true if you’re on a laptop, so that it won’t run out of battery if you forgot to plug it in. That goes in the [Unit] section.