Commit afc49466 authored by Marius Burkard's avatar Marius Burkard

Merge branch '5867-mysql-backups-are-not-generating-on-3-2-multi-server-setup' into 'develop'

Resolve "MySQL backups are not generating on 3.2 & multi server setup"

Closes #5866 and #5867

See merge request ispconfig/ispconfig3!1323
parents b4434315 fd95b9b2
Pipeline #6491 passed with stage
in 13 seconds
......@@ -666,6 +666,14 @@ class installer_base {
$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
}
$query = "GRANT SELECT ON ?? TO ?@?";
if ($verbose){
echo $query ."\n";
}
if(!$this->dbmaster->query($query, $value['db'] . '.web_database', $value['user'], $host)) {
$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
}
$query = "GRANT SELECT ON ?? TO ?@?";
if ($verbose){
echo $query ."\n";
......
......@@ -56,10 +56,22 @@ class plugin_backuplist extends plugin_base {
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = ? AND action_param = ?";
$tmp = $app->db->queryOneRecord($sql, $action_type, $domain_id);
if ($tmp['number'] == 0) {
$server_id = $this->form->dataRecord['server_id'];
if($action_type === 'backup_database') {
// get all server ids of databases for this domain
$sql = 'SELECT `server_id` FROM `web_database` WHERE `parent_domain_id` = ?';
$result = $app->db->query($sql, $domain_id);
while(($cur = $result->get())) {
$server_id = $cur['server_id'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) VALUES (?, UNIX_TIMESTAMP(), ?, ?, 'pending', '')";
$app->db->query($sql, $server_id, $action_type, $domain_id);
}
$result->free();
} else {
$server_id = $this->form->dataRecord['server_id'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) VALUES (?, UNIX_TIMESTAMP(), ?, ?, 'pending', '')";
$app->db->query($sql, $server_id, $action_type, $domain_id);
}
$message .= $wb['backup_info_txt'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) VALUES (?, UNIX_TIMESTAMP(), ?, ?, 'pending', '')";
$app->db->query($sql, $server_id, $action_type, $domain_id);
} else {
$error .= $wb['backup_pending_txt'];
}
......@@ -193,10 +205,10 @@ class plugin_backuplist extends plugin_base {
$rec['backup_encrypted'] = empty($rec['backup_password']) ? $wb["no_txt"] : $wb["yes_txt"];
$backup_manual_prefix = 'manual-';
$rec['backup_job'] = (substr($rec['filename'], 0, strlen($backup_manual_prefix)) == $backup_manual_prefix) ? $wb["backup_job_manual_txt"] : $wb["backup_job_auto_txt"];
$rec['download_available'] = true;
if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
if($rec['filesize'] > 0){
$rec['filesize'] = $app->functions->currency_format($rec['filesize']/(1024*1024), 'client').' MB';
}
......
......@@ -1145,7 +1145,7 @@ class backup
if (empty($backup_job))
$backup_job = "auto";
$records = $app->db->queryAllRecords("SELECT * FROM web_database WHERE server_id = ? AND parent_domain_id = ?", $server_id, $domain_id);
$records = $app->dbmaster->queryAllRecords("SELECT * FROM web_database WHERE server_id = ? AND parent_domain_id = ?", $server_id, $domain_id);
if (empty($records)){
$app->log('Skipping database backup for domain ' . $web_domain['domain_id'] . ', because no related databases found.', LOGLEVEL_DEBUG);
return true;
......@@ -1396,17 +1396,17 @@ class backup
*/
public static function run_backup($domain_id, $type, $backup_job, $mount = true)
{
global $app;
global $app, $conf;
$domain_id = intval($domain_id);
$sql = "SELECT * FROM web_domain WHERE (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND domain_id = ?";
$rec = $app->db->queryOneRecord($sql, $domain_id);
$rec = $app->dbmaster->queryOneRecord($sql, $domain_id);
if (empty($rec)) {
$app->log('Failed to make backup of type ' . $type . ', because no information present about requested domain id ' . $domain_id, LOGLEVEL_ERROR);
return false;
}
$server_id = intval($rec['server_id']);
$server_id = intval($conf['server_id']);
if ($mount && !self::mount_backup_dir($server_id)) {
$app->log('Failed to make backup of type ' . $type . ' for domain id ' . $domain_id . ', because failed to mount backup directory', LOGLEVEL_ERROR);
......@@ -1419,6 +1419,7 @@ class backup
$ok = self::make_web_backup($rec, $backup_job);
break;
case 'mysql':
$rec['server_id'] = $server_id;
$ok = self::make_database_backup($rec, $backup_job);
break;
default:
......@@ -1443,7 +1444,7 @@ class backup
$server_id = intval($server_id);
$sql = "SELECT * FROM web_domain WHERE server_id = ? AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND active = 'y' AND backup_interval != 'none' AND backup_interval != ''";
$domains = $app->db->queryAllRecords($sql, $server_id);
$domains = $app->dbmaster->queryAllRecords($sql, $server_id);
if (!self::mount_backup_dir($server_id)) {
$app->log('Failed to run regular backups routine because failed to mount backup directory', LOGLEVEL_ERROR);
......@@ -1456,7 +1457,15 @@ class backup
foreach ($domains as $domain) {
if (($domain['backup_interval'] == 'daily' or ($domain['backup_interval'] == 'weekly' && $date_of_week == 0) or ($domain['backup_interval'] == 'monthly' && $date_of_month == '01'))) {
self::run_backup($domain['domain_id'], 'web', $backup_job, false);
self::run_backup($domain['domain_id'], 'mysql', $backup_job, false);
}
}
$sql = "SELECT DISTINCT d.*, db.server_id as `server_id` FROM web_database as db INNER JOIN web_domain as d ON (d.domain_id = db.parent_domain_id) WHERE db.server_id = ? AND db.active = 'y' AND d.backup_interval != 'none' AND d.backup_interval != ''";
$databases = $app->dbmaster->queryAllRecords($sql, $server_id);
foreach ($databases as $database) {
if (($database['backup_interval'] == 'daily' or ($database['backup_interval'] == 'weekly' && $date_of_week == 0) or ($database['backup_interval'] == 'monthly' && $date_of_month == '01'))) {
self::run_backup($database['domain_id'], 'mysql', $backup_job, false);
}
}
self::unmount_backup_dir($server_id);
......
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