Backup at shutdown

#1

Banging my head against the wall. Why doesn’t this Systemd service run?
I’m trying to run a user service , to backup my documents, before the desktop system shuts down every night.

`# Needs to be placed in ~/.config/systemd/user/
[Unit]
Description=Backup with restic before shutdown
Before=poweroff.target halt.target
After=networking.service

[Service]
Type=oneshot
ExecStart=/usr/bin/restic backup --verbose --one-file-system --tag systemd.shutdown $BACKUP_EXCLUDES $BACKUP_PATHS
ExecStartPost=/usr/bin/restic forget --verbose --tag systemd.shutdown --group-by paths,tags --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --keep-yearly $RETENTION_YEARS
EnvironmentFile=%h/.config/restic-backup.conf
RemainAfterExit=yes

[Install]
WantedBy=poweroff.target halt.target`

It runs if I start it manually: systemctl --user start restic-backup.service
It seems to enable fine: systemctl --user enable restic-backup.service
Returns:
Created symlink /home/lance/.config/systemd/user/poweroff.target.wants/restic-backup.service /home/lance/.config/systemd/user/restic-backup.service. Created symlink /home/lance/.config/systemd/user/halt.target.wants/restic-backup.service /home/lance/.config/systemd/user/restic-backup.service.

…but when I go to the desktop menu & shutdown, the script does not run, the computer just shuts down.

Anyone see what I’m missing?

#2

Yep. You can’t have dependencies on system level services in a user service file. Create/enable it as a system service but with the User= directive (if required).