Skip to content

Commit 1e99ca4

Browse files
added check for yesterdays sql-backup
1 parent e8c9b15 commit 1e99ca4

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

src/server/extension/monitoring-endpoint.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// GET /api/v1/plugin/extension/monitoring-endpoint/monitoring
22

33
const fs = require('fs');
4+
const path = require('path');
45
const https = require('https');
56

67
let info = {}
@@ -316,6 +317,52 @@ process.stdin.on('end', () => {
316317
});
317318
}
318319

320+
function checkSqlBackups() {
321+
return new Promise((resolve, reject) => {
322+
// check sqldumps
323+
const sqlBackupDir = '/fylr/files/sqlbackups/';
324+
325+
fs.readdir(sqlBackupDir, (err, files) => {
326+
if (err) {
327+
return resolve(false);
328+
}
329+
else {
330+
for (const file of files) {
331+
// get yesterdays-date
332+
let yesterday = new Date();
333+
yesterday.setDate(yesterday.getDate() - 1);
334+
335+
const year = yesterday.getFullYear();
336+
const month = String(yesterday.getMonth() + 1).padStart(2, '0');
337+
const day = String(yesterday.getDate()).padStart(2, '0');
338+
339+
yesterday = year + '-' + month + '-' + day;
340+
341+
const backupFile = files.find(file => file.endsWith('.pgdump') && file.includes(yesterday));
342+
343+
if (backupFile) {
344+
// Passende Log-Datei suchen
345+
const logFile = `${backupFile}.log`;
346+
if (files.includes(logFile)) {
347+
// Log-Datei lesen und prüfen
348+
const logPath = path.join(sqlBackupDir, logFile);
349+
const logContent = fs.readFileSync(logPath, 'utf8');
350+
if (logContent.includes('Backup completed successfully')) {
351+
return resolve(true);
352+
} else {
353+
return resolve(false);
354+
}
355+
} else {
356+
return resolve(false);
357+
}
358+
} else {
359+
return resolve(false);
360+
}
361+
};
362+
}
363+
});
364+
});
365+
}
319366

320367
async function fetchData() {
321368
const infoData = await Promise.all([
@@ -329,11 +376,16 @@ process.stdin.on('end', () => {
329376
getConfigFromInspectAPI(),
330377
getPoolStatsFromAPI(),
331378
getDiskUsageFromAPI(),
332-
getObjectTypeStatsFromAPI()
379+
getObjectTypeStatsFromAPI(),
380+
checkSqlBackups()
333381
]);
334382

335383
let configinfo = infoData[6];
336-
384+
385+
//////////////////////////////////////////////////////////////
386+
// check mysql-backups, a successfull backup from yesterday is wanted
387+
result.sqlbackups = infoData[11];
388+
337389
//////////////////////////////////////////////////////////////
338390
// email-configs
339391
result.email = {};

0 commit comments

Comments
 (0)