Detect Backup File Missing: Verify Backup Files Exist
Your backup job completes successfully, but the backup file is missing. Learn how to detect missing backup files automatically.
Why Backup Files Can Be Missing
Backup files can be missing even when jobs complete:
- Backup script fails before creating file
- File permissions prevent file creation
- Disk space runs out during backup
- Backup script writes to wrong location
- File gets deleted immediately after creation
- Network issues prevent remote file creation
Without checking file existence, you might think backups are working when files don't exist.
How to Detect Missing Files
Always verify backup file exists after backup creation. Check file existence immediately after the backup command completes. The check must be inside your backup script.
Bash Example: Verify File Exists
#!/bin/bashBACKUP_FILE="/backups/db-$(date +%Y%m%d).sql.gz"pg_dump mydb | gzip > "$BACKUP_FILE"# Get file dataFILE_EXISTS=0FILE_SIZE=0if [ -f "$BACKUP_FILE" ]; then FILE_EXISTS=1 FILE_SIZE=$(stat -f%z "$BACKUP_FILE" 2>/dev/null || stat -c%s "$BACKUP_FILE")fi# Single ping with file data in payload# In DeadManPing panel: set validation rules:# - "file_exists" == 1# - "size" > 0# Panel will automatically detect if file is missing or emptycurl -X POST "https://deadmanping.com/api/ping/backup-daily?file_exists=$FILE_EXISTS&size=$FILE_SIZE"Python Example: Check File Existence
import osimport 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 file datafile_exists = os.path.exists(backup_file)file_size = os.path.getsize(backup_file) if file_exists else 0# Single ping with file data in payload# In DeadManPing panel: set validation rules:# - "file_exists" == True# - "size" > 0# Panel will automatically detect if file is missing or emptyrequests.post(f"https://deadmanping.com/api/ping/backup-daily?file_exists={file_exists}&size={file_size}")Monitoring Missing Backup Files
After adding file existence checks to your backup script, use a dead man switch to monitor whether the check completed successfully. If your script detects a missing file and exits with error code, the ping never arrives, and you get an alert.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Detecting Missing Backup Files
DeadManPing monitors whether your backup file verification completes. Set up monitoring in 2 minutes, get alerts when backup files are missing.
Start Monitoring FreeRelated Articles
Learn more about cron job monitoring and troubleshooting:
Backup Monitoring Service
Backup monitoring that doesn't touch your execution.
Detect Empty Backup File
How to detect when backup files are empty or zero bytes.
Verify Backup File Size
How to verify backup file sizes are within expected ranges.
Dead Man Switch for Backups
Implement dead man switch monitoring for backup jobs.