[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Tarsnap fails with broken pipe in systemd timer unit



Hi,

I'm trying to configure my daily tarsnap backup with a systemd timer unit, but running into an error that I can't really explain myself. I have a shell script that runs the actual backups, which looks like this:

#!/bin/bash

current_date=$(/bin/date +%F)

/usr/bin/tarsnap --list-archives | /bin/grep -q ${current_date}

GREP_RETURN=$?
if [[ $GREP_RETURN == 0 ]]; then
	echo "Archive for ${current_date} already exists. Not archiving again"
	exit 1
fi
/usr/bin/tarsnap -c --quiet -f "etc-hostname-${current_date}" /etc
/usr/bin/tarsnap -c --quiet -f "root-hostname-${current_date}" /root
/usr/bin/tarsnap -c --quiet -f "simon-hostname-${current_date}" /home/simon

When running that script on the command line directly, all is well, and it either creates the archives, or doesn't do so if they already existed. Now, I've added a systemd service file that should run this script, which looks like this:

[Unit]
Description=Run tarsnap backups
_OnFailure_=status-email-root@%n.service

[Service]
ExecStart=/root/tarsnap.sh
Type=oneshot
User=root

For testing services, I started this unit file once, but in the --list-archives step, tarsnap produces the following error:

● tarsnap-backup.service - Run tarsnap backups
   Loaded: loaded (/etc/systemd/system/tarsnap-backup.service; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2019-10-08 18:45:27 CEST; 6min ago
  Process: 17247 ExecStart=/root/tarsnap.sh (code=exited, status=1/FAILURE)
 Main PID: 17247 (code=exited, status=1/FAILURE)

Okt 08 18:45:26 slevermann.de systemd[1]: Starting Run tarsnap backups...
Okt 08 18:45:27 slevermann.de tarsnap.sh[17247]: tarsnap: fprintf: Broken pipe
Okt 08 18:45:27 slevermann.de tarsnap.sh[17247]: tarsnap: Error listing archives
Okt 08 18:45:27 slevermann.de tarsnap.sh[17247]: tarsnap: Error exit delayed from previous errors.
Okt 08 18:45:27 slevermann.de systemd[1]: tarsnap-backup.service: Main process exited, code=exited, status=1/FAILURE
Okt 08 18:45:27 slevermann.de systemd[1]: tarsnap-backup.service: Failed with result 'exit-code'.
Okt 08 18:45:27 slevermann.de systemd[1]: Failed to start Run tarsnap backups.
Okt 08 18:45:27 slevermann.de systemd[1]: tarsnap-backup.service: Triggering _OnFailure_= dependencies.

Does anyone have an idea why the script would execute correctly, but consistently fail inside the systemd service?

Regards, Simon