Too easy to backup wrong datadir with multiple instances
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Percona XtraBackup moved to https://jira.percona.com/projects/PXB |
Fix Released
|
Wishlist
|
Alexey Kopytov | ||
2.1 |
Won't Fix
|
Undecided
|
Unassigned | ||
2.2 |
Fix Released
|
Wishlist
|
Alexey Kopytov |
Bug Description
If you have a valid datadir that is referenced in /etc/my.cnf and another instance you specify by socket, you can silently back up the wrong directory when you forget to pass --defaults-file:
# innobackupex --socket=
<SNIP>
140716 19:05:51 innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/var/lib/mysql'
innobackupex: Backing up files '/var/lib/
# mysql -S/s/56master/
/s/56master/data/
A straight forward fix would be to compare $orig_datadir/ to @@datadir that you SELECT over the socket:
For percona-
@@ -1899,6 +1899,13 @@
my $buffer_
+ # Validate datadir for current socket before doing any heavy lifting
+ my ($datadir_var) = eval { $mysql{
+ if ( "$orig_datadir/" ne "$datadir_var" ) {
+ print STDERR "$prefix Error: $orig_datadir incorrect for this unix socket\n";
+ exit 1;
+ }
+
detect_
#
For percona-
If this is not acceptable or conflicts with goals in https:/
my $buffer_
+ # Validate datadir for current socket before doing any heavy lifting
+ use Digest::MD5 qw(md5_hex);
+ my $test_view = md5_hex("$now $prefix $orig_datadir"); # Avoid replication race
+ print STDERR "\n";
+ print STDERR "$now $prefix Creating a test view to validate that datadir is $orig_datadir\n";
+ mysql_query(
+ if (!-f "$orig_
+ print STDERR "$now $prefix Dropping test view\n";
+ mysql_query(
+ print STDERR "Detected $orig_datadir to be incorrect for this unix socket\n";
+ exit 1;
+ } else {
+ print STDERR "$now $prefix Datadir validated, dropping test view\n";
+ mysql_query(
+ }
+
detect_
#
At least one problem with the heavy handed approach is that there is a race condition if the slave runs a backup at the same second but server_id does not seem to be available via xtrabackup --print-param. Perhaps it could be extended to toggle the session variable for sql_log_
Related branches
- Sergei Glushchenko (community): Approve
-
Diff: 875 lines (+385/-197)8 files modifiedstorage/innobase/xtrabackup/innobackupex.pl (+182/-136)
storage/innobase/xtrabackup/src/xtrabackup.cc (+106/-48)
storage/innobase/xtrabackup/test/run.sh (+2/-6)
storage/innobase/xtrabackup/test/t/bug1062684.sh (+6/-6)
storage/innobase/xtrabackup/test/t/bug1334062.sh (+24/-0)
storage/innobase/xtrabackup/test/t/bug1343722.sh (+18/-0)
storage/innobase/xtrabackup/test/t/bug766305.sh (+1/-1)
storage/innobase/xtrabackup/test/t/xb_print_param.sh (+46/-0)
This might also occur without multiple instances, if you have changed datadir in /etc/my.cnf but have not yet restarted the server.