You are not logged in.
Hi all,
I'm trying to make automatic backups with the help of systemd and borg to an external USB drive every time I initiate a system shutdown.
I have created and modified several times a systemd service (/etc/systemd/system/backup.service):
[Unit]
Description=backup
RequiresMountsFor=/home /mnt/backups
Before=shutdown.target reboot.target
Conflicts=reboot.target
[Service]
Type=simple
ExecStart=/bin/true
ExecStop=/usr/bin/borgmatic
RemainAfterExit=true
[Install]
WantedBy=multi-user.targetbut it doesn't work! After I initiate a system shutdown the system powers off without making any backup!
Any ideas how can I make it work?
Offline
Is the service running before you shutdown?
Does "ExecStop=/usr/bin/echo foo > /home/bar" leave a trace?
Offline
@seth: Thanks. I was able to find out what is going on by using:
$ journalctl -u <myservice>Now I have two other minor problems:
1. The backup runs even on reboot which is annoying since the backup process can take over 30 min. How can I force systemd to run myservice only on shutdown? (Before=shutdown.target doesn't help)
2. During shutdown, when tty1 appears there is no message that myservice has started. Is there a way to get some info about the progress or status of the service? (StandardOutput=tty and StandardError=tty do not help)
This is my current service configuration:
[Unit]
Description=backup
RequiresMountsFor=/home /mnt/backups
Before=shutdown.target
[Service]
TimeoutStartSec=0
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/bin/borgmatic --verbosity 2
RemainAfterExit=true
User=user
Group=user
StandardOutput=tty
StandardError=tty
TimeoutSec=infinity
KillMode=none
SendSIGKILL=no
[Install]
WantedBy=multi-user.targetOffline
"Conflicts=reboot.target"?
Try kmesg as output.
Offline
Sorry for the late response.
The option:
Conflicts=reboot.targetdidn't help. It was just throwing me to a tty before shutting down without any message and after at least half an hour the system was restarting without making a backup.
I have tried some other options but I was in the same situation, namely either restart and backup or restart and wait for nothing.
Finally I gave up making experiments because I couldn't work.
If someone has a solution that works for sure I would be glad to hear it.
The option:
StandardOutput=kmsgseem to be working fine.
Offline