Single-transaction backup option

This commit is contained in:
Jamie Cameron
2010-02-01 15:44:43 -08:00
parent 3da49bdc8a
commit 8b63c04ac9
6 changed files with 17 additions and 5 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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',"<pre>$err</pre>"),"<p>\n";

View File

@ -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'}};

View File

@ -644,6 +644,7 @@ backup_mkdir=Create destination directory?
backup_where=Only backup rows matching <tt>where</tt> clause
backup_none=All rows
backup_drop=Add <tt>drop table</tt> 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

View File

@ -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);
}