Verify Backup File Size: Ensure Backups Are Complete
Your backup completes, but is the file size reasonable? Learn how to verify backup file sizes and detect when backups are too small or suspiciously large.
Why File Size Matters
Backup file sizes can indicate problems:
- Too small - Backup might be empty or incomplete
- Too large - Backup might include unnecessary data or be corrupted
- Unexpected change - Sudden size changes might indicate data loss or corruption
- Zero bytes - Backup definitely failed
- Much smaller than previous - Data might be missing
Checking file size helps catch backup failures that exit codes miss.
How to Verify File Size
Check file size after backup creation. Compare against minimum expected size, maximum expected size, or previous backup sizes. The check must be inside your backup script, not in the cron line.
Bash Example: Check Minimum and Maximum Size
#!/bin/bashBACKUP_FILE="/backups/db-$(date +%Y%m%d).sql.gz"MIN_SIZE=1048576 # 1MB minimumMAX_SIZE=10737418240 # 10GB maximumpg_dump mydb | gzip > "$BACKUP_FILE"# Get file sizeFILE_SIZE=$(stat -f%z "$BACKUP_FILE" 2>/dev/null || stat -c%s "$BACKUP_FILE")# Single ping with file size in payload# In DeadManPing panel: set validation rules:# - "size" >= 1048576 (1MB minimum)# - "size" <= 10737418240 (10GB maximum)# Panel will automatically detect if size is outside rangecurl -X POST "https://deadmanping.com/api/ping/backup-daily?size=$FILE_SIZE"Python Example: Compare with Previous Backup
import osimport globimport subprocessimport requestsbackup_file = "/backups/db-backup.sql.gz"subprocess.run(["pg_dump", "mydb"], stdout=open(backup_file.replace('.gz', ''), "w"))subprocess.run(["gzip", backup_file.replace('.gz', '')])# Get current file sizecurrent_size = os.path.getsize(backup_file)# Find previous backupprevious_backups = sorted(glob.glob("/backups/db-*.sql.gz"), reverse=True)if len(previous_backups) > 1: previous_size = os.path.getsize(previous_backups[1]) # Single ping with file size in payload# In DeadManPing panel: set validation rules:# - "size" >= 1048576 (1MB minimum)# - "size" <= 10737418240 (10GB maximum)# Panel will automatically detect if size is outside rangerequests.post(f"https://deadmanping.com/api/ping/backup-daily?size={current_size}")Node.js Example: Size Range Validation
const fs = require('fs');const { execSync } = require('child_process');const https = require('https');const backupFile = '/backups/db-backup.sql.gz';const MIN_SIZE = 1024 * 1024; // 1MBconst MAX_SIZE = 10 * 1024 * 1024 * 1024; // 10GBexecSync(`pg_dump mydb | gzip > ${backupFile}`);// Get file sizeconst stats = fs.statSync(backupFile);// Single ping with file size in payload// In DeadManPing panel: set validation rules:// - "size" >= 1048576 (1MB minimum)// - "size" <= 10737418240 (10GB maximum)// Panel will automatically detect if size is outside rangehttps.request(`https://deadmanping.com/api/ping/backup-daily?size=${stats.size}`, { method: 'POST' }).end();Monitoring Backup File Sizes
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 invalid file size and exits with error code, the ping never arrives, and you get an alert.
Include file sizes in your ping payload so you can track backup sizes over time and detect gradual changes that might indicate problems.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Verifying Backup File Sizes
DeadManPing monitors whether your backup file size verification completes. Set up monitoring in 2 minutes, get alerts when backups are wrong size.
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.
Detect Backup File Missing
How to detect when backup files are missing after backup jobs complete.