From ea91c26d7055fabb866ce8d70fb35df13552aebf Mon Sep 17 00:00:00 2001 From: Scott Lucas Date: Thu, 12 Aug 2021 09:29:02 +0100 Subject: [PATCH] Add custom mysql backup parameters option --- mysql/backup.pl | 1 + mysql/backup_db.cgi | 4 +++- mysql/backup_form.cgi | 5 +++++ mysql/lang/en | 1 + mysql/mysql-lib.pl | 7 ++++--- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mysql/backup.pl b/mysql/backup.pl index 00409ce62..f865e6194 100755 --- a/mysql/backup.pl +++ b/mysql/backup.pl @@ -98,6 +98,7 @@ foreach $db (@dbs) { "root", $config{'backup_single_'.$sf}, $config{'backup_quick_'.$sf}, + $config{'backup_parameters_'.$sf} ); if ($err) { $ex = 1; diff --git a/mysql/backup_db.cgi b/mysql/backup_db.cgi index 465c1dcdf..4994a3f91 100755 --- a/mysql/backup_db.cgi +++ b/mysql/backup_db.cgi @@ -92,6 +92,7 @@ if ($module_info{'usermin'}) { $userconfig{'backup_drop_'.$in{'db'}} = $in{'drop'}; $userconfig{'backup_single_'.$in{'db'}} = $in{'single'}; $userconfig{'backup_quick_'.$in{'db'}} = $in{'quick'}; + $userconfig{'backup_parameters_'.$in{'db'}} = $in{'parameters'}; $userconfig{'backup_tables_'.$in{'db'}} = join(" ", @tables); if ($in{'save'}) { &save_user_module_config(); @@ -116,6 +117,7 @@ else { $config{'backup_drop_'.$in{'db'}} = $in{'drop'}; $config{'backup_single_'.$in{'db'}} = $in{'single'}; $config{'backup_quick_'.$in{'db'}} = $in{'quick'}; + $config{'backup_parameters_'.$in{'db'}} = $in{'parameters'}; $config{'backup_tables_'.$in{'db'}} = join(" ", @tables); if ($in{'save'}) { &save_module_config(); @@ -204,7 +206,7 @@ if (!$in{'save'}) { $in{'drop'}, $in{'where_def'} ? undef : $in{'where'}, $in{'charset_def'} ? undef : $in{'charset'}, \@compat, \@tables, $access{'buser'}, $in{'single'}, - $in{'quick'}); + $in{'quick'}, $in{'parameters'}); if ($err) { print &text('backup_ebackup', "
".&html_escape($err)."
"),"

\n"; diff --git a/mysql/backup_form.cgi b/mysql/backup_form.cgi index ac47366d8..7ca520a02 100755 --- a/mysql/backup_form.cgi +++ b/mysql/backup_form.cgi @@ -150,6 +150,11 @@ $q = $c{'backup_quick_'.$in{'db'}}; print &ui_table_row($text{'backup_quick'}, &ui_yesno_radio("quick", $q ? 1 : 0)); +# Allow user to specify custom backup parameters +$b = $c{'backup_parameters_'.$in{'db'}}; +print &ui_table_row($text{'backup_parameters'}, + &ui_textbox("parameters", $b, 60)); + if ($cron) { # Show before/after commands $b = $c{'backup_before_'.$in{'db'}}; diff --git a/mysql/lang/en b/mysql/lang/en index 38fff6444..d46d3f053 100644 --- a/mysql/lang/en +++ b/mysql/lang/en @@ -621,6 +621,7 @@ backup_none=All rows backup_drop=Add drop table statements to backup? backup_single=Backup within a transaction? backup_quick=Dump rows one at a time? +backup_parameters=Add custom parameters to backup command? backup_charset=Character set for backup backup_ok=Backup Now backup_ok1=Save and Backup Now diff --git a/mysql/mysql-lib.pl b/mysql/mysql-lib.pl index 707dd9da5..5b87710fd 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1439,13 +1439,13 @@ return $two eq "\037\213" ? 1 : # backup_database(db, dest-file, compress-mode, drop-flag, where-clause, # charset, &compatible, &only-tables, run-as-user, -# single-transaction-flag, quick-flag, force-flag) +# single-transaction-flag, quick-flag, parameters, force-flag) # Backs up a database to the given file, optionally with compression. Returns # undef on success, or an error message on failure. sub backup_database { local ($db, $file, $compress, $drop, $where, $charset, $compatible, - $tables, $user, $single, $quick, $force) = @_; + $tables, $user, $single, $quick, $parameters, $force) = @_; if ($compress == 0) { $writer = "cat >".quotemeta($file); } @@ -1459,6 +1459,7 @@ local $dropsql = $drop ? "--add-drop-table" : ""; local $singlesql = $single ? "--single-transaction" : ""; local $forcesql = $force ? "--force" : ""; local $quicksql = $quick ? "--quick" : ""; +local $parameterssql = $parameters ? quotemeta($parameters) : ""; local $wheresql = $where ? "--where=".quotemeta($in{'where'}) : ""; local $charsetsql = $charset ? "--default-character-set=".quotemeta($charset) : ""; @@ -1482,7 +1483,7 @@ if ($user && $user ne "root") { # Actual writing of output is done as another user $writer = &command_as_user($user, 0, $writer); } -local $cmd = "$config{'mysqldump'} $authstr $dropsql $singlesql $forcesql $quicksql $wheresql $charsetsql $compatiblesql $quotingsql $routinessql ".quotemeta($db)." $tablessql $eventssql $gtidsql | $writer"; +local $cmd = "$config{'mysqldump'} $authstr $dropsql $singlesql $forcesql $quicksql $parameterssql $wheresql $charsetsql $compatiblesql $quotingsql $routinessql ".quotemeta($db)." $tablessql $eventssql $gtidsql | $writer"; if (&shell_is_bash()) { $cmd = "set -o pipefail ; $cmd"; }