Add DB Backup to Maintenance
Added the possibility to perform a backup of the database. This creates a "pending" backup (a copy of the database) and from it an archive with the current date. The "pending" backup is overwritten with the next backup. The status information on the maintenance page has been supplemented accordingly.
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
$pia_db = str_replace('front', 'db', getcwd()).'/pialert.db';
|
$pia_db = str_replace('front', 'db', getcwd()).'/pialert.db';
|
||||||
//echo $pia_db;
|
//echo $pia_db;
|
||||||
$pia_db_size = number_format(filesize($pia_db),2,",",".") . ' Byte';
|
$pia_db_size = number_format(filesize($pia_db),0,",",".") . ' Byte';
|
||||||
//echo $pia_db_size;
|
//echo $pia_db_size;
|
||||||
$pia_db_mod = date ("F d Y H:i:s", filemtime($pia_db));
|
$pia_db_mod = date ("F d Y H:i:s", filemtime($pia_db));
|
||||||
|
|
||||||
@@ -47,6 +47,14 @@ $execstring = 'ps -f -u pi | grep "nmap" 2>&1';
|
|||||||
$pia_nmapscans = "";
|
$pia_nmapscans = "";
|
||||||
exec($execstring, $pia_nmapscans);
|
exec($execstring, $pia_nmapscans);
|
||||||
|
|
||||||
|
$Pia_Archive_Path = "/home/pi/pialert/db/";
|
||||||
|
$Pia_Archive_count = 0;
|
||||||
|
$files = glob($Pia_Archive_Path . "*.zip");
|
||||||
|
if ($files){
|
||||||
|
$Pia_Archive_count = count($files);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="table">
|
<div class="table">
|
||||||
@@ -62,13 +70,17 @@ exec($execstring, $pia_nmapscans);
|
|||||||
<div class="table-cell">last Modification</div>
|
<div class="table-cell">last Modification</div>
|
||||||
<div class="table-cell"><?php echo $pia_db_mod;?></div>
|
<div class="table-cell"><?php echo $pia_db_mod;?></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="table-row">
|
||||||
|
<div class="table-cell">DB Backup</div>
|
||||||
|
<div class="table-cell"><?php echo $Pia_Archive_count.' Backups where found';?></div>
|
||||||
|
</div>
|
||||||
<div class="table-row">
|
<div class="table-row">
|
||||||
<div class="table-cell">Scan Status (arp)</div>
|
<div class="table-cell">Scan Status (arp)</div>
|
||||||
<div class="table-cell"><?php echo sizeof($pia_arpscans);?> Scans currently running</div>
|
<div class="table-cell"><?php echo sizeof($pia_arpscans);?> scan(s) currently running</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-row">
|
<div class="table-row">
|
||||||
<div class="table-cell">Scan Status (nmap)</div>
|
<div class="table-cell">Scan Status (nmap)</div>
|
||||||
<div class="table-cell"><?php echo sizeof($pia_nmapscans);?> Scans currently running</div>
|
<div class="table-cell"><?php echo sizeof($pia_nmapscans);?> scan(s) currently running</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -83,6 +95,8 @@ exec($execstring, $pia_nmapscans);
|
|||||||
|
|
||||||
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnDeleteEvents" style="border-top: solid 3px #dd4b39;" onclick="askDeleteEvents()">Delete all Events (Reset Presence)</button>
|
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnDeleteEvents" style="border-top: solid 3px #dd4b39;" onclick="askDeleteEvents()">Delete all Events (Reset Presence)</button>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-default pa-btn pa-btn-delete bg-red dbtools-button" id="btnPiaBackupDBtoArchive" style="border-top: solid 3px #dd4b39;" onclick="askPiaBackupDBtoArchive()">Execute DB Backup</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ----------------------------------------------------------------------- -->
|
<!-- ----------------------------------------------------------------------- -->
|
||||||
@@ -168,6 +182,22 @@ function deleteEvents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Backup DB to Archive
|
||||||
|
function askPiaBackupDBtoArchive () {
|
||||||
|
// Ask
|
||||||
|
showModalWarning('DB Backup', 'Are you sure you want to exectute the the DB Backup? Be sure that no scan is currently running.',
|
||||||
|
'Cancel', 'Run Backup', 'PiaBackupDBtoArchive');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function PiaBackupDBtoArchive()
|
||||||
|
{
|
||||||
|
// Execute
|
||||||
|
$.get('php/server/devices.php?action=PiaBackupDBtoArchive', function(msg) {
|
||||||
|
showMessage (msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
case 'runScan1min': runScan1min(); break;
|
case 'runScan1min': runScan1min(); break;
|
||||||
case 'deleteUnknownDevices': deleteUnknownDevices(); break;
|
case 'deleteUnknownDevices': deleteUnknownDevices(); break;
|
||||||
case 'deleteEvents': deleteEvents(); break;
|
case 'deleteEvents': deleteEvents(); break;
|
||||||
|
case 'PiaBackupDBtoArchive': PiaBackupDBtoArchive(); break;
|
||||||
|
|
||||||
|
|
||||||
case 'getDevicesTotals': getDevicesTotals(); break;
|
case 'getDevicesTotals': getDevicesTotals(); break;
|
||||||
@@ -260,7 +261,29 @@ function deleteEvents() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Backup DB to Archiv
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
function PiaBackupDBtoArchive() {
|
||||||
|
|
||||||
|
$file = '/home/pi/pialert/db/pialert.db';
|
||||||
|
$newfile = '/home/pi/pialert/db/pialert.db.backup';
|
||||||
|
|
||||||
|
if (!copy($file, $newfile)) {
|
||||||
|
echo "Test Function executed not successfully";
|
||||||
|
} else {
|
||||||
|
$Pia_Archive_Name = 'pialertdb_'.date("Ymd_his").'.zip';
|
||||||
|
$Pia_Archive_Path = '/home/pi/pialert/db/';
|
||||||
|
exec('zip -j '.$Pia_Archive_Path.$Pia_Archive_Name.' /home/pi/pialert/db/pialert.db', $output);
|
||||||
|
if (file_exists($Pia_Archive_Path.$Pia_Archive_Name)) {
|
||||||
|
echo 'Test Function executed successfully ('.$Pia_Archive_Name.')';
|
||||||
|
} else {
|
||||||
|
echo 'Test Function executed successfully';
|
||||||
|
}
|
||||||
|
// echo "Test Function executed successfully";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user