adding automatic backups
This commit is contained in:
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
//this file does only house functions and does not have a ui
|
||||||
|
|
||||||
|
function create_log_backup($conn){ //the $conn is the linker variable to the db server
|
||||||
|
//create a filename
|
||||||
|
$filename="log_export_".date('Y-m-d H:i:s').".csv";
|
||||||
|
|
||||||
|
$fp=fopen("/var/www/html/backup/$filename","w");
|
||||||
|
//do all the logic here and write into file
|
||||||
|
// Query log entries for the export file
|
||||||
|
$sql = "SELECT * FROM machines,log WHERE machine_name=machine_id ORDER BY log.id DESC";
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
fwrite ($fp,"Entry id;Loglevel;Logtext;Machine id;Machine Location;Time & date\n");
|
||||||
|
//now add entrys
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
fwrite($fp,$row["id"] . ';');
|
||||||
|
fwrite($fp,$row["loglevel"] . ';');
|
||||||
|
fwrite($fp,$row["logtext"] . ';');
|
||||||
|
fwrite($fp,$row["machine_id"] . ';');
|
||||||
|
fwrite($fp,$row["machine_location"] . ';');
|
||||||
|
fwrite($fp,$row["time"] . ";\n");
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_dashboard_backup($conn){
|
||||||
|
//create a filename
|
||||||
|
$filename="dashboard_export_".date('Y-m-d H:i:s').".csv";
|
||||||
|
|
||||||
|
$fp=fopen("/var/www/html/backup/$filename","w");
|
||||||
|
//do all the logic here and write into file
|
||||||
|
// Query log entries for the export file
|
||||||
|
$sql = "SELECT * FROM machines,vir_notify WHERE machine_name=machine_id ORDER BY vir_notify.id DESC";
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
fwrite ($fp,"Entry id;Machine id;Machine Location;Path;Hash;Action taken\n");
|
||||||
|
//now add entrys
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
fwrite($fp,$row["id"] . ';');
|
||||||
|
fwrite($fp,$row["machine_id"] . ';');
|
||||||
|
fwrite($fp,$row["machine_location"] . ';');
|
||||||
|
fwrite($fp,$row["path"] . ';');
|
||||||
|
fwrite($fp,$row["hash"] . ';');
|
||||||
|
fwrite($fp,$row["action"] . ";\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($fp);
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -19,7 +19,7 @@ $hash = htmlspecialchars(isset($_GET["hash"]) ? $_GET["hash"] : "");
|
|||||||
$action = htmlspecialchars(isset($_GET["action"]) ? $_GET["action"] : "");
|
$action = htmlspecialchars(isset($_GET["action"]) ? $_GET["action"] : "");
|
||||||
$machine_location = htmlspecialchars(isset($_GET["machine_location"]) ? $_GET["machine_location"] : "");
|
$machine_location = htmlspecialchars(isset($_GET["machine_location"]) ? $_GET["machine_location"] : "");
|
||||||
$filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&machine_location=$machine_location";
|
$filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&machine_location=$machine_location";
|
||||||
|
include "create_log_backup.php";
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@@ -56,6 +56,7 @@ $filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&ma
|
|||||||
if ($conn->connect_error) {
|
if ($conn->connect_error) {
|
||||||
die("Connection failed: " . $conn->connect_error);
|
die("Connection failed: " . $conn->connect_error);
|
||||||
}
|
}
|
||||||
|
create_dashboard_backup($conn);
|
||||||
$sql = "DELETE FROM vir_notify WHERE id = ?";
|
$sql = "DELETE FROM vir_notify WHERE id = ?";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->bind_param("i", $id);
|
$stmt->bind_param("i", $id);
|
||||||
@@ -78,6 +79,7 @@ $filter_query = "&hash=$hash&path=$path&machine_id=$machine_id&action=$action&ma
|
|||||||
if ($conn->connect_error) {
|
if ($conn->connect_error) {
|
||||||
die("Connection failed: " . $conn->connect_error);
|
die("Connection failed: " . $conn->connect_error);
|
||||||
}
|
}
|
||||||
|
create_dashboard_backup($conn);
|
||||||
$sql = "DELETE FROM vir_notify";
|
$sql = "DELETE FROM vir_notify";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
// Execute the statement
|
// Execute the statement
|
||||||
|
|||||||
Reference in New Issue
Block a user