From 821c0926e815f1949c533e4cacc90a0bac375dae Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Mon, 15 Feb 2021 14:18:44 +0100 Subject: [PATCH] DB Backup Plugin Sync Time Setting Fields --- app/models/managers/SettingsManager.php | 4 ++-- app/plugins/DatabaseBackup.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/models/managers/SettingsManager.php b/app/models/managers/SettingsManager.php index 1d350f9..2c34c69 100644 --- a/app/models/managers/SettingsManager.php +++ b/app/models/managers/SettingsManager.php @@ -14,7 +14,7 @@ class SettingsManager{ } public static function create ($name, $value, $type = '') { - if (!self::getByName($name)){ + //if (!self::getByName($name)){ $setting = array ( 'name' => $name, 'value' => $value, @@ -26,7 +26,7 @@ class SettingsManager{ echo $error->getMessage(); die(); } - } + //} } public static function update ($name, $value, $type = '') { diff --git a/app/plugins/DatabaseBackup.php b/app/plugins/DatabaseBackup.php index e30dbda..29b2f97 100644 --- a/app/plugins/DatabaseBackup.php +++ b/app/plugins/DatabaseBackup.php @@ -3,6 +3,19 @@ class DatabaseBackup { public function make() { + //Register the settings + $time = '00:00'; + $settingMng = new SettingsManager(); + if (!($settingField = $settingMng->getByName("backup_time","db_backup"))) { + $settingMng->create("backup_time", $time, "db_backup"); + } else { + $time = $settingField['value']; + } + + //Time to Backup ? + if (date("H:i",time()) != $time) + return 'pending'; + try { $filenames = []; $backupWorker = new DatabaseBackup; @@ -19,6 +32,7 @@ class DatabaseBackup private function data() { $backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql'; + if (file_exists($backupfile)) return null; $command = "mysqldump --skip-comments --no-create-info -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1"; $this->executeCommand($command); return $backupfile; @@ -27,6 +41,7 @@ class DatabaseBackup private function scheme() { $backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql'; + if (file_exists($backupfile)) return null; $command = "mysqldump --skip-comments --no-data -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1"; $this->executeCommand($command); return $backupfile;