-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_empty_backup_file.py
More file actions
28 lines (23 loc) · 986 Bytes
/
detect_empty_backup_file.py
File metadata and controls
28 lines (23 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
"""
Detect Empty Backup File
Problem: Backup file is created but is zero bytes
Solution: Send file size in payload, validate in DeadManPing panel
Documentation: https://deadmanping.com/detect-empty-backup-file
"""
import os
import subprocess
import requests
MONITOR_ID = "YOUR_MONITOR_ID" # Replace with your actual monitor ID
backup_file = "/backups/db-backup.sql.gz"
# Run backup
subprocess.run(["pg_dump", "mydb"], stdout=open(backup_file.replace('.gz', ''), "w"))
subprocess.run(["gzip", backup_file.replace('.gz', '')])
# Get file size (0 if file doesn't exist)
file_size = os.path.getsize(backup_file) if os.path.exists(backup_file) else 0
# Always ping with file size in payload
# In DeadManPing panel: set validation rules:
# - "size" > 0 (to detect empty files)
# - "size" >= 1024 (minimum size, optional)
# Panel will automatically detect if size violates rules
requests.post(f"https://deadmanping.com/api/ping/{MONITOR_ID}?size={file_size}")