Merge lp:~akopytov/percona-xtrabackup/bug1049291-2.1 into lp:percona-xtrabackup/2.1

Proposed by Alexey Kopytov
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 700
Proposed branch: lp:~akopytov/percona-xtrabackup/bug1049291-2.1
Merge into: lp:percona-xtrabackup/2.1
Diff against target: 183 lines (+111/-9)
3 files modified
innobackupex.pl (+47/-9)
test/t/bug1049291.sh (+23/-0)
test/t/bug382742.sh (+41/-0)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/bug1049291-2.1
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+195754@code.launchpad.net

Description of the change

  Bug #1049291: innobackupex --copy-back fails with an empty
                innodb-data-home-dir

  The problem was that innobackupex unconditionally required
  innodb-data-home-dir to exist and be empty. There are, however, cases
  when the value of that variable does not represent a valid path (it may
  be empty), or point to root directory ("/") which naturally cannot be
  empty.

  Solutions:

  - do not perform any checks for an empty innodb-data-home-dir

  - assume an empty innodb-data-home-dir to be identical to MySQL’s
  datadir to replicate InnoDB behavior

  - do not require innodb-data-home-dir to be empty, but instead refuse to
  existing files in that directory. The non-empty requirement for the
  data directory makes sense, it was implemented to fix bug
  #737569. Requiring other directories to be empty is redundant, it is
  sufficient to just refuse to overwrite any files.

  The above changes, together with some previous bugfixes, automatically
  fix bug #382742. So this patch adds a test case for that bug.

http://jenkins.percona.com/view/XtraBackup/job/percona-xtrabackup-2.1-param/499/

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'innobackupex.pl'
--- innobackupex.pl 2013-11-15 11:01:25 +0000
+++ innobackupex.pl 2013-11-19 11:58:36 +0000
@@ -2090,6 +2090,18 @@
2090}2090}
20912091
2092#2092#
2093# Check if a given directory exists, or fail with an error otherwise
2094#
2095
2096sub if_directory_exists {
2097 my $empty_dir = shift;
2098 my $is_directory_empty_comment = shift;
2099 if (! -d $empty_dir) {
2100 die "$is_directory_empty_comment directory '$empty_dir' does not exist!";
2101 }
2102}
2103
2104#
2093# if_directory_exists_and_empty accepts two arguments:2105# if_directory_exists_and_empty accepts two arguments:
2094# variable with directory name and comment.2106# variable with directory name and comment.
2095# Sub checks that directory exists and is empty2107# Sub checks that directory exists and is empty
@@ -2099,9 +2111,9 @@
2099sub if_directory_exists_and_empty {2111sub if_directory_exists_and_empty {
2100 my $empty_dir = shift;2112 my $empty_dir = shift;
2101 my $is_directory_empty_comment = shift;2113 my $is_directory_empty_comment = shift;
2102 if (! -d $empty_dir) {2114
2103 die "$is_directory_empty_comment directory '$empty_dir' does not exist!";2115 if_directory_exists($empty_dir, $is_directory_empty_comment);
2104 }2116
2105 opendir (my $dh, $empty_dir) or die "$is_directory_empty_comment directory '$empty_dir': Not a directory";2117 opendir (my $dh, $empty_dir) or die "$is_directory_empty_comment directory '$empty_dir': Not a directory";
2106 if ( ! scalar( grep { $_ ne "." && $_ ne ".." && $_ ne "my.cnf" && $_ ne "master.info"} readdir($dh)) == 0) {2118 if ( ! scalar( grep { $_ ne "." && $_ ne ".." && $_ ne "my.cnf" && $_ ne "master.info"} readdir($dh)) == 0) {
2107 die "$is_directory_empty_comment directory '$empty_dir' is not empty!";2119 die "$is_directory_empty_comment directory '$empty_dir' is not empty!";
@@ -2110,6 +2122,18 @@
2110}2122}
21112123
2112#2124#
2125# Fail with an error if file exists
2126#
2127
2128sub die_if_exists {
2129 my $path = shift;
2130
2131 if (-e $path) {
2132 die "Cannot overwrite file: $path";
2133 }
2134}
2135
2136#
2113# copy() wrapper with error handling2137# copy() wrapper with error handling
2114#2138#
2115sub copy_file {2139sub copy_file {
@@ -2358,10 +2382,12 @@
23582382
2359 # check that original data directories exist and they are empty2383 # check that original data directories exist and they are empty
2360 if_directory_exists_and_empty($orig_datadir, "Original data");2384 if_directory_exists_and_empty($orig_datadir, "Original data");
2361 if_directory_exists_and_empty($orig_ibdata_dir, "Original InnoDB data");2385 if ($orig_ibdata_dir) {
2362 if_directory_exists_and_empty($orig_iblog_dir, "Original InnoDB log");2386 if_directory_exists($orig_ibdata_dir, "Original InnoDB data");
2387 }
2388 if_directory_exists($orig_iblog_dir, "Original InnoDB log");
2363 if ($orig_undo_dir) {2389 if ($orig_undo_dir) {
2364 if_directory_exists_and_empty($orig_undo_dir,2390 if_directory_exists($orig_undo_dir,
2365 "Original undo directory");2391 "Original undo directory");
2366 }2392 }
23672393
@@ -2421,7 +2447,17 @@
2421 foreach my $c (parse_innodb_data_file_path($orig_innodb_data_file_path)) {2447 foreach my $c (parse_innodb_data_file_path($orig_innodb_data_file_path)) {
2422 # get the relative pathname of a data file2448 # get the relative pathname of a data file
2423 $src_name = escape_path("$backup_dir/$c->{filename}");2449 $src_name = escape_path("$backup_dir/$c->{filename}");
2424 $dst_name = escape_path("$orig_ibdata_dir/$c->{path}");2450 if ($orig_ibdata_dir) {
2451 $dst_name = escape_path("$orig_ibdata_dir/$c->{path}");
2452 } else {
2453 # If innodb_data_home_dir is empty, but file path(s) in
2454 # innodb_data_file_path are relative, InnoDB treats them as if
2455 # innodb_data_home_dir was the same as datadir.
2456
2457 my $dst_root = ($c->{path} =~ /^\//) ? "" : $orig_datadir;
2458 $dst_name = escape_path("$dst_root/$c->{path}");
2459 }
2460 die_if_exists($dst_name);
2425 &$move_or_copy_file($src_name, $dst_name);2461 &$move_or_copy_file($src_name, $dst_name);
2426 }2462 }
24272463
@@ -2435,7 +2471,8 @@
2435 while (defined($file = readdir(DIR))) {2471 while (defined($file = readdir(DIR))) {
2436 if ($file =~ /^$ibundo_files$/ && -f "$backup_dir/$file") {2472 if ($file =~ /^$ibundo_files$/ && -f "$backup_dir/$file") {
2437 $src_name = escape_path("$backup_dir/$file");2473 $src_name = escape_path("$backup_dir/$file");
2438 $dst_name = escape_path("$orig_undo_dir");2474 $dst_name = escape_path("$orig_undo_dir/$file");
2475 die_if_exists($dst_name);
2439 &$move_or_copy_file($src_name, $dst_name);2476 &$move_or_copy_file($src_name, $dst_name);
2440 }2477 }
2441 }2478 }
@@ -2450,7 +2487,8 @@
2450 while (defined($file = readdir(DIR))) {2487 while (defined($file = readdir(DIR))) {
2451 if ($file =~ /^$iblog_files$/ && -f "$backup_dir/$file") {2488 if ($file =~ /^$iblog_files$/ && -f "$backup_dir/$file") {
2452 $src_name = escape_path("$backup_dir/$file");2489 $src_name = escape_path("$backup_dir/$file");
2453 $dst_name = escape_path("$orig_iblog_dir");2490 $dst_name = escape_path("$orig_iblog_dir/$file");
2491 die_if_exists($dst_name);
2454 &$move_or_copy_file($src_name, $dst_name);2492 &$move_or_copy_file($src_name, $dst_name);
2455 }2493 }
2456 }2494 }
24572495
=== added file 'test/t/bug1049291.sh'
--- test/t/bug1049291.sh 1970-01-01 00:00:00 +0000
+++ test/t/bug1049291.sh 2013-11-19 11:58:36 +0000
@@ -0,0 +1,23 @@
1########################################################################
2# Bug #1049291: innobackupex --copy-back fails with an empty
3# innodb-data-home-dir
4########################################################################
5
6MYSQLD_EXTRA_MY_CNF_OPTS="
7innodb_data_home_dir=
8"
9start_server
10
11innobackupex --no-timestamp $topdir/backup
12
13stop_server
14
15rm -rf $MYSQLD_DATADIR/*
16
17innobackupex --apply-log $topdir/backup
18
19innobackupex --copy-back $topdir/backup
20
21test -f $MYSQLD_DATADIR/ibdata1
22
23rm -rf $MYSQLD_DATADIR
024
=== added file 'test/t/bug382742.sh'
--- test/t/bug382742.sh 1970-01-01 00:00:00 +0000
+++ test/t/bug382742.sh 2013-11-19 11:58:36 +0000
@@ -0,0 +1,41 @@
1########################################################################
2# Bug #382742: Absolute paths in innodb_data_file_path are not supported
3########################################################################
4
5# Use this as an absolute path prefix in innodb_data_file_path
6innodb_data_home_dir=$TEST_VAR_ROOT/innodb_data_home_dir
7
8mkdir $innodb_data_home_dir
9
10MYSQLD_EXTRA_MY_CNF_OPTS="
11innodb_file_per_table=0
12innodb_data_home_dir=/
13innodb_data_file_path=$innodb_data_home_dir/ibdata1:3M;$innodb_data_home_dir/ibdata2:10M:autoextend
14"
15
16start_server
17
18test -f $innodb_data_home_dir/ibdata1
19test -f $innodb_data_home_dir/ibdata2
20
21$MYSQL $MYSQL_ARGS -e "CREATE TABLE test.t(a INT)"
22
23record_db_state test
24
25innobackupex --no-timestamp $topdir/backup
26
27stop_server
28
29rm -rf $MYSQLD_DATADIR/*
30rm -rf $innodb_data_home_dir/*
31
32innobackupex --apply-log $topdir/backup
33
34innobackupex --copy-back $topdir/backup
35
36test -f $innodb_data_home_dir/ibdata1
37test -f $innodb_data_home_dir/ibdata2
38
39start_server
40
41verify_db_state test

Subscribers

People subscribed via source and target branches

to all changes: