-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_backup_file_missing.js
More file actions
31 lines (26 loc) · 1021 Bytes
/
detect_backup_file_missing.js
File metadata and controls
31 lines (26 loc) · 1021 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
29
30
31
#!/usr/bin/env node
/**
* Detect Backup File Missing
* Problem: Backup job completes but backup file is missing
* Solution: Verify backup file exists after backup creation
* Documentation: https://deadmanping.com/detect-backup-file-missing
*/
const fs = require('fs');
const { execSync } = require('child_process');
const https = require('https');
const MONITOR_ID = 'YOUR_MONITOR_ID'; // Replace with your actual monitor ID
const backupFile = '/backups/db-backup.sql.gz';
// Run backup
execSync('pg_dump mydb | gzip > ' + backupFile);
// Get file data
let fileExists = fs.existsSync(backupFile);
let fileSize = 0;
if (fileExists) {
fileSize = fs.statSync(backupFile).size;
}
// Always 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 empty
https.request(`https://deadmanping.com/api/ping/${MONITOR_ID}?file_exists=${fileExists}&size=${fileSize}`, { method: 'POST' }).end();