DB Backup Plugin Sync Time Setting Fields

This commit is contained in:
Václav Španinger 2021-02-15 14:18:44 +01:00
parent 3d3b073131
commit 821c0926e8
2 changed files with 17 additions and 2 deletions

View File

@ -14,7 +14,7 @@ class SettingsManager{
} }
public static function create ($name, $value, $type = '') { public static function create ($name, $value, $type = '') {
if (!self::getByName($name)){ //if (!self::getByName($name)){
$setting = array ( $setting = array (
'name' => $name, 'name' => $name,
'value' => $value, 'value' => $value,
@ -26,7 +26,7 @@ class SettingsManager{
echo $error->getMessage(); echo $error->getMessage();
die(); die();
} }
} //}
} }
public static function update ($name, $value, $type = '') { public static function update ($name, $value, $type = '') {

View File

@ -3,6 +3,19 @@ class DatabaseBackup
{ {
public function make() 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 { try {
$filenames = []; $filenames = [];
$backupWorker = new DatabaseBackup; $backupWorker = new DatabaseBackup;
@ -19,6 +32,7 @@ class DatabaseBackup
private function data() private function data()
{ {
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql'; $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"; $command = "mysqldump --skip-comments --no-create-info -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
$this->executeCommand($command); $this->executeCommand($command);
return $backupfile; return $backupfile;
@ -27,6 +41,7 @@ class DatabaseBackup
private function scheme() private function scheme()
{ {
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql'; $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"; $command = "mysqldump --skip-comments --no-data -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
$this->executeCommand($command); $this->executeCommand($command);
return $backupfile; return $backupfile;