Bug #8136 problem in mysqlhotcopy regexp
Submitted: 25 Jan 2005 17:05 Modified: 7 Mar 2005 0:21
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.1.9 OS:Linux (GNU/Linux)
Assigned to: Jim Winstead CPU Architecture:Any

[25 Jan 2005 17:05] [ name withheld ]
Description:
I think I found a problem in mysqlhotcopy script. When I use a regexp like this :

$ mysqlhotcopy database_name./^table_name$/

mysqlhotcopy don't process table_name, it's possible to bypass this if I add backquotes to "table_name" like this :

$ mysqlhotcopy database_name./^`table_name`$/

In this case mysqlhotcopy is able to apply the regexp on "table_name" but not the files of the database, so the process is not complete. The problem is when it checks the regexp the tables name are already backquoted in the array, not the files.

How to repeat:
$ mysqlhotcopy database_name./^table_name$/

Suggested fix:
I don't know how to make a patch and I'm not a Perl programmer ;) But here is a diff of the modifications I made because I absolutly needed a working mysqlhotcopy.

--------------------------------8<--------------------------------
--- /usr/bin/mysqlhotcopy       2005-01-13 04:35:05.000000000 +0100
+++ mysqlhotcopy                2005-01-25 17:18:49.149811727 +0100
@@ -280,11 +280,17 @@
         $t_regex = qr/$t_regex/;           ## make regex string from
                                            ## user regex
 
+        ## generate an array of tables without backquotes.
+        my @regex_tables;
+        foreach my $tbl (@dbh_tables) {
+            $tbl =~ s/`//g;
+            push @regex_tables, $tbl;
+        }
         ## filter (out) tables specified in t_regex
         print "Filtering tables with '$t_regex'\n" if $opt{debug};
         @dbh_tables = ( $negated 
-                        ? grep { $_ !~ $t_regex } @dbh_tables
-                        : grep { $_ =~ $t_regex } @dbh_tables );
+                        ? grep { $_ !~ $t_regex } @regex_tables
+                        : grep { $_ =~ $t_regex } @regex_tables );
     }
 
     ## get list of files to copy
-------------------------------->8--------------------------------

Someone would certainly be able to write this clean :)
[27 Jan 2005 22:34] Jim Winstead
This problem only crops up with DBD::mysql 2.9003 or later, when quoting of table names was implemented. Rather than remove all back-ticks, my patch only removes the leading and trailing quote when they are present.
[3 Mar 2005 21:20] Jim Winstead
Pushed, will be in 4.1.11 and 5.0.3.
[7 Mar 2005 0:21] Paul DuBois
Noted in 4.1.11, 5.0.3 changelogs.