Detect Empty Backup File Cron: Verify Your Backups Aren't Empty
Your cron backup job returns success, but the backup file is empty. Learn how to detect and prevent this silent failure.
The Problem: Empty Backup Files
A cron backup job can exit with success code (0) even when the backup file is empty. This happens when:
- Database connection fails silently, creating an empty dump file
- Disk space runs out mid-backup, leaving a zero-byte file
- Backup script errors are caught but not properly handled
- File permissions prevent writes, but the script doesn't check
- Network timeouts during remote backups create empty files
Without checking file size, you might think backups are working when they're actually failing silently.
Solution: Check File Size After Backup
Always verify backup file size after creation. The check must be inside your script, not in the cron line, because you need access to the file path and size.
Bash Example
#!/bin/bash
BACKUP_FILE="/backups/db-$(date +%Y%m%d).sql"
pg_dump mydb > "$BACKUP_FILE"
# Get file size
FILE_SIZE=$(stat -f%z "$BACKUP_FILE" 2>/dev/null || stat -c%s "$BACKUP_FILE" 2>/dev/null || echo 0)
# Single ping with file size in payload
# In DeadManPing panel: set validation rule "size" > 0 (or >= 1024 for minimum size)
# Panel will automatically detect if size is 0 or too small
curl -X POST "https://deadmanping.com/api/ping/backup-daily?size=$FILE_SIZE"Python Example
import os
import subprocess
import requests
from datetime import datetime
backup_file = f"/backups/db-{datetime.now().strftime('%Y%m%d')}.sql"
subprocess.run(["pg_dump", "mydb"], stdout=open(backup_file, "w"))
# Get file size
file_size = os.path.getsize(backup_file) if os.path.exists(backup_file) else 0
# Single ping with file size in payload
# In DeadManPing panel: set validation rule "size" > 0 (or >= 1024 for minimum size)
# Panel will automatically detect if size is 0 or too small
requests.post(f"https://deadmanping.com/api/ping/backup-daily?size={file_size}")Node.js Example
const fs = require('fs');
const { execSync } = require('child_process');
const https = require('https');
const backupFile = `/backups/db-${new Date().toISOString().split('T')[0].replace(/-/g, '')}.sql`;
execSync(`pg_dump mydb > ${backupFile}`);
// Get file size
let fileSize = 0;
try {
fileSize = fs.statSync(backupFile).size;
} catch (e) {
// File doesn't exist
}
// Single ping with file size in payload
// In DeadManPing panel: set validation rule "size" > 0 (or >= 1024 for minimum size)
// Panel will automatically detect if size is 0 or too small
https.request(`https://deadmanping.com/api/ping/backup-daily?size=${fileSize}`, { method: 'POST' }).end();Monitoring Empty Backup Files
After adding file size checks to your backup script, use a dead man switch to monitor whether the check completed successfully. If your script detects an empty file and exits with error code, the ping never arrives, and you get an alert.
Include the file size in your ping payload so you can track backup sizes over time and detect gradual decreases that might indicate problems.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Monitoring Backup File Sizes
DeadManPing monitors whether your backup verification completes. Set up monitoring in 2 minutes, get alerts when backups are empty or too small.
Start Monitoring FreeRelated Articles
Learn more about cron job monitoring and troubleshooting:
Detect Empty Backup File
How to detect when backup files are empty or zero bytes.
Backup File Zero Bytes
How to detect when backup files are zero bytes.
Backup Monitoring Service
Backup monitoring that doesn't touch your execution.
Verify Backup File Size
How to verify backup file sizes are within expected ranges.