mirror of https://github.com/itflow-org/itflow
Operation Cleanup Round 3 - Remove automated SQL backups as this should be handled by system level backups which will also backup the files
This commit is contained in:
parent
6eb96df277
commit
2ea41ed960
73
cron.php
73
cron.php
|
|
@ -35,8 +35,6 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||
$config_mail_from_name = $row['config_mail_from_name'];
|
||||
$config_recurring_auto_send_invoice = $row['config_recurring_auto_send_invoice'];
|
||||
$config_base_url = $row['config_base_url'];
|
||||
$config_backup_enable = $row['config_backup_enable'];
|
||||
$config_backup_path = $row['config_backup_path'];
|
||||
|
||||
// Tickets
|
||||
$config_ticket_prefix = $row['config_ticket_prefix'];
|
||||
|
|
@ -50,77 +48,6 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Cron', log_action = 'Started', log_description = 'Cron started for $company_name', company_id = $company_id");
|
||||
|
||||
if($config_backup_enable == 1){
|
||||
// DATABASE BACKUP
|
||||
// This needs to be set to the full file system path or else when cron runs php it will break cron.php and cron will not run properly
|
||||
//$backup_dir = "backups/";
|
||||
$backup_dir = "$config_backup_path/";
|
||||
|
||||
// Get All Table Names From the Database
|
||||
$tables = array();
|
||||
$sql = "SHOW TABLES";
|
||||
$result = mysqli_query($mysqli, $sql);
|
||||
while ($row = mysqli_fetch_row($result)) {
|
||||
$tables[] = $row[0];
|
||||
}
|
||||
|
||||
$sqlScript = "";
|
||||
foreach ($tables as $table) {
|
||||
|
||||
// Prepare SQLscript for creating table structure
|
||||
$query = "SHOW CREATE TABLE $table";
|
||||
$result = mysqli_query($mysqli, $query);
|
||||
$row = mysqli_fetch_row($result);
|
||||
|
||||
$sqlScript .= "\n\n" . $row[1] . ";\n\n";
|
||||
|
||||
$query = "SELECT * FROM $table";
|
||||
$result = mysqli_query($mysqli, $query);
|
||||
|
||||
$columnCount = mysqli_num_fields($result);
|
||||
|
||||
// Prepare SQLscript for dumping data for each table
|
||||
for ($i = 0; $i < $columnCount; $i ++) {
|
||||
while ($row = mysqli_fetch_row($result)) {
|
||||
$sqlScript .= "INSERT INTO $table VALUES(";
|
||||
for ($j = 0; $j < $columnCount; $j ++) {
|
||||
|
||||
if (isset($row[$j])) {
|
||||
$sqlScript .= '"' . $row[$j] . '"';
|
||||
} else {
|
||||
$sqlScript .= '""';
|
||||
}
|
||||
if ($j < ($columnCount - 1)) {
|
||||
$sqlScript .= ',';
|
||||
}
|
||||
}
|
||||
$sqlScript .= ");\n";
|
||||
}
|
||||
}
|
||||
$sqlScript .= "\n";
|
||||
}
|
||||
|
||||
// Save the SQL script to a backup file
|
||||
if(!empty($sqlScript)) {
|
||||
$random_string = key32gen();
|
||||
if(!empty($random_string)){
|
||||
$backup_file_name = date('Y-m-d') . '_backup__' . $random_string . '.sql';
|
||||
$fileHandler = fopen($backup_dir . '/' .$backup_file_name, 'w+');
|
||||
$number_of_lines = fwrite($fileHandler, $sqlScript);
|
||||
fclose($fileHandler);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete backups older than 30 days
|
||||
$now = time();
|
||||
foreach (glob($backup_dir."*.sql") as $file) {
|
||||
if(time() - filectime($file) > 2592000){
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// GET NOTIFICATIONS
|
||||
|
||||
// DOMAINS EXPIRING
|
||||
|
|
|
|||
|
|
@ -300,18 +300,27 @@ if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){
|
|||
}
|
||||
|
||||
if(CURRENT_DATABASE_VERSION == '0.1.6'){
|
||||
// Insert queries here required to update to DB version 0.1.7
|
||||
// Insert queries here required to update to DB version 0.1.7
|
||||
//Remove custom links
|
||||
mysqli_query($mysqli, "DROP TABLE custom_links");
|
||||
// Then, update the database to the next sequential version
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.7'");
|
||||
// Then, update the database to the next sequential version
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.7'");
|
||||
}
|
||||
|
||||
//if(CURRENT_DATABASE_VERSION == '0.1.7'){
|
||||
if(CURRENT_DATABASE_VERSION == '0.1.7'){
|
||||
// Insert queries here required to update to DB version 0.1.8
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_backup_enable`");
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_backup_path`");
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.8'");
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.8'");
|
||||
}
|
||||
|
||||
//if(CURRENT_DATABASE_VERSION == '0.1.8'){
|
||||
// Insert queries here required to update to DB version 0.1.9
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.9'");
|
||||
//}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.1.7");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.1.8");
|
||||
23
db.sql
23
db.sql
|
|
@ -339,25 +339,6 @@ CREATE TABLE `contacts` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `custom_links`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `custom_links`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `custom_links` (
|
||||
`custom_link_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`custom_link_name` varchar(250) NOT NULL,
|
||||
`custom_link_icon` varchar(100) DEFAULT NULL,
|
||||
`custom_link_url` varchar(250) NOT NULL,
|
||||
`custom_link_order` int(11) DEFAULT NULL,
|
||||
`custom_link_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`company_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`custom_link_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `documents`
|
||||
--
|
||||
|
|
@ -1052,8 +1033,6 @@ CREATE TABLE `settings` (
|
|||
`config_stripe_secret` varchar(255) DEFAULT NULL,
|
||||
`config_azure_client_id` varchar(200) DEFAULT NULL,
|
||||
`config_azure_client_secret` varchar(200) DEFAULT NULL,
|
||||
`config_backup_enable` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`config_backup_path` varchar(250) DEFAULT NULL,
|
||||
`config_module_enable_itdoc` tinyint(1) NOT NULL DEFAULT 1,
|
||||
`config_module_enable_accounting` tinyint(1) NOT NULL DEFAULT 1,
|
||||
`config_module_enable_ticketing` tinyint(1) NOT NULL DEFAULT 1,
|
||||
|
|
@ -1494,4 +1473,4 @@ CREATE TABLE `vendors` (
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2022-09-17 16:34:13
|
||||
-- Dump completed on 2022-09-17 17:15:06
|
||||
|
|
|
|||
|
|
@ -70,10 +70,6 @@ $config_stripe_enable = $row['config_stripe_enable'];
|
|||
$config_stripe_publishable = $row['config_stripe_publishable'];
|
||||
$config_stripe_secret = $row['config_stripe_secret'];
|
||||
|
||||
// Backups
|
||||
$config_backup_enable = $row['config_backup_enable'];
|
||||
$config_backup_path = $row['config_backup_path'];
|
||||
|
||||
// Modules
|
||||
$config_module_enable_itdoc = $row['config_module_enable_itdoc'];
|
||||
$config_module_enable_ticketing = $row['config_module_enable_ticketing'];
|
||||
|
|
|
|||
18
post.php
18
post.php
|
|
@ -1053,24 +1053,6 @@ if(isset($_POST['edit_integrations_settings'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_backup_settings'])){
|
||||
|
||||
validateAdminRole();
|
||||
|
||||
$config_backup_enable = intval($_POST['config_backup_enable']);
|
||||
$config_backup_path = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_backup_path'])));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE settings SET config_backup_enable = $config_backup_enable, config_backup_path = '$config_backup_path' WHERE company_id = $session_company_id");
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Settings', log_action = 'Modify', log_description = '$session_name modified backup settings', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Backup Settings updated";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_module_settings'])){
|
||||
|
||||
validateAdminRole();
|
||||
|
|
|
|||
|
|
@ -1,42 +1,12 @@
|
|||
<?php include("inc_all_admin.php"); ?>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><i class="fa fa-fw fa-database"></i> Backup</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
|
||||
<div class="custom-control custom-switch mb-2">
|
||||
<input type="checkbox" class="custom-control-input" name="config_backup_enable" <?php if($config_backup_enable == 1){ echo "checked"; } ?> value="1" id="backupSwitch">
|
||||
<label class="custom-control-label" for="backupSwitch">Enable Backups <small>(cron.php must also be added to cron and run nightly at 11:00PM for backups to work)</small></label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Backup Path</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="config_backup_path" placeholder="Specify Full File System Path ex /home/user/web/itflow.example.com/private/backups" value="<?php echo $config_backup_path; ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<button type="submit" name="edit_backup_settings" class="btn btn-primary">Save</button>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark mb-3">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title"><i class="fa fa-fw fa-database"></i> Backup Database</h3>
|
||||
<h3 class="card-title"><i class="fa fa-fw fa-database"></i> Download Database</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<center>
|
||||
<a class="btn btn-primary btn-lg p-3" href="post.php?download_database"><i class="fa fa-fw fa-4x fa-download"></i><br><br>Download Database</a>
|
||||
<a class="btn btn-primary btn-lg p-3" href="post.php?download_database"><i class="fa fa-fw fa-4x fa-download"></i><br><br>Download</a>
|
||||
</center>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue