53 public $sqlPath =
'../system/backup/current/';
80 if (isset($this->storeSqlTmp) && ($this->storeSqlTmp ==
"true"))
82 $this->zipBackup =
"false";
104 $this->dumpSettings = array(
120 if (isset($excludeTables) && (is_array($excludeTables) && (!empty($excludeTables))))
123 $this->excludeTablesArray = $excludeTables;
126 foreach ($this->excludeTablesArray AS $exclude => $table)
128 $this->dumpSettings[
'exclude-tables'][] = $table;
133 if (isset($this->dumpSettings[
'exclude-tables']) && (is_array($this->dumpSettings[
'exclude-tables']) && (!empty($this->dumpSettings[
'exclude-tables']))))
139 return $this->dumpSettings[
'exclude-tables'] = array();
151 if (isset($includeTables) && (is_array($includeTables) && (!empty($includeTables))))
154 $this->includeTablesArray = $includeTables;
157 foreach ($this->includeTablesArray AS $include => $table)
159 $this->dumpSettings[
'include-tables'][] = $table;
164 if (isset($this->dumpSettings[
'include-tables']) && (is_array($this->dumpSettings[
'include-tables']) && (!empty($this->dumpSettings[
'include-tables']))))
170 return $this->dumpSettings[
'include-tables'] = array();
181 require (
"../system/classes/dbconfig.php");
183 $this->host = $this->config[
'server'];
184 $this->
user = $this->config[
'username'];
185 $this->pass = $this->config[
'password'];
186 $this->dbname = $this->config[
'dbname'];
187 $this->prefix = $this->config[
'prefix'];
188 $this->port = $this->config[
'port'];
203 if (is_file(
'../system/engines/mysqldump/Mysqldump.php'))
206 require_once(
'../system/engines/mysqldump/Mysqldump.php');
209 if (isset($_POST[
'database']) && (!empty($_POST[
'database'])))
212 foreach ($_POST[
'database'] as $table)
215 $this->includeTablesArray[] = $table;
219 $this->dumpSettings = $this->
includeTables($this->includeTablesArray);
230 $this->mysqldump = new \Ifsnop\Mysqldump\Mysqldump(
"mysql:host=$this->host;dbname=$this->dbname", $this->
user, $this->pass, $this->dumpSettings);
235 \YAWK\sys::setSyslog(
$db, 52, 2,
"unable to backup: failed to include mysqldump class", 0, 0, 0, 0);
248 $this->sqlBackup = $this->sqlPath.$this->backupSqlFile;
250 if (is_file($this->sqlBackup))
267 public function setBackupSettings(
$db)
278 $this->backupSettings[
'USER_ID'] = $_SESSION[
'uid'];
279 $this->backupSettings[
'TABLES'] =
'';
280 foreach ($this->dumpSettings[
'include-tables'] as $table)
282 $this->backupSettings[
'TABLES'] .= $table.
",";
295 if (is_file($this->sqlBackup))
297 return $this->hashValue = hash_file(
'md5', $this->sqlBackup);
302 \YAWK\sys::setSyslog(
$db, 52, 2,
"failed to generate hash value - $this->sqlBackup not accessable", 0, 0, 0, 0);
316 if (isset($this->storeSqlTmp) && ($this->storeSqlTmp ==
"true"))
318 if (is_writeable($this->tmpFolder))
320 if (!is_dir($this->tmpFolder.
"database"))
322 mkdir($this->tmpFolder.
"database");
325 $this->sqlPath = $this->tmpFolder.
"database/";
327 $this->sqlBackup = $this->sqlPath.$this->backupSqlFile;
331 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to create database backup: $this->tmpFolder is not writeable", 0, 0, 0, 0);
337 if (is_writeable($this->sqlPath))
342 $this->mysqldump->start($this->sqlBackup, $this->dumpSettings);
348 \YAWK\sys::setSyslog(
$db, 52, 2,
"".$e->getMessage().
"", 0, 0, 0, 0);
357 $this->backupSettings = $this->setBackupSettings(
$db);
365 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to write $this->configFile", 0, 0, 0, 0);
369 if ($this->zipBackup ==
"true")
375 \YAWK\sys::setSyslog(
$db, 49, 0,
"created database backup $this->sqlBackup", 0, 0, 0, 0);
380 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to create database zip archive", 0, 0, 0, 0);
396 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to create database backup: $this->sqlPath is not writeable", 0, 0, 0, 0);
409 if ($this->zipBackup ==
"true")
414 $zip = new \ZipArchive();
428 \YAWK\sys::setSyslog(
$db, 51, 2,
"failed to create new zip archive $filename", 0, 0, 0, 0);
433 $zip->addFile($this->sqlBackup,$this->backupSqlFile);
436 if (is_file($this->sqlPath.$this->configFilename))
438 $zip->addFile($this->sqlPath.$this->configFilename, $this->configFilename);
442 \YAWK\sys::setSyslog(
$db, 51, 2,
"failed to add $this->configFilename to archive $filename", 0, 0, 0, 0);
453 if ($this->removeAfterZip ==
"true")
455 if (unlink ($this->sqlPath.$this->backupSqlFile)
456 && (unlink ($this->sqlPath.$this->configFilename)))
462 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to delete backup files after adding .zip archive $filename", 0, 0, 0, 0);
470 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to create .zip file: $filename", 0, 0, 0, 0);
476 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed create .zip archive - PHP ZIP class not available. Ask your web hosting provider about that", 0, 0, 0, 0);
500 if ($this->overwriteBackup ==
"false")
505 if (isset($_POST[
'newFolder']) && (!empty($_POST[
'newFolder'])))
508 $this->archiveBackupSubFolder = $this->archiveBackupFolder.$_POST[
'newFolder'].
"/";
511 if (!is_dir($this->archiveBackupSubFolder))
513 if (mkdir($this->archiveBackupSubFolder))
516 \YAWK\sys::setSyslog(
$db, 49, 0,
"archive directory created: $this->archiveBackupSubFolder", 0, 0, 0, 0);
521 \YAWK\sys::setSyslog(
$db, 52, 0,
"failed to create archive directory: $this->archiveBackupSubFolder", 0, 0, 0, 0);
526 else if (isset($_POST[
'selectFolder']) && (!empty($_POST[
'selectFolder'])))
528 $this->archiveBackupSubFolder = $this->archiveBackupFolder.$_POST[
'selectFolder'].
"/";
544 \YAWK\sys::setSyslog(
$db, 50, 3,
"database backup overwritten", 0, 0, 0, 0);
549 \YAWK\sys::setSyslog(
$db, 52, 2,
"failed to overwrite database backup", 0, 0, 0, 0);
562 \YAWK\sys::setSyslog(
$db, 52, 2,
"failed to write database backup", 0, 0, 0, 0);
generateZipArchive($db, $sqlBackup)
ZIP Archive method generates a zip archive from .sql file.
getHashValue($db)
get hash value from .sql backup file
setDumpSettings()
Set mysqldump settings.
includeMysqldumpClass($db)
Include mysqldump-php and create new dump object.
includeTables($includeTables)
Include only this tables into backup.
getDatabaseConfig()
Get current database config.
excludeTables($excludeTables)
Exclude tables from backup.
doSqlBackup($db)
Start mysqldump and check if .sql file exists. Zip it afterwards if enabled.
initMysqlBackup($db, $overwriteBackup, $zipBackup, $storeSqlTmp)
Initialize this database backup class.
sqlFileExists()
Check if .sql backup file exists.
startMysqlBackup($db)
Start and manage mysql backup routine.
setIniFile(object $db)
Set backup information file (backup.ini)
checkZipFunction()
Check if ZipArchive function exists.
static now()
returns the current datetime
The default user class. Provide all functions to handle the user object.