Documentation

systemd timer

Success and failure reporting handled by systemd itself.

systemd has something cron lacks: ExecStopPost knows how the run ended. That lets you report both success and failure without touching the script itself.

backup.service
[Unit]
Description=Ночной бэкап

[Service]
Type=oneshot
Environment=PING=https://ping.tickwatch.dev/YOUR-KEY
ExecStartPre=-/usr/bin/curl -fsS -m 10 --retry 3 ${PING}/start
ExecStart=/usr/local/bin/backup.sh
ExecStopPost=-/bin/sh -c 'if [ "$SERVICE_RESULT" = success ]; then \
  curl -fsS -m 10 --retry 3 "${PING}"; \
else \
  journalctl -u backup.service -n 50 --no-pager | \
    curl -fsS -m 10 --retry 3 --data-binary @- "${PING}/fail"; \
fi'

systemd sets SERVICE_RESULT and EXIT_STATUS itself — there is nothing to compute.

The leading dash in ExecStartPre and ExecStopPost is required: without it a network hiccup turns a healthy job into a failed one. Monitoring must not break what it monitors.

backup.timer
[Unit]
Description=Ночной бэкап по расписанию

[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true

[Install]
WantedBy=timers.target
systemd timer · Tickwatch