Commit e125017d authored by Florian Schaal's avatar Florian Schaal
Browse files

Update backup.inc.php

parent 83bd082d
......@@ -265,42 +265,6 @@ class backup {
}
//* Remove the uncompressed file
if(is_file($db_backup_dir.'/'.$db_backup_file)) unlink($db_backup_dir.'/'.$db_backup_file);
// additional dump per table
if($rec['backup_per_table'] == 'y' && $rec['active'] == 'y') {
$dump_tables = array();
$database = new db($clientdb_host, $clientdb_user, $clientdb_password, $db_name);
$temp = $database->queryAllRecords('show tables');
unset($database);
foreach($temp as $idx=>$val) $dump_tables[] = $val['Tables_in_'.$db_name];
$annex = $archive_annex.'-split';
$db_backup_archive = 'db_'.$db_name.'_'.date('Y-m-d_H-i').$annex.'.sql.zip';
if(is_array($dump_tables) && !empty($dump_tables)) {
$app->system->mkdirpath($this->backup_tmp.'/'.$db_name.$annex);
foreach($dump_tables as $dump_table) {
$temp_file = $this->backup_tmp.'/'.$db_name.$annex.'/'.$dump_table.'.sql';
$command = "mysqldump -h ? -u ? -p? -c --add-drop-table --create-options --quick --max_allowed_packet=512M --result-file=? ? ?";
$app->system->exec_safe($command, $clientdb_host, $clientdb_user, $clientdb_password, $temp_file, $db_name, $dump_table);
$retval = $app->system->last_exec_retcode();
if($retval != 0) $app->log('mysqldump for '.$db_name.'.'.$dump_table.' failed', LOGLEVEL_ERROR);
}
$check = glob($this->backup_tmp.'/'.$db_name.$annex.'/*sql');
if(is_array($check) && !empty($check)) {
chmod($this->backup_tmp.'/'.$db_name.$annex, 0700);
$app->system->exec_safe('chown -R ?.? ?', 'root', 'root', $this->backup_tmp.'/'.$db_name.$annex);
$app->system->exec_safe('cd ? && zip ? *sql && cd ..', $this->backup_tmp.'/'.$db_name.$annex, $db_backup_dir.'/'.$db_backup_archive);
$app->system->exec_safe('rm -rf ?', $this->backup_tmp.'/'.$db_name.$annex);
$filesize = filesize($db_backup_dir.'/'.$db_backup_archive);
$sql = 'INSERT INTO web_backup (server_id, parent_domain_id, backup_type, backup_mode, tstamp, filename, filesize) VALUES (?, ?, ?, ?, ?, ?, ?)';
$app->db->query($sql, $this->server_id, $web_id, 'mysql', 'zip', time(), $db_backup_archive, $filesize);
if($app->db->dbHost != $app->dbmaster->dbHost) {
$app->dbmaster->query($sql, $this->server_id, $web_id, 'mysql', 'sqlgz', time(), $db_backup_archive, $filesize);
}
unset($filesize);
} else {
$app->log('mysqldump for '.$db_name.' with file per table failed', LOGLEVEL_ERROR);
}
}
}
//* Remove old backups
$this->clean_backup_dir($rec, 'mysql');
} else {
......@@ -358,19 +322,12 @@ class backup {
if(array_key_exists($matches[1], $files) == false) $files[$matches[1]] = array();
$files[$matches[1]][] = $entry;
}
if($entry != '.' && $entry != '..' && preg_match('/^db_('.$db_name.')_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}(-manual|)-split\.sql\.zip$/', $entry, $matches) && is_file($backup_dir.'/'.$entry)) {
if(array_key_exists($matches[1], $split_files) == false) $split_files[$matches[1]] = array();
$split_files[$matches[1]][] = $entry;
}
}
$dir_handle->close();
reset($files);
foreach($files as $db_name => $filelist) rsort($filelist);
$files = $filelist;
reset($split_files);
foreach($split_files as $db_name => $filelist) rsort($filelist);
$split_files = $filelist;
}
for ($n = $backup_copies; $n <= 10; $n++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment