Check that last night's backup exists and isn't empty
A nightly backup job that "succeeds" can still leave you with nothing to restore: a 0-byte dump, a file half the usual size, or a copy that never left the machine. You find out on the day you need it. A size check after every run tells you that last night's backup exists, isn't empty and isn't much smaller than usual.
How a backup can succeed and still be useless
Backup scripts are usually a chain: dump the database or zip the folder, then copy the file somewhere else. The scheduler sees the exit code of the chain, which is often the code of its last step. Common ways it goes wrong without an error:
- the dump tool wrote an empty file because the database login failed, and printed a warning instead of exiting with an error;
- the disk filled up halfway and the file was cut off;
- a filter or a changed path backed up an empty folder;
- the copy to the network share or the cloud failed, but the script ended with a successful clean-up step;
- the job didn't run at all, because the server was off or the task was disabled during maintenance.
On Linux, cron mails the output of a job only if the machine can send mail (cronie writes it to syslog otherwise), and a backup script that prints nothing sends nothing either way.
Send the file's size after the copy
The check is simple: after the file has been written and copied off the machine, send its size in bytes with the finishing ping. When you tick This is a backup on a job's Code tab, TaskBeacon watches that number with two rules: the size is below 1 byte, or it drops more than 40% below the recent backups. In Python:
# --- TaskBeacon: top of the script (standard library only) ---
import json, os, traceback, urllib.request
TB = "https://taskbeacon.io/ping/your-job-id"
BACKUP_FILE = r"D:\backups\sales.bak"
def tb_ping(path="", data=None):
body = json.dumps(data).encode() if data else None
req = urllib.request.Request(TB + path, data=body, headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req, timeout=10)
except Exception as e:
print("TaskBeacon ping failed:", e)
tb_ping("/start")
try:
# --- your code here ---
df = [1, 2, 3] # example data: replace with your own (e.g. pandas.read_csv)
# backup: its size, read after the file is uploaded or copied off this machine
tb_bytes = os.path.getsize(BACKUP_FILE)
except Exception as e:
# the error and the last 20 lines of the traceback go with the failure
tb_ping("/fail", {"error": f"{type(e).__name__}: {e}"[:200],
"log": "\n".join(traceback.format_exc().splitlines()[-20:])[-4000:]})
raise
# --- TaskBeacon: end of the script ---
tb_ping("", {"bytes": tb_bytes})In the app, the Code tab of your job gives you this code with the job's own address instead of your-job-id, and you can untick the parts you don't need.
Set BACKUP_FILE to the file you just created, and keep the tb_bytes line after the upload, not after the dump; otherwise a failed copy still reports success. The size is read inside the try, so a missing or unreadable file turns the run Failed, with the error. The same option exists in the cron line (using stat) and in Stata. If the size naturally grows or shrinks a lot, change the 40% on the job page.
What you get
- Odd data when the backup is empty or much smaller than usual, with the size and the usual size in the alert.
- Failed when the script raises an error, with the message, for example a
FileNotFoundErrorbecause the dump was never written. - Missed when no ping came by the planned time plus grace: the backup didn't run.
- Late when the backup started and is taking much longer than usual, which often means it is stuck on a network share.
A size check is not a restore test: a file of the right size can still be unusable. It does catch the most common silent failures every night, for free; test a restore now and then as well.
Without TaskBeacon
Add a step at the end of the backup script that checks the file exists and is larger than a fixed minimum, and exits with an error (and sends a mail) when it isn't. Many backup tools have a "verify" option and email reports; use them. What these don't give you is a comparison with the usual size, or an alert when the backup didn't run at all, which needs something outside the server that expects to hear from it; see heartbeat monitoring.
Connected Claude or ChatGPT to TaskBeacon? Ask it "what failed last night, and why?" and it answers from your jobs. How that works.
Related
In the Docs: Backup size · Python · Linux cron.
- Get an alert when a job loads 0 rows, or far fewer than usualExit code 0 says nothing about how many rows arrived.
- Heartbeat monitoring (a dead man's switch) for scheduled scriptsThe job checks in on every run; silence is the alert.
- Find out when a scheduled job didn't run at allA run that never happened leaves no error to alert on.
TaskBeacon is free to start, with every feature open for now and no credit card. Create a job, paste the code, and the first ping shows up on the job page.
Start free View live demoSources
- man7.org: cron(8), cronie (output is mailed; without sendmail it goes to syslog) (page 2013, matches upstream cronie 2026)
Page checked against its sources on 2026-11-09. Menus and limits of other products change; if something here no longer matches, write to support@taskbeacon.io.