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

Re: Tarsnap fails with broken pipe in systemd timer unit



On 08.10.19 22:00, Colin Percival wrote:
On 2019-10-08 09:53, Simon Levermann wrote:
/usr/bin/tarsnap --list-archives | /bin/grep -q ${current_date}
[...]
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
The `grep -q` command exits as soon as it finds a matching line, breaking
the pipe which tarsnap's output is directed to.  Most programs exit silently
when this happens; tarsnap is paranoid and prints a warning before exiting
with a failure status.

Why your shell cares about tarsnap's exit code, I don't know; normal POSIX
shells ignore the exit codes from processes other than the last one in a
pipeline.  Maybe systemd launches bash with some weird "don't behave the way
that shells are supposed to behave" flags.

You can probably get what you want by replacing the above line with

( /usr/bin/tarsnap --list-archives 2>/dev/null || true ) | \
     /bin/grep -q ${current_date}

since that will silence the warnings and ignore the exit code.

Thank you. In the meantime, I "fixed" it by simply letting tarsnap attempt to create the backups again. Worst thing it can do is fail and report the failure. I'll try your fix the next time I'm logged into that system and see if it helps!