List:Commits« Previous MessageNext Message »
From:Jim Winstead Date:August 4 2009 7:00pm
Subject:bzr commit into mysql-5.1-bugteam branch (jimw:3055) Bug#44278
View as plain text  
#At file:///Users/jimw/my/mysql-5.1-fixes/ based on revid:jimw@stripped

 3055 Jim Winstead	2009-08-04
      mysqlhotcopy did not handle the encoding of schema names in the filesystem, so
      schemas with most non-alphanumeric characters in their name could not be
      backed up. (Bug #44278).

    modified:
      scripts/mysqlhotcopy.sh
=== modified file 'scripts/mysqlhotcopy.sh'
--- a/scripts/mysqlhotcopy.sh	2009-04-28 16:16:17 +0000
+++ b/scripts/mysqlhotcopy.sh	2009-08-04 18:57:34 +0000
@@ -222,7 +222,7 @@ my ($tgt_dirname, $to_other_database);
 $to_other_database=0;
 if (defined($tgt_name) && $tgt_name =~ m:^\w+$: && @db_desc <= 1)
 {
-    $tgt_dirname = "$datadir/$tgt_name";
+    $tgt_dirname = "$datadir/" . encode_identifier_as_filename($tgt_name);
     $to_other_database=1;
 }
 elsif (defined($tgt_name) && ($tgt_name =~ m:/: || $tgt_name eq '.')) {
@@ -285,7 +285,7 @@ foreach my $rdb ( @db_desc ) {
     }
 
     ## get list of files to copy
-    my $db_dir = "$datadir/$db";
+    my $db_dir = "$datadir/" . encode_identifier_as_filename($db);
     opendir(DBDIR, $db_dir ) 
       or die "Cannot open dir '$db_dir': $!";
 
@@ -353,7 +353,8 @@ if (defined($tgt_name) && length $tgt_na
     elsif ($opt{method} =~ /^scp\b/) 
     {   # we have to trust scp to hit the target
 	foreach my $rdb ( @db_desc ) {
-	    $rdb->{target} = "$tgt_dirname/$rdb->{src}";
+	    $rdb->{target} = "$tgt_dirname/" .
+                             encode_identifier_as_filename($rdb->{src});
 	}
     }
     else
@@ -361,7 +362,8 @@ if (defined($tgt_name) && length $tgt_na
       die "Last argument ($tgt_dirname) is not a directory\n"
 	if (!(-e $tgt_dirname && -d $tgt_dirname ) );
       foreach my $rdb ( @db_desc ) {
-	$rdb->{target} = "$tgt_dirname/$rdb->{src}";
+	$rdb->{target} = "$tgt_dirname/" .
+                         encode_identifier_as_filename($rdb->{src});
       }
     }
   }
@@ -369,7 +371,8 @@ else {
   die "Error: expected \$opt{suffix} to exist" unless ( exists $opt{suffix} );
 
   foreach my $rdb ( @db_desc ) {
-    $rdb->{target} = "$datadir/$rdb->{src}$opt{suffix}";
+    $rdb->{target} = "$datadir/" .
+                     encode_identifier_as_filename("$rdb->{src}$opt{suffix}");
   }
 }
 
@@ -414,7 +417,8 @@ foreach my $rdb ( @db_desc ) {
             unless -d $tgt_dirpath;
         if ($^O !~ m/^(NetWare)$/)  
         {
-            my @f_info= stat "$datadir/$rdb->{src}";
+            my @f_info= stat "$datadir/" .
+                             encode_identifier_as_filename($rdb->{src});
             chown $f_info[4], $f_info[5], $tgt_dirpath;
         }
     }
@@ -471,7 +475,9 @@ my @failed = ();
 
 foreach my $rdb ( @db_desc )
 {
-  my @files = map { "$datadir/$rdb->{src}/$_" } @{$rdb->{files}};
+  my @files = map { "$datadir/" .
+                    encode_identifier_as_filename($rdb->{src}) .
+                    "/$_" } @{$rdb->{files}};
   next unless @files;
   
   eval { copy_files($opt{method}, \@files, $rdb->{target}); };
@@ -482,7 +488,8 @@ foreach my $rdb ( @db_desc )
   if ($rdb->{index})
   {
     copy_index($opt{method}, \@files,
-	       "$datadir/$rdb->{src}", $rdb->{target} );
+	       "$datadir/" . encode_identifier_as_filename($rdb->{src}),
+               $rdb->{target} );
   }
   
   if ( $opt{checkpoint} ) {
@@ -794,6 +801,20 @@ sub quote_names {
   return "`$db`.`$table`";
 }
 
+#
+# In MySQL 5.1 and later, directory and table names are encoded on disk.
+# We use the server to figure out the encoded names, and just fall back
+# to the unencoded identifier if that fails.
+#
+sub encode_identifier_as_filename {
+  my ($ident)= @_;
+  my ($filename)= $dbh->selectrow_array(
+                    "SELECT BINARY(CAST(? AS CHAR CHARACTER SET FILENAME))",
+                    { RaiseError => 0 },
+                    $ident);
+  return $filename ? $filename : $ident;
+}
+
 __END__
 
 =head1 DESCRIPTION


Attachment: [text/bzr-bundle] bzr/jimw@mysql.com-20090804185734-0n0zsqzu10d8lkup.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (jimw:3055) Bug#44278Jim Winstead4 Aug