Merge lp:~akopytov/percona-xtrabackup/bug759701-1.7 into lp:percona-xtrabackup/2.0

Proposed by Alexey Kopytov
Status: Merged
Approved by: Stewart Smith
Approved revision: no longer in the source branch.
Merged at revision: 390
Proposed branch: lp:~akopytov/percona-xtrabackup/bug759701-1.7
Merge into: lp:percona-xtrabackup/2.0
Diff against target: 372 lines (+159/-69)
9 files modified
innobackupex (+83/-62)
test/t/bug723097.sh (+1/-1)
test/t/bug759701.sh (+69/-0)
test/t/ib_incremental.sh (+1/-1)
test/t/xb_export.sh (+1/-1)
test/t/xb_incremental.sh (+1/-1)
test/t/xb_incremental_compressed.sh (+1/-1)
test/t/xb_part_range.sh (+1/-1)
test/t/xb_partial.sh (+1/-1)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/bug759701-1.7
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Review via email: mp+86602@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) wrote :
Revision history for this message
Stewart Smith (stewart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'innobackupex'
2--- innobackupex 2011-12-17 03:23:36 +0000
3+++ innobackupex 2011-12-21 18:48:30 +0000
4@@ -15,6 +15,8 @@
5 use FileHandle;
6 use File::Basename;
7 use File::Temp;
8+use File::Find;
9+use File::Copy;
10 use English qw(-no_match_vars);
11
12 # version of this script
13@@ -208,6 +210,11 @@
14 my $xtrabackup_binary_file = 'xtrabackup_binary';
15 my %rsync_files_hash;
16
17+my $copy_dir_src;
18+my $copy_dir_dst;
19+my $copy_dir_exclude_regexp;
20+my $copy_dir_overwrite;
21+
22 ######################################################################
23 # program execution begins here
24 ######################################################################
25@@ -519,6 +526,58 @@
26 }
27
28 #
29+# Callback function for copy_dir_recursively that actually does all
30+# the copying work
31+#
32+sub copy_file() {
33+ if (/$copy_dir_exclude_regexp/) {
34+ return;
35+ }
36+ (my $dst_path = $File::Find::name) =~ s/^$copy_dir_src/$copy_dir_dst/;
37+ if (-d "$File::Find::name") {
38+ # Create the directory in the destination if necessary
39+ if (! -e "$dst_path") {
40+ print STDERR "$prefix Creating directory '$dst_path'\n";
41+ mkdir "$dst_path" or Die "mkdir failed: $!";
42+ } elsif (! -d "$dst_path") {
43+ Die "$dst_path exists, but is not a directory";
44+ }
45+ } else {
46+ # Don't overwrite files unless $copy_dir_overwrite is 1
47+ if (!$copy_dir_overwrite && -e "$copy_dir_dst/$_") {
48+ Die "Failed to copy file $File::Find::name: " .
49+ "file $copy_dir_dst/$_ exists";
50+ }
51+
52+ print STDERR "$prefix Copying file '$copy_dir_dst/$_'\n";
53+ copy($File::Find::name, $dst_path) or Die "copy failed: $!";
54+ }
55+}
56+
57+#
58+# copy_dir_recursively subroutine does a recursive copy of a specified
59+# directory excluding files matching a specifies regexp. If $overwrite
60+# is 1, it overwrites the existing files.
61+#
62+# SYNOPSIS
63+#
64+# copy_dir_recursively($src_dir, $dst_dir, $exclude_regexp,
65+# $overwrite);
66+#
67+# TODO
68+#
69+# use rsync when --rsync is specified
70+#
71+sub copy_dir_recursively {
72+ $copy_dir_src = shift;
73+ $copy_dir_dst = shift;
74+ $copy_dir_exclude_regexp = shift;
75+ $copy_dir_overwrite = shift;
76+
77+ find(\&copy_file, $copy_dir_src);
78+}
79+
80+#
81 # copy_back subroutine copies data and index files from backup directory
82 # back to their original locations.
83 #
84@@ -530,10 +589,11 @@
85 get_option(\%config, 'mysqld', 'innodb_data_file_path');
86 my $orig_iblog_dir =
87 get_option(\%config, 'mysqld', 'innodb_log_group_home_dir');
88+ my $iblog_files = 'ib_logfile.*';
89 my $excluded_files =
90- '^(\.\.?|backup-my\.cnf|xtrabackup_logfile|mysql-std(err|out)|.*\.ibz)$';
91- my @ibdata_files;
92- my $iblog_files = '^ib_logfile.*$';
93+ '\.\.?|backup-my\.cnf|xtrabackup_logfile|' .
94+ 'xtrabackup_binary|xtrabackup_binlog_info|xtrabackup_checkpoints' .
95+ $iblog_files;
96 my $compressed_data_file = '.*\.ibz$';
97 my $file;
98 my $backup_innodb_data_file_path;
99@@ -573,59 +633,20 @@
100 Die "Backup data file '$backup_dir/$filename' does not exist.";
101 }
102 }
103-
104- if (!is_in_array($filename, \@ibdata_files)) {
105- push(@ibdata_files, $filename);
106- }
107+
108+ $excluded_files .= "|\Q$filename\E";
109 }
110
111 # copy files from backup dir to their original locations
112
113 # copy files to original data directory
114- opendir(DIR, $backup_dir)
115- || Die "Can't open directory '$backup_dir': $!\n";
116- print STDERR "$prefix Starting to copy MyISAM tables, indexes,\n";
117- print STDERR "$prefix .MRG, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV, .opt, and .frm files\n";
118- print STDERR "$prefix in '$backup_dir'\n";
119+ my $excluded_regexp = '^(' . $excluded_files . ')$';
120+ print STDERR "$prefix Starting to copy files in '$backup_dir'\n";
121 print STDERR "$prefix back to original data directory '$orig_datadir'\n";
122- while (defined($file = readdir(DIR))) {
123- if ($file =~ /$excluded_files/) { next; }
124- if (is_in_array($file, \@ibdata_files)) { next; }
125- if ($file =~ /$iblog_files/) { next; }
126- if (-d "$backup_dir/$file") {
127- my $subdir = "$backup_dir/$file";
128- my $file2;
129-
130- print STDERR "$prefix Copying directory '$subdir'\n";
131- if (! -x "\"".escape_path("$orig_datadir/$file")."\"") {
132- system("mkdir \"".escape_path("$orig_datadir/$file")."\"")
133- and Die "Failed to create directory "
134- . "'$orig_datadir/$file' : $!";
135- }
136- opendir(SUBDIR, "$subdir")
137- || Die "Can't open directory '$subdir': $!\n";
138- while (defined($file2 = readdir(SUBDIR))) {
139- if (-d "$subdir/$file2") { next; }
140- if ($file2 =~ /$compressed_data_file/) { next; }
141- $src_name = escape_path("$subdir/$file2");
142- $dst_name = escape_path("$orig_datadir/$file");
143- system("$CP_CMD \"$src_name\" \"$dst_name\"")
144- and Die "Failed to copy file '$file': $!";
145- }
146- closedir(SUBDIR);
147- } else {
148- print STDERR "$prefix Copying file " .
149- "'$backup_dir/$file'\n";
150- $src_name = escape_path("$backup_dir/$file");
151- $dst_name = escape_path("$orig_datadir");
152- system("$CP_CMD \"$src_name\" \"$dst_name\"")
153- and Die "Failed to copy file '$file': $!";
154- }
155- }
156- closedir(DIR);
157+ copy_dir_recursively($backup_dir, $orig_datadir, $excluded_regexp, 0);
158
159 # copy InnoDB data files to original InnoDB data directory
160- print STDERR "\n$prefix Starting to copy InnoDB tables and indexes\n";
161+ print STDERR "\n$prefix Starting to copy InnoDB system tablespace\n";
162 print STDERR "$prefix in '$backup_dir'\n";
163 print STDERR "$prefix back to original InnoDB data directory '$orig_ibdata_dir'\n";
164 foreach my $a (split(/;/, $orig_innodb_data_file_path)) {
165@@ -646,7 +667,7 @@
166 print STDERR "$prefix in '$backup_dir'\n";
167 print STDERR "$prefix back to original InnoDB log directory '$orig_iblog_dir'\n";
168 while (defined($file = readdir(DIR))) {
169- if ($file =~ /$iblog_files/ && -f "$backup_dir/$file") {
170+ if ($file =~ /'^' . $iblog_files . '$'/ && -f "$backup_dir/$file") {
171 print STDERR "$prefix Copying file '$backup_dir/$file'\n";
172 $src_name = escape_path("$backup_dir/$file");
173 $dst_name = escape_path("$orig_iblog_dir");
174@@ -714,20 +735,20 @@
175 }
176 }
177
178- # If we were applying an incremental change set, we need to make sure the xtrabackup_slave_info is still correct
179+ # If we were applying an incremental change set, we need to make
180+ # sure non-InnoDB files and xtrabackup_* metainfo files are copied
181+ # to the full backup directory.
182 if ( $option_incremental_dir ) {
183-
184- # If the latest backup has this file, then update the target dir with the new file
185- if ( -e "$option_incremental_dir/xtrabackup_slave_info" ) {
186- print STDERR "\n$now $prefix Updating xtrabackup_slave_info with new slave position info...";
187- $cmdline = "cp $option_incremental_dir/xtrabackup_slave_info $backup_dir/xtrabackup_slave_info";
188- $rcode = system("$cmdline");
189- if ($rcode) {
190- # failure
191- Die "\n$prefix Failed to update xtrabackup_slave_info in $backup_dir";
192- }
193- # If the latest backup has no file, we need to remove the old xtrabackup_slave_info file, because it is out of date
194- } elsif ( -e "$backup_dir/xtrabackup_slave_info" ) {
195+ print STDERR "$prefix Starting to copy non-InnoDB files in '$option_incremental_dir'\n";
196+ print STDERR "$prefix to the full backup directory '$backup_dir'\n";
197+ copy_dir_recursively($option_incremental_dir, $backup_dir,
198+ '^(\.\.?|backup-my\.cnf|xtrabackup_logfile|' .
199+ 'xtrabackup_binary|xtrabackup_checkpoints|' .
200+ '.*\.delta|.*\.meta|ib_logfile.*)$', 1);
201+ # If the latest backup has no file, we need to remove the old
202+ # xtrabackup_slave_info file, because it is out of date
203+ # TODO: this will not be needed when bug #856400 is fixed.
204+ if ( -e "$backup_dir/xtrabackup_slave_info" ) {
205 print STDERR "\n$now $prefix No updated xtrabackup_slave_info found in incremental dir, removing stale xtrabackup_slave_info file from target dir.";
206 $cmdline = "rm $backup_dir/xtrabackup_slave_info";
207 $rcode = system("$cmdline");
208
209=== modified file 'test/t/bug723097.sh'
210--- test/t/bug723097.sh 2011-09-14 17:41:10 +0000
211+++ test/t/bug723097.sh 2011-12-21 18:48:30 +0000
212@@ -27,7 +27,7 @@
213 checksum_b=`checksum_table test messages`
214 vlog "Checksum after is $checksum_b"
215
216-if [ $checksum_a -eq $checksum_b ]
217+if [ "$checksum_a" -eq "$checksum_b" ]
218 then
219 vlog "Checksums are Ok"
220 else
221
222=== added file 'test/t/bug759701.sh'
223--- test/t/bug759701.sh 1970-01-01 00:00:00 +0000
224+++ test/t/bug759701.sh 2011-12-21 18:48:30 +0000
225@@ -0,0 +1,69 @@
226+##########################################################################
227+# Bug #759701: innobackupex does not copy non-InnoDB files when applying #
228+# incremental backups #
229+##########################################################################
230+. inc/common.sh
231+
232+init
233+run_mysqld --innodb_file_per_table
234+load_sakila
235+
236+# Full backup
237+# backup root directory
238+vlog "Starting backup"
239+
240+full_backup_dir=$topdir/full_backup
241+innobackupex --no-timestamp $full_backup_dir
242+
243+# Changing data
244+
245+run_cmd $MYSQL $MYSQL_ARGS -e "CREATE DATABASE newdb"
246+run_cmd $MYSQL $MYSQL_ARGS -e \
247+ "CREATE TABLE actor_copy ENGINE=MyISAM SELECT * FROM sakila.actor" newdb
248+
249+# Saving the checksum of original table
250+checksum_a=`checksum_table newdb actor_copy`
251+test -n "$checksum_a" || die "Failed to checksum table actor_copy"
252+
253+vlog "Making incremental backup"
254+
255+# Incremental backup
256+inc_backup_dir=$topdir/incremental_backup
257+innobackupex --incremental --no-timestamp \
258+ --incremental-basedir=$full_backup_dir $inc_backup_dir
259+vlog "Incremental backup created in directory $inc_backup_dir"
260+
261+vlog "Preparing backup"
262+innobackupex --apply-log --redo-only $full_backup_dir
263+vlog "Log applied to full backup"
264+
265+innobackupex --apply-log --redo-only --incremental-dir=$inc_backup_dir \
266+ $full_backup_dir
267+vlog "Delta applied to full backup"
268+
269+innobackupex --apply-log $full_backup_dir
270+vlog "Data prepared for restore"
271+
272+# Destroying mysql data
273+stop_mysqld
274+rm -rf $mysql_datadir/*
275+vlog "Data destroyed"
276+
277+# Restore backup
278+vlog "Copying files to their original locations"
279+innobackupex --copy-back $full_backup_dir
280+vlog "Data restored"
281+
282+run_mysqld --innodb_file_per_table
283+
284+vlog "Checking checksums"
285+checksum_b=`checksum_table newdb actor_copy`
286+
287+vlog "Old checksum: $checksum_a"
288+vlog "New checksum: $checksum_b"
289+
290+if [ "$checksum_a" != "$checksum_b" ]
291+then
292+ vlog "Checksums do not match"
293+ exit -1
294+fi
295
296=== modified file 'test/t/ib_incremental.sh'
297--- test/t/ib_incremental.sh 2011-09-14 17:41:10 +0000
298+++ test/t/ib_incremental.sh 2011-12-21 18:48:30 +0000
299@@ -89,7 +89,7 @@
300 vlog "Checking checksums"
301 checksum_b=`checksum_table incremental_sample test`
302
303-if [ $checksum_a -ne $checksum_b ]
304+if [ "$checksum_a" != "$checksum_b" ]
305 then
306 vlog "Checksums are not equal"
307 exit -1
308
309=== modified file 'test/t/xb_export.sh'
310--- test/t/xb_export.sh 2011-09-14 17:41:10 +0000
311+++ test/t/xb_export.sh 2011-12-21 18:48:30 +0000
312@@ -123,7 +123,7 @@
313 checksum_3=`checksum_table incremental_sample test`
314 vlog "checksum_3 is $checksum_3"
315
316-if [ "$checksum_3" != $checksum_2 ]
317+if [ "$checksum_3" != "$checksum_2" ]
318 then
319 vlog "Checksums are not equal"
320 exit -1
321
322=== modified file 'test/t/xb_incremental.sh'
323--- test/t/xb_incremental.sh 2011-09-14 17:41:10 +0000
324+++ test/t/xb_incremental.sh 2011-12-21 18:48:30 +0000
325@@ -85,7 +85,7 @@
326 vlog "Checking checksums"
327 checksum_b=`checksum_table incremental_sample test`
328
329-if [ $checksum_a -ne $checksum_b ]
330+if [ "$checksum_a" != "$checksum_b" ]
331 then
332 vlog "Checksums are not equal"
333 exit -1
334
335=== modified file 'test/t/xb_incremental_compressed.sh'
336--- test/t/xb_incremental_compressed.sh 2011-09-14 17:41:10 +0000
337+++ test/t/xb_incremental_compressed.sh 2011-12-21 18:48:30 +0000
338@@ -149,7 +149,7 @@
339 vlog "Cheking checksums"
340 checksum_b=`checksum_table incremental_sample test`
341
342- if [ $checksum_a -ne $checksum_b ]
343+ if [ "$checksum_a" != "$checksum_b" ]
344 then
345 vlog "Checksums are not equal"
346 exit -1
347
348=== modified file 'test/t/xb_part_range.sh'
349--- test/t/xb_part_range.sh 2011-09-14 17:41:10 +0000
350+++ test/t/xb_part_range.sh 2011-12-21 18:48:30 +0000
351@@ -104,7 +104,7 @@
352 vlog "Cheking checksums"
353 checksum_b=`checksum_table test test`
354
355-if [ $checksum_a -ne $checksum_b ]
356+if [ "$checksum_a" != "$checksum_b" ]
357 then
358 vlog "Checksums are not equal"
359 exit -1
360
361=== modified file 'test/t/xb_partial.sh'
362--- test/t/xb_partial.sh 2011-09-14 17:41:10 +0000
363+++ test/t/xb_partial.sh 2011-12-21 18:48:30 +0000
364@@ -44,7 +44,7 @@
365 vlog "Checking checksums"
366 checksum_b=`checksum_table incremental_sample test`
367
368-if [ $checksum_a -ne $checksum_b ]
369+if [ "$checksum_a" != "$checksum_b" ]
370 then
371 vlog "Checksums are not equal"
372 exit -1

Subscribers

People subscribed via source and target branches