Monitor Synology and NAS scheduled tasks
The backup script on the NAS stopped weeks ago, and you found out when you needed the backup. NAS task schedulers only tell you about failures if you set up email and read it. A heartbeat check tells you instead: the script reports to Pingstack after it succeeds, and Pingstack alerts you when that report doesn’t arrive on time.
This recipe uses Synology DSM’s Task Scheduler. TrueNAS and Unraid work the same way; see the end of the page.
1. Create a heartbeat check that matches the schedule
Section titled “1. Create a heartbeat check that matches the schedule”Decide when the task runs, for example daily at 02:00.
Create a heartbeat check and set its
schedule to Cron with the equivalent expression (0 2 * * *), or an
Interval for tasks that repeat every few hours.
The NAS runs tasks in its own timezone, set in DSM under Control Panel › Regional Options. Choose the same timezone in Pingstack. See schedules and timezones.
Set a grace period longer than the task’s usual runtime. Large backups can take hours. Attach a notification group.
2. Save the ping URL on the NAS
Section titled “2. Save the ping URL on the NAS”Copy the location’s ping URL from the check in Pingstack. Over SSH, save it in
a file only the task’s user can read, for example in a scripts folder on
your volume:
mkdir -p /volume1/scriptsinstall -m 600 /dev/null /volume1/scripts/pingstack-backup.envread -rs URL && printf 'PINGSTACK_PING_URL=%s\n' "$URL" > /volume1/scripts/pingstack-backup.envread -rs waits for you to paste the URL without echoing it, then press
Enter. If you’d rather not use SSH, create the file in File Station and
restrict its permissions to the task’s user.
3. Write the script and schedule it
Section titled “3. Write the script and schedule it”Save the job as a script that reports only when it succeeds:
#!/bin/bashset -euo pipefailsource /volume1/scripts/pingstack-backup.env
rsync -a --delete /volume1/photos/ /volumeUSB1/usbshare/photos/
curl --fail --silent --show-error --max-time 10 --retry 3 \ "$PINGSTACK_PING_URL" > /dev/nullThen schedule it in DSM:
- Open Control Panel › Task Scheduler.
- Choose Create › Scheduled Task › User-defined script.
- On General, name the task and choose the user it runs as.
- On Schedule, set the same time as the check.
- On Task Settings, enter
bash /volume1/scripts/backup.shas the script.
set -euo pipefail stops the script at the first failure, so a failed copy
sends nothing and Pingstack alerts you when the deadline passes. If the USB
drive isn’t mounted, rsync fails and the script stops there.
4. Confirm the first report
Section titled “4. Confirm the first report”In Task Scheduler, select the task and choose Run. Open the check in Pingstack and confirm the location received a heartbeat and shows a next deadline.
Optional: report a number
Section titled “Optional: report a number”Send the size of what was copied as a numeric value, and set a below threshold so a backup of an empty or missing folder raises an alert:
SIZE_MB=$(du -sm /volumeUSB1/usbshare/photos | cut -f1)curl --fail --silent --show-error --max-time 10 --retry 3 \ --get --data-urlencode "value=$SIZE_MB" "$PINGSTACK_PING_URL" > /dev/nullTrueNAS and Unraid
Section titled “TrueNAS and Unraid”- TrueNAS SCALE: add the script under System › Advanced Settings › Cron Jobs, with the same schedule and the user to run it as.
- Unraid: install the User Scripts plugin, add the script, and set a custom cron schedule.
The script, the private file and the check are the same.
Built-in backup apps
Section titled “Built-in backup apps”Hyper Backup and similar apps don’t run a script when they finish. To watch them, schedule a script shortly after the backup that checks its result, or check the backup destination’s newest file date and report only when it’s recent.
Why a healthy task might still alert
Section titled “Why a healthy task might still alert”- NAS asleep or rebooting. A task that was due while the NAS was off doesn’t run late. That’s an alert worth getting.
- Timezone mismatch. The check and the NAS’s regional settings must agree.
- Slow backups. A backup that grows over time eventually outlasts the grace period. Lengthen it.
If alerts still don’t match what you expect, see troubleshooting monitoring.