Skip to content

Commit

Permalink
Merge branch 'fix/optimize-mysql-dump'
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Apr 11, 2023
2 parents 10d8540 + 9abb2d1 commit c1d8050
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Method/MysqlMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ public function exportSqlToFile(
$get_structure_cmd[] = "--opt";
$get_structure_cmd[] = "-Q";
$get_structure_cmd[] = "--no-data";
$get_structure_cmd[] = ">";
$get_structure_cmd[] = $backup_file_name;

$get_data_cmd = $this->getMysqlCommand($host_config, $context, 'mysqlDump', $data, true);
$get_data_cmd[] = "--no-autocommit";
Expand All @@ -235,8 +233,6 @@ public function exportSqlToFile(
foreach ($context->getConfigurationService()->getSetting('sqlSkipTables', []) as $table_name) {
$get_data_cmd[] = sprintf("--ignore-table %s.%s", $data['name'], $table_name);
}
$get_data_cmd[] = ">>";
$get_data_cmd[] = $backup_file_name;

if (!$shell->exists(dirname($backup_file_name))) {
$shell->run(sprintf('mkdir -p %s', dirname($backup_file_name)));
Expand All @@ -245,12 +241,24 @@ public function exportSqlToFile(
$shell->run(sprintf('rm -f %s', $backup_file_name));


$shell->run(implode(" ", $get_structure_cmd), false, true);
$shell->run(implode(" ", $get_data_cmd), false, true);
$get_structure_cmd_str = implode(" ", $get_structure_cmd);
$get_data_cmd_str = implode(" ", $get_data_cmd);

if ($zipped_backup) {
$shell->run(sprintf('#!gzip -f %s', $backup_file_name));
$backup_file_name .= '.gz';
$shell->run(sprintf(
'( %s && %s ) | #!gzip > %s',
$get_structure_cmd_str,
$get_data_cmd_str,
$backup_file_name
));
} else {
$shell->run(sprintf(
'( %s && %s ) > %s',
$get_structure_cmd_str,
$get_data_cmd_str,
$backup_file_name
));
}
$shell->run('set +o pipefail');
$shell->popWorkingDir();
Expand Down

0 comments on commit c1d8050

Please sign in to comment.