From 8b63c04ac9436fbbff9499ad524122337cea2fc8 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 1 Feb 2010 15:44:43 -0800 Subject: [PATCH] Single-transaction backup option --- mysql/CHANGELOG | 1 + mysql/backup.pl | 3 ++- mysql/backup_db.cgi | 4 +++- mysql/backup_form.cgi | 5 +++++ mysql/lang/en | 1 + mysql/mysql-lib.pl | 8 +++++--- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mysql/CHANGELOG b/mysql/CHANGELOG index ed24ecc21..73ffcb0e4 100644 --- a/mysql/CHANGELOG +++ b/mysql/CHANGELOG @@ -90,3 +90,4 @@ Restores and imports from local files are now run as the Unix user configured fo The information_schema database is no longer included when backing up all databases, as it really just contains metadata. ---- Changes since 1.500 ---- Added a collation order field to the database creation form. +Added an option to the backup form to do backup in a single transaction, for InnoDB tables. diff --git a/mysql/backup.pl b/mysql/backup.pl index 3503bb772..c2bb6415d 100755 --- a/mysql/backup.pl +++ b/mysql/backup.pl @@ -75,7 +75,8 @@ foreach $db (@dbs) { $config{'backup_charset_'.$sf}, \@compat, \@tables, - "root"); + "root", + $config{'backup_single_'.$sf}); if ($err) { print "Backup of database $db to file $file failed:\n"; print $out; diff --git a/mysql/backup_db.cgi b/mysql/backup_db.cgi index 7290836ed..e1a491319 100755 --- a/mysql/backup_db.cgi +++ b/mysql/backup_db.cgi @@ -77,6 +77,7 @@ if ($module_info{'usermin'}) { join(" ", split(/\0/, $in{'options'})); $userconfig{'backup_compress_'.$in{'db'}} = $in{'compress'}; $userconfig{'backup_drop_'.$in{'db'}} = $in{'drop'}; + $userconfig{'backup_single_'.$in{'db'}} = $in{'single'}; $userconfig{'backup_tables_'.$in{'db'}} = join(" ", @tables); &write_file("$user_module_config_directory/config", \%userconfig); } @@ -93,6 +94,7 @@ else { join(" ", split(/\0/, $in{'options'})); $config{'backup_compress_'.$in{'db'}} = $in{'compress'}; $config{'backup_drop_'.$in{'db'}} = $in{'drop'}; + $config{'backup_single_'.$in{'db'}} = $in{'single'}; $config{'backup_tables_'.$in{'db'}} = join(" ", @tables); &write_file("$module_config_directory/config", \%config); } @@ -132,7 +134,7 @@ if (!$in{'save'}) { local $err = &backup_database($db, $file, $in{'compress'}, $in{'drop'}, $in{'where_def'} ? undef : $in{'where'}, $in{'charset_def'} ? undef : $in{'charset'}, - \@compat, \@tables, $access{'buser'}); + \@compat, \@tables, $access{'buser'}, $in{'single'}); if ($err) { print "$main::whatfailed : ", &text('backup_ebackup',"
$err
"),"

\n"; diff --git a/mysql/backup_form.cgi b/mysql/backup_form.cgi index e668d0a1a..d56c1e466 100755 --- a/mysql/backup_form.cgi +++ b/mysql/backup_form.cgi @@ -121,6 +121,11 @@ print &ui_table_row($text{'backup_compress'}, [ 1, $text{'backup_gzip'} ], [ 2, $text{'backup_bzip2'} ] ])); +# Show single-transaction option +$s = $c{'backup_single_'.$in{'db'}}; +print &ui_table_row($text{'backup_single'}, + &ui_yesno_radio("single", $s ? 1 : 0)); + if ($cron) { # Show before/after commands $b = $c{'backup_before_'.$in{'db'}}; diff --git a/mysql/lang/en b/mysql/lang/en index 605cc8ad5..9db5356c3 100644 --- a/mysql/lang/en +++ b/mysql/lang/en @@ -644,6 +644,7 @@ backup_mkdir=Create destination directory? backup_where=Only backup rows matching where clause backup_none=All rows backup_drop=Add drop table statements to backup? +backup_single=Backup within a transaction? 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 3dee1a0ff..2686210b3 100755 --- a/mysql/mysql-lib.pl +++ b/mysql/mysql-lib.pl @@ -1324,13 +1324,14 @@ return $two eq "\037\213" ? 1 : } # backup_database(db, dest-file, compress-mode, drop-flag, where-clause, -# charset, &compatible, &only-tables, run-as-user) +# charset, &compatible, &only-tables, run-as-user, +# single-transaction-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) = @_; + $tables, $user, $single) = @_; if ($compress == 0) { $writer = ">$file"; } @@ -1341,6 +1342,7 @@ elsif ($compress == 2) { $writer = "| bzip2 -c >$file"; } local $dropsql = $drop ? "--add-drop-table" : ""; +local $singlesql = $single ? "--single-transaction" : ""; local $wheresql = $where ? "\"--where=$in{'where'}\"" : ""; local $charsetsql = $charset ? "--default-character-set=".quotemeta($charset) : ""; @@ -1349,7 +1351,7 @@ local $compatiblesql = @$compatible ? local $quotingsql = &supports_quoting() ? "--quote-names" : ""; local $routinessql = &supports_routines() ? "--routines" : ""; local $tablessql = join(" ", map { quotemeta($_) } @$tables); -local $cmd = "$config{'mysqldump'} $authstr $dropsql $wheresql $charsetsql $compatiblesql $quotingsql $routinessql ".quotemeta($db)." $tablessql 2>&1 $writer"; +local $cmd = "$config{'mysqldump'} $authstr $dropsql $singlesql $wheresql $charsetsql $compatiblesql $quotingsql $routinessql ".quotemeta($db)." $tablessql 2>&1 $writer"; if ($user && $user ne "root") { $cmd = &command_as_user($user, undef, $cmd); }