Merge lp:~akopytov/percona-xtrabackup/rsync-for-non-innodb-files-1.6 into lp:percona-xtrabackup/1.6

Proposed by Alexey Kopytov
Status: Merged
Approved by: Stewart Smith
Approved revision: no longer in the source branch.
Merged at revision: 306
Proposed branch: lp:~akopytov/percona-xtrabackup/rsync-for-non-innodb-files-1.6
Merge into: lp:percona-xtrabackup/1.6
Prerequisite: lp:~akopytov/percona-xtrabackup/bug408803-1.6
Diff against target: 214 lines (+124/-8)
2 files modified
innobackupex (+98/-8)
test/t/ib_rsync.sh (+26/-0)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/rsync-for-non-innodb-files-1.6
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Review via email: mp+82278@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-11-15 14:09:24 +0000
3+++ innobackupex 2011-11-15 14:09:24 +0000
4@@ -93,6 +93,7 @@
5 my $option_incremental_lsn = '';
6 my $option_extra_lsndir = '';
7 my $option_remote_host = '';
8+my $option_rsync = '';
9 my $option_stream = '';
10 my $option_tmpdir = '';
11
12@@ -203,6 +204,8 @@
13 my $win = ($^O eq 'MSWin32' ? 1 : 0);
14 my $CP_CMD = ($win eq 1 ? "copy /Y" : "cp -p");
15 my $xtrabackup_binary_file = 'xtrabackup_binary';
16+my %rsync_files_hash;
17+
18 ######################################################################
19 # program execution begins here
20 ######################################################################
21@@ -365,10 +368,12 @@
22 wait_for_safe_slave();
23 }
24
25- if (!$option_incremental) {
26+ if (!$option_incremental && !$option_no_lock) {
27+ # make a prep copy before locking tables, if using rsync
28+ backup_files(1);
29+
30 # flush tables with read lock
31- mysql_lockall() if !$option_no_lock;
32-
33+ mysql_lockall();
34 }
35
36 if ($option_slave_info) {
37@@ -377,7 +382,8 @@
38
39
40 # backup .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV and .opt files
41- backup_files();
42+ # (or finalize the backup by syncing changes if using rsync)
43+ backup_files(0);
44
45 # resume ibbackup and wait till it has finished
46 my $ibbackup_exit_code = resume_ibbackup();
47@@ -1603,6 +1609,7 @@
48 'extra-lsndir=s' => \$option_extra_lsndir,
49 'remote-host=s' => \$option_remote_host,
50 'stream=s' => \$option_stream,
51+ 'rsync' => \$option_rsync,
52 'tmpdir=s' => \$option_tmpdir,
53 'no-lock' => \$option_no_lock,
54 'ibbackup=s' => \$option_ibbackup_binary,
55@@ -1700,6 +1707,11 @@
56 }
57 }
58
59+ if ($option_rsync && ($option_remote_host || $option_stream)) {
60+ print STDERR "--rsync doesn't work with --remote-host or --stream\n";
61+ exit(1);
62+ }
63+
64 print STDERR "\n";
65
66 parse_databases_option_value();
67@@ -1805,16 +1817,43 @@
68 # backup directory.
69 #
70 sub backup_files {
71+ my $prep_mode = shift;
72 my $source_dir = get_option(\%config, 'mysqld', 'datadir');
73 my @list;
74 my $file;
75 my $database;
76 my $wildcard = '*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}';
77+ my $rsync_file_list;
78+ my $operation;
79+ my $rsync_tmpfile_pass1 = "$option_tmpdir/xtrabackup_rsyncfiles_pass1";
80+ my $rsync_tmpfile_pass2 = "$option_tmpdir/xtrabackup_rsyncfiles_pass2";
81+
82+ # prep_mode will pre-copy the data, so that rsync is faster the 2nd time
83+ # saving time while all tables are locked.
84+ # currently only rsync mode is supported for prep.
85+ if ($prep_mode and !$option_rsync) {
86+ return;
87+ }
88+
89+ if ($option_rsync) {
90+ if ($prep_mode) {
91+ $rsync_file_list = $rsync_tmpfile_pass1;
92+ } else {
93+ $rsync_file_list = $rsync_tmpfile_pass2;
94+ }
95+ open(RSYNC, ">$rsync_file_list")
96+ || Die "Can't open $rsync_file_list for writing: $!\n";
97+ }
98
99 opendir(DIR, $source_dir)
100 || Die "Can't open directory '$source_dir': $!\n";
101 $now = current_time();
102- print STDERR "\n$now $prefix Starting to backup .frm, .MRG, .MYD, .MYI,\n";
103+ if ($prep_mode) {
104+ $operation = "a prep copy of";
105+ } else {
106+ $operation = "to backup";
107+ }
108+ print STDERR "\n$now $prefix Starting $operation .frm, .MRG, .MYD, .MYI,\n";
109 print STDERR "$prefix .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV and .opt files in\n";
110 print STDERR "$prefix subdirectories of '$source_dir'\n";
111 # loop through all database directories
112@@ -1865,7 +1904,13 @@
113 if ($print_each_file) {
114 print STDERR "$prefix Backing up file '$source_dir/$database/$file'\n";
115 }
116- if (!$option_remote_host && !$option_stream) {
117+
118+ if ($option_rsync) {
119+ print RSYNC "$database/$file\n";
120+ if (!$prep_mode) {
121+ $rsync_files_hash{"$database/$file"} = 1;
122+ }
123+ } elsif (!$option_remote_host && !$option_stream) {
124 $src_name = escape_path("$source_dir/$database/$file");
125 $dst_name = escape_path("$backup_dir/$database");
126 system("$CP_CMD \"$src_name\" \"$dst_name\"")
127@@ -1901,9 +1946,54 @@
128 }
129 closedir(DIR);
130
131+ if ($option_rsync) {
132+ close(RSYNC);
133+
134+ # do the actual rsync now
135+ $now = current_time();
136+ my $rsync_cmd = "rsync -t \"$source_dir\" --files-from=\"$rsync_file_list\" \"$backup_dir\"";
137+ print STDERR "$now Starting rsync as: $rsync_cmd\n";
138+
139+ # ignore errors in the prep mode, since we are running without lock,
140+ # so some files may have disappeared.
141+ if (system("$rsync_cmd") && !$prep_mode) {
142+ Die "rsync failed: $!\n";
143+ }
144+
145+ $now = current_time();
146+ print STDERR "$now rsync finished successfully.\n";
147+
148+ # Remove from $backup_dir files that have been removed between first and
149+ # second passes. Cannot use "rsync --delete" because it does not work
150+ # with --files-from.
151+ if (!$prep_mode) {
152+ open(RSYNC, "<$rsync_tmpfile_pass1")
153+ || Die "Can't open $rsync_tmpfile_pass1 for reading: $!\n";
154+
155+ while (<RSYNC>) {
156+ chomp;
157+ if (!exists $rsync_files_hash{$_}) {
158+ print STDERR "Removing '$backup_dir/$_'\n";
159+ unlink "$backup_dir/$_";
160+ }
161+ }
162+
163+ close(RSYNC);
164+ unlink "$rsync_tmpfile_pass1" || \
165+ Die "Failed to delete $rsync_tmpfile_pass1: $!";
166+ unlink "$rsync_tmpfile_pass2" || \
167+ Die "Failed to delete $rsync_tmpfile_pass2: $!";
168+ }
169+ }
170+
171+ if ($prep_mode) {
172+ $operation = "a prep copy of";
173+ } else {
174+ $operation = "backing up";
175+ }
176 $now = current_time();
177- print STDERR "$now $prefix Finished backing up .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSV, .CSM and .opt files\n\n";
178-}
179+ print STDERR "$now $prefix Finished $operation .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSV, .CSM and .opt files\n\n";
180+ }
181
182
183 #
184
185=== added file 'test/t/ib_rsync.sh'
186--- test/t/ib_rsync.sh 1970-01-01 00:00:00 +0000
187+++ test/t/ib_rsync.sh 2011-11-15 14:09:24 +0000
188@@ -0,0 +1,26 @@
189+. inc/common.sh
190+
191+if ! which rsync > /dev/null 2>&1
192+then
193+ echo "Requires rsync to be installed" > $SKIPPED_REASON
194+ exit $SKIPPED_EXIT_CODE
195+fi
196+
197+init
198+run_mysqld --innodb_file_per_table
199+load_sakila
200+
201+innobackupex --rsync --no-timestamp $topdir/backup
202+
203+stop_mysqld
204+
205+run_cmd rm -r $mysql_datadir
206+
207+innobackupex --apply-log $topdir/backup
208+
209+run_cmd mkdir -p $mysql_datadir
210+
211+innobackupex --copy-back $topdir/backup
212+
213+run_mysqld
214+run_cmd ${MYSQL} ${MYSQL_ARGS} -e "SELECT COUNT(*) FROM actor" sakila

Subscribers

People subscribed via source and target branches