Single-transaction backup option
authorJamie Cameron <jcameron@webmin.com>
Mon, 1 Feb 2010 23:44:43 +0000 (15:44 -0800)
committerJamie Cameron <jcameron@webmin.com>
Mon, 1 Feb 2010 23:44:43 +0000 (15:44 -0800)
mysql/CHANGELOG
mysql/backup.pl
mysql/backup_db.cgi
mysql/backup_form.cgi
mysql/lang/en
mysql/mysql-lib.pl

index ed24ecc..73ffcb0 100644 (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.
index 3503bb7..c2bb641 100755 (executable)
@@ -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;
index 7290836..e1a4913 100755 (executable)
@@ -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";
index e668d0a..d56c1e4 100755 (executable)
@@ -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'}};
index 605cc8a..9db5356 100644 (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
index 3dee1a0..2686210 100755 (executable)
@@ -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);
        }