Bug #2650 mysqlhotcopy doesn't work with mysqld in chroot. Patch attached
Submitted: 5 Feb 2004 3:23 Modified: 10 Mar 2004 12:16
Reporter: David Fletcher Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.0.17 OS:Linux (Linux)
Assigned to: Jani Tolonen CPU Architecture:Any

[5 Feb 2004 3:23] David Fletcher
Description:
Mysqlhot copy fails when the mysqld process has been set-up to run in a chroot jail. The hotcopy script looks for files in the main file tree, not in the chroot. 

This happens becuase mysqlhotcopy queries the server for the database directory, but the server gives the reply from inside the chroot, not relative to the real root directory.

How to repeat:
With mysqld set up to run in a jail at /chroot/mysql:

mysqlhotcopy -u user -p topsecret mydatabase /backup_dir

fails with 

Cannot open dir '/usr/local/mysql/data/mydatabase'

Suggested fix:
A patch for mysqlhotcopy is included below. It adds the command line option 'chroot' to tell the hotcopy script the root of the chroot jail.

The patch is against Mysql 4.0.17, mysqlhotcopy version 1.20

--- mysqlhotcopy	2003-12-14 21:59:12.000000000 +0000
+++ mysqlhotcopy2	2004-02-05 10:53:56.000000000 +0000
@@ -73,6 +73,7 @@
   --resetslave         reset the master.info once all tables are locked
   --tmpdir=#	       temporary directory (instead of $opt_tmpdir)
   --record_log_pos=#   record slave and master status in specified db.table
+  --chroot=#           base directory of chroot jail in which mysqld operates
 
   Try \'perldoc $0 for more complete documentation\'
 _OPTIONS
@@ -117,6 +118,7 @@
     "resetslave",
     "tmpdir|t=s",
     "dryrun|n",
+    "chroot=s",
 ) or usage("Invalid option");
 
 # @db_desc
@@ -210,6 +212,9 @@
 }
 my $datadir = $mysqld_vars{'datadir'}
     || die "datadir not in mysqld variables";
+if ( $opt{chroot} ) {
+    $datadir = $opt{chroot}.$datadir;
+}
 $datadir =~ s:/$::;
[10 Feb 2004 12:09] Timothy Smith
The supplied patch looks good to me; I verified that it does fix the problem.
[4 Mar 2004 7:48] Jani Tolonen
Fix will appear in 4.0.19.