Browse Source

DB Backup Plugin Sync Time Setting Fields

remastering
Václav Španinger 1 year ago
parent
commit
821c0926e8
2 changed files with 17 additions and 2 deletions
  1. +2
    -2
      app/models/managers/SettingsManager.php
  2. +15
    -0
      app/plugins/DatabaseBackup.php

+ 2
- 2
app/models/managers/SettingsManager.php View File

@ -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 = '') {

+ 15
- 0
app/plugins/DatabaseBackup.php View File

@ -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;

Loading…
Cancel
Save