1 /******************************************************
2 hot backup tool for InnoDB
3 (c) 2009-2015 Percona LLC and/or its affiliates
4 Originally Created 3/3/2009 Yasufumi Kinoshita
5 Written by Alexey Kopytov, Aleksandr Kuzminsky, Stewart Smith, Vadim Tkachenko,
6 Yasufumi Kinoshita, Ignacio Nin and Baron Schwartz.
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1335  USA
20 
21 *******************************************************
22 
23 This file incorporates work covered by the following copyright and
24 permission notice:
25 
26 Copyright (c) 2000, 2011, MySQL AB & Innobase Oy. All Rights Reserved.
27 
28 This program is free software; you can redistribute it and/or modify it under
29 the terms of the GNU General Public License as published by the Free Software
30 Foundation; version 2 of the License.
31 
32 This program is distributed in the hope that it will be useful, but WITHOUT
33 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
35 
36 You should have received a copy of the GNU General Public License along with
37 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
38 Street, Fifth Floor, Boston, MA 02110-1335 USA
39 
40 *******************************************************/
41 
42 #include <my_global.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include <mysql.h>
46 #include <my_dir.h>
47 #include <ut0mem.h>
48 #include <os0file.h>
49 #include <srv0start.h>
50 #include <algorithm>
51 #include <mysqld.h>
52 #include <my_default.h>
53 #include <my_getopt.h>
54 #include <string>
55 #include <sstream>
56 #include <set>
57 #include "common.h"
58 #include "innobackupex.h"
59 #include "xtrabackup.h"
60 #include "xbstream.h"
61 #include "fil_cur.h"
62 #include "write_filt.h"
63 #include "backup_copy.h"
64 
65 using std::min;
66 using std::max;
67 
68 /* options */
69 my_bool opt_ibx_version = FALSE;
70 my_bool opt_ibx_help = FALSE;
71 my_bool opt_ibx_apply_log = FALSE;
72 my_bool opt_ibx_incremental = FALSE;
73 my_bool opt_ibx_notimestamp = FALSE;
74 
75 my_bool opt_ibx_copy_back = FALSE;
76 my_bool opt_ibx_move_back = FALSE;
77 my_bool opt_ibx_galera_info = FALSE;
78 my_bool opt_ibx_slave_info = FALSE;
79 my_bool opt_ibx_no_lock = FALSE;
80 my_bool opt_ibx_safe_slave_backup = FALSE;
81 my_bool opt_ibx_rsync = FALSE;
82 my_bool opt_ibx_force_non_empty_dirs = FALSE;
83 my_bool opt_ibx_noversioncheck = FALSE;
84 my_bool opt_ibx_no_backup_locks = FALSE;
85 my_bool opt_ibx_decompress = FALSE;
86 
87 char *opt_ibx_incremental_history_name = NULL;
88 char *opt_ibx_incremental_history_uuid = NULL;
89 
90 char *opt_ibx_user = NULL;
91 const char *opt_ibx_password = NULL;
92 char *opt_ibx_host = NULL;
93 char *opt_ibx_defaults_group = NULL;
94 char *opt_ibx_socket = NULL;
95 uint opt_ibx_port = 0;
96 
97 ulong opt_ibx_lock_wait_query_type;
98 ulong opt_ibx_kill_long_query_type;
99 
100 uint opt_ibx_kill_long_queries_timeout = 0;
101 uint opt_ibx_lock_wait_timeout = 0;
102 uint opt_ibx_lock_wait_threshold = 0;
103 uint opt_ibx_debug_sleep_before_unlock = 0;
104 uint opt_ibx_safe_slave_backup_timeout = 0;
105 
106 const char *opt_ibx_history = NULL;
107 
108 char *opt_ibx_include = NULL;
109 char *opt_ibx_databases = NULL;
110 bool ibx_partial_backup = false;
111 
112 char *ibx_position_arg = NULL;
113 char *ibx_backup_directory = NULL;
114 
115 extern bool xb_opt_destroy_password;
116 
117 /* copy of proxied xtrabackup options */
118 my_bool ibx_xb_close_files;
119 const char *ibx_xtrabackup_compress_alg;
120 uint ibx_xtrabackup_compress_threads;
121 ulonglong ibx_xtrabackup_compress_chunk_size;
122 my_bool ibx_xtrabackup_export;
123 char *ibx_xtrabackup_extra_lsndir;
124 char *ibx_xtrabackup_incremental_basedir;
125 char *ibx_xtrabackup_incremental_dir;
126 my_bool	ibx_xtrabackup_incremental_force_scan;
127 ulint ibx_xtrabackup_log_copy_interval;
128 char *ibx_xtrabackup_incremental;
129 int ibx_xtrabackup_parallel;
130 char *ibx_xtrabackup_stream_str;
131 char *ibx_xtrabackup_tables_file;
132 long ibx_xtrabackup_throttle;
133 char *ibx_opt_mysql_tmpdir;
134 longlong ibx_xtrabackup_use_memory;
135 
136 
137 static inline int ibx_msg(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
ibx_msg(const char * fmt,...)138 static inline int ibx_msg(const char *fmt, ...)
139 {
140 	int	result;
141 	time_t	t = time(NULL);
142 	char	date[100];
143 	char	*line;
144 	va_list args;
145 
146 	strftime(date, sizeof(date), "%y%m%d %H:%M:%S", localtime(&t));
147 
148 	va_start(args, fmt);
149 
150 	result = vasprintf(&line, fmt, args);
151 
152 	va_end(args);
153 
154 	if (result != -1) {
155 		result = fprintf(stderr, "%s %s: %s",
156 					date, INNOBACKUPEX_BIN_NAME, line);
157 		free(line);
158 	}
159 
160 	return result;
161 }
162 
163 enum innobackupex_options
164 {
165 	OPT_APPLY_LOG = 256,
166 	OPT_COPY_BACK,
167 	OPT_MOVE_BACK,
168 	OPT_REDO_ONLY,
169 	OPT_GALERA_INFO,
170 	OPT_SLAVE_INFO,
171 	OPT_INCREMENTAL,
172 	OPT_INCREMENTAL_HISTORY_NAME,
173 	OPT_INCREMENTAL_HISTORY_UUID,
174 	OPT_LOCK_WAIT_QUERY_TYPE,
175 	OPT_KILL_LONG_QUERY_TYPE,
176 	OPT_KILL_LONG_QUERIES_TIMEOUT,
177 	OPT_LOCK_WAIT_TIMEOUT,
178 	OPT_LOCK_WAIT_THRESHOLD,
179 	OPT_DEBUG_SLEEP_BEFORE_UNLOCK,
180 	OPT_NO_LOCK,
181 	OPT_SAFE_SLAVE_BACKUP,
182 	OPT_SAFE_SLAVE_BACKUP_TIMEOUT,
183 	OPT_RSYNC,
184 	OPT_HISTORY,
185 	OPT_INCLUDE,
186 	OPT_FORCE_NON_EMPTY_DIRS,
187 	OPT_NO_TIMESTAMP,
188 	OPT_NO_VERSION_CHECK,
189 	OPT_NO_BACKUP_LOCKS,
190 	OPT_DATABASES,
191 	OPT_DECOMPRESS,
192 
193 	/* options wich are passed directly to xtrabackup */
194 	OPT_CLOSE_FILES,
195 	OPT_COMPACT,
196 	OPT_COMPRESS,
197 	OPT_COMPRESS_THREADS,
198 	OPT_COMPRESS_CHUNK_SIZE,
199 	OPT_EXPORT,
200 	OPT_EXTRA_LSNDIR,
201 	OPT_INCREMENTAL_BASEDIR,
202 	OPT_INCREMENTAL_DIR,
203 	OPT_INCREMENTAL_FORCE_SCAN,
204 	OPT_LOG_COPY_INTERVAL,
205 	OPT_PARALLEL,
206 	OPT_REBUILD_INDEXES,
207 	OPT_REBUILD_THREADS,
208 	OPT_STREAM,
209 	OPT_TABLES_FILE,
210 	OPT_THROTTLE,
211 	OPT_USE_MEMORY,
212 	OPT_INNODB_FORCE_RECOVERY,
213 };
214 
215 ibx_mode_t ibx_mode = IBX_MODE_BACKUP;
216 
217 static struct my_option ibx_long_options[] =
218 {
219 	{"version", 'v', "print version information",
220 	 (uchar *) &opt_ibx_version, (uchar *) &opt_ibx_version, 0,
221 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
222 
223 	{"help", '?', "This option displays a help screen and exits.",
224 	 (uchar *) &opt_ibx_help, (uchar *) &opt_ibx_help, 0,
225 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
226 
227 	{"apply-log", OPT_APPLY_LOG, "Prepare a backup in BACKUP-DIR by "
228 	"applying the redo log 'ib_logfile0' and creating new redo log. "
229 	"The InnoDB configuration is read from the file \"backup-my.cnf\".",
230 	(uchar*) &opt_ibx_apply_log, (uchar*) &opt_ibx_apply_log,
231 	0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
232 
233 	{"copy-back", OPT_COPY_BACK, "Copy all the files in a previously made "
234 	 "backup from the backup directory to their original locations.",
235 	 (uchar *) &opt_ibx_copy_back, (uchar *) &opt_ibx_copy_back, 0,
236 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
237 
238 	{"move-back", OPT_MOVE_BACK, "Move all the files in a previously made "
239 	 "backup from the backup directory to the actual datadir location. "
240 	 "Use with caution, as it removes backup files.",
241 	 (uchar *) &opt_ibx_move_back, (uchar *) &opt_ibx_move_back, 0,
242 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
243 
244 	{"galera-info", OPT_GALERA_INFO, "This options creates the "
245 	 "xtrabackup_galera_info file which contains the local node state at "
246 	 "the time of the backup. Option should be used when performing the "
247 	 "backup of MariaDB Galera Cluster. Has no effect when backup locks "
248 	 "are used to create the backup.",
249 	 (uchar *) &opt_ibx_galera_info, (uchar *) &opt_ibx_galera_info, 0,
250 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
251 
252 	{"slave-info", OPT_SLAVE_INFO, "This option is useful when backing "
253 	 "up a replication slave server. It prints the binary log position "
254 	 "and name of the master server. It also writes this information to "
255 	 "the \"xtrabackup_slave_info\" file as a \"CHANGE MASTER\" command. "
256 	 "A new slave for this master can be set up by starting a slave server "
257 	 "on this backup and issuing a \"CHANGE MASTER\" command with the "
258 	 "binary log position saved in the \"xtrabackup_slave_info\" file.",
259 	 (uchar *) &opt_ibx_slave_info, (uchar *) &opt_ibx_slave_info, 0,
260 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261 
262 	{"incremental", OPT_INCREMENTAL,
263 	 "Create an incremental backup, rather than a full one. When this option is specified, "
264 	 "either --incremental-lsn or --incremental-basedir can also be given. "
265 	 "If neither option is given, option --incremental-basedir is used "
266 	 "by default, set to the first timestamped backup "
267 	 "directory in the backup base directory.",
268 	 (uchar *) &opt_ibx_incremental, (uchar *) &opt_ibx_incremental, 0,
269 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
270 
271 	{"no-lock", OPT_NO_LOCK, "Use this option to disable table lock "
272 	 "with \"FLUSH TABLES WITH READ LOCK\". Use it only if ALL your "
273 	 "tables are InnoDB and you DO NOT CARE about the binary log "
274 	 "position of the backup. This option shouldn't be used if there "
275 	 "are any DDL statements being executed or if any updates are "
276 	 "happening on non-InnoDB tables (this includes the system MyISAM "
277 	 "tables in the mysql database), otherwise it could lead to an "
278 	 "inconsistent backup. If you are considering to use --no-lock "
279 	 "because your backups are failing to acquire the lock, this could "
280 	 "be because of incoming replication events preventing the lock "
281 	 "from succeeding. Please try using --safe-slave-backup to "
282 	 "momentarily stop the replication slave thread, this may help "
283 	 "the backup to succeed and you then don't need to resort to "
284 	 "using this option.",
285 	 (uchar *) &opt_ibx_no_lock, (uchar *) &opt_ibx_no_lock, 0,
286 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
287 
288 	{"safe-slave-backup", OPT_SAFE_SLAVE_BACKUP, "Stop slave SQL thread "
289 	 "and wait to start backup until Slave_open_temp_tables in "
290 	 "\"SHOW STATUS\" is zero. If there are no open temporary tables, "
291 	 "the backup will take place, otherwise the SQL thread will be "
292 	 "started and stopped until there are no open temporary tables. "
293 	 "The backup will fail if Slave_open_temp_tables does not become "
294 	 "zero after --safe-slave-backup-timeout seconds. The slave SQL "
295 	 "thread will be restarted when the backup finishes.",
296 	 (uchar *) &opt_ibx_safe_slave_backup,
297 	 (uchar *) &opt_ibx_safe_slave_backup,
298 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
299 
300 	{"rsync", OPT_RSYNC, "Uses the rsync utility to optimize local file "
301 	 "transfers. When this option is specified, innobackupex uses rsync "
302 	 "to copy all non-InnoDB files instead of spawning a separate cp for "
303 	 "each file, which can be much faster for servers with a large number "
304 	 "of databases or tables.  This option cannot be used together with "
305 	 "--stream.",
306 	 (uchar *) &opt_ibx_rsync, (uchar *) &opt_ibx_rsync,
307 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
308 
309 	{"force-non-empty-directories", OPT_FORCE_NON_EMPTY_DIRS, "This "
310 	 "option, when specified, makes --copy-back or --move-back transfer "
311 	 "files to non-empty directories. Note that no existing files will be "
312 	 "overwritten. If --copy-back or --move-back has to copy a file from "
313 	 "the backup directory which already exists in the destination "
314 	 "directory, it will still fail with an error.",
315 	 (uchar *) &opt_ibx_force_non_empty_dirs,
316 	 (uchar *) &opt_ibx_force_non_empty_dirs,
317 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
318 
319 	{"no-timestamp", OPT_NO_TIMESTAMP, "This option prevents creation of a "
320 	 "time-stamped subdirectory of the BACKUP-ROOT-DIR given on the "
321 	 "command line. When it is specified, the backup is done in "
322 	 "BACKUP-ROOT-DIR instead.",
323 	 (uchar *) &opt_ibx_notimestamp,
324 	 (uchar *) &opt_ibx_notimestamp,
325 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
326 
327 	{"no-version-check", OPT_NO_VERSION_CHECK, "This option disables the "
328 	 "version check which is enabled by the --version-check option.",
329 	 (uchar *) &opt_ibx_noversioncheck,
330 	 (uchar *) &opt_ibx_noversioncheck,
331 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
332 
333 	{"no-backup-locks", OPT_NO_BACKUP_LOCKS, "This option controls if "
334 	 "backup locks should be used instead of FLUSH TABLES WITH READ LOCK "
335 	 "on the backup stage. The option has no effect when backup locks are "
336 	 "not supported by the server. This option is enabled by default, "
337 	 "disable with --no-backup-locks.",
338 	 (uchar *) &opt_ibx_no_backup_locks,
339 	 (uchar *) &opt_ibx_no_backup_locks,
340 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
341 
342 	{"decompress", OPT_DECOMPRESS, "Decompresses all files with the .qp "
343 	 "extension in a backup previously made with the --compress option.",
344 	 (uchar *) &opt_ibx_decompress,
345 	 (uchar *) &opt_ibx_decompress,
346 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
347 
348 	{"user", 'u', "This option specifies the MySQL username used "
349 	 "when connecting to the server, if that's not the current user. "
350 	 "The option accepts a string argument. See mysql --help for details.",
351 	 (uchar*) &opt_ibx_user, (uchar*) &opt_ibx_user, 0, GET_STR,
352 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
353 
354 	{"host", 'H', "This option specifies the host to use when "
355 	 "connecting to the database server with TCP/IP.  The option accepts "
356 	 "a string argument. See mysql --help for details.",
357 	 (uchar*) &opt_ibx_host, (uchar*) &opt_ibx_host, 0, GET_STR,
358 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
359 
360 	{"port", 'P', "This option specifies the port to use when "
361 	 "connecting to the database server with TCP/IP.  The option accepts "
362 	 "a string argument. See mysql --help for details.",
363 	 &opt_ibx_port, &opt_ibx_port, 0, GET_UINT, REQUIRED_ARG,
364 	 0, 0, 0, 0, 0, 0},
365 
366 	{"password", 'p', "This option specifies the password to use "
367 	 "when connecting to the database. It accepts a string argument.  "
368 	 "See mysql --help for details.",
369 	 0, 0, 0, GET_STR,
370 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
371 
372 	{"socket", 'S', "This option specifies the socket to use when "
373 	 "connecting to the local database server with a UNIX domain socket.  "
374 	 "The option accepts a string argument. See mysql --help for details.",
375 	 (uchar*) &opt_ibx_socket, (uchar*) &opt_ibx_socket, 0, GET_STR,
376 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
377 
378 	{"incremental-history-name", OPT_INCREMENTAL_HISTORY_NAME,
379 	 "This option specifies the name of the backup series stored in the "
380 	 "PERCONA_SCHEMA.xtrabackup_history history record to base an "
381 	 "incremental backup on. Backup will search the history table "
382 	 "looking for the most recent (highest innodb_to_lsn), successful "
383 	 "backup in the series and take the to_lsn value to use as the "
384 	 "starting lsn for the incremental backup. This will be mutually "
385 	 "exclusive with --incremental-history-uuid, --incremental-basedir "
386 	 "and --incremental-lsn. If no valid lsn can be found (no series by "
387 	 "that name, no successful backups by that name), "
388 	 "an error will be returned. It is used with the --incremental option.",
389 	 (uchar*) &opt_ibx_incremental_history_name,
390 	 (uchar*) &opt_ibx_incremental_history_name, 0, GET_STR,
391 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
392 
393 	{"incremental-history-uuid", OPT_INCREMENTAL_HISTORY_UUID,
394 	 "This option specifies the UUID of the specific history record "
395 	 "stored in the PERCONA_SCHEMA.xtrabackup_history to base an "
396 	 "incremental backup on. --incremental-history-name, "
397 	 "--incremental-basedir and --incremental-lsn. If no valid lsn can be "
398 	 "found (no success record with that uuid), an error will be returned."
399 	 " It is used with the --incremental option.",
400 	 (uchar*) &opt_ibx_incremental_history_uuid,
401 	 (uchar*) &opt_ibx_incremental_history_uuid, 0, GET_STR,
402 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
403 
404 	{"ftwrl-wait-query-type", OPT_LOCK_WAIT_QUERY_TYPE,
405 	 "This option specifies which types of queries are allowed to complete "
406 	 "before innobackupex will issue the global lock. Default is all.",
407 	 (uchar*) &opt_ibx_lock_wait_query_type,
408 	 (uchar*) &opt_ibx_lock_wait_query_type, &query_type_typelib,
409 	 GET_ENUM, REQUIRED_ARG, QUERY_TYPE_ALL, 0, 0, 0, 0, 0},
410 
411 	{"kill-long-query-type", OPT_KILL_LONG_QUERY_TYPE,
412 	 "This option specifies which types of queries should be killed to "
413 	 "unblock the global lock. Default is \"all\".",
414 	 (uchar*) &opt_ibx_kill_long_query_type,
415 	 (uchar*) &opt_ibx_kill_long_query_type, &query_type_typelib,
416 	 GET_ENUM, REQUIRED_ARG, QUERY_TYPE_SELECT, 0, 0, 0, 0, 0},
417 
418 	{"history", OPT_HISTORY,
419 	 "This option enables the tracking of backup history in the "
420 	 "PERCONA_SCHEMA.xtrabackup_history table. An optional history "
421 	 "series name may be specified that will be placed with the history "
422 	 "record for the current backup being taken.",
423 	 NULL, NULL, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
424 
425 	{"include", OPT_INCLUDE,
426 	 "This option is a regular expression to be matched against table "
427 	 "names in databasename.tablename format. It is passed directly to "
428 	 "--tables option. See the documentation for "
429 	 "details.",
430 	 (uchar*) &opt_ibx_include,
431 	 (uchar*) &opt_ibx_include, 0, GET_STR,
432 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
433 
434 	{"databases", OPT_DATABASES,
435 	 "This option specifies the list of databases that innobackupex should "
436 	 "back up. The option accepts a string argument or path to file that "
437 	 "contains the list of databases to back up. The list is of the form "
438 	 "\"databasename1[.table_name1] databasename2[.table_name2] . . .\". "
439 	 "If this option is not specified, all databases containing MyISAM and "
440 	 "InnoDB tables will be backed up.  Please make sure that --databases "
441 	 "contains all of the InnoDB databases and tables, so that all of the "
442 	 "innodb.frm files are also backed up. In case the list is very long, "
443 	 "this can be specified in a file, and the full path of the file can "
444 	 "be specified instead of the list. (See option --tables-file.)",
445 	 (uchar*) &opt_ibx_databases,
446 	 (uchar*) &opt_ibx_databases, 0, GET_STR,
447 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
448 
449 	{"kill-long-queries-timeout", OPT_KILL_LONG_QUERIES_TIMEOUT,
450 	 "This option specifies the number of seconds innobackupex waits "
451 	 "between starting FLUSH TABLES WITH READ LOCK and killing those "
452 	 "queries that block it. Default is 0 seconds, which means "
453 	 "innobackupex will not attempt to kill any queries.",
454 	 (uchar*) &opt_ibx_kill_long_queries_timeout,
455 	 (uchar*) &opt_ibx_kill_long_queries_timeout, 0, GET_UINT,
456 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
457 
458 	{"ftwrl-wait-timeout", OPT_LOCK_WAIT_TIMEOUT,
459 	 "This option specifies time in seconds that innobackupex should wait "
460 	 "for queries that would block FTWRL before running it. If there are "
461 	 "still such queries when the timeout expires, innobackupex terminates "
462 	 "with an error. Default is 0, in which case innobackupex does not "
463 	 "wait for queries to complete and starts FTWRL immediately.",
464 	 (uchar*) &opt_ibx_lock_wait_timeout,
465 	 (uchar*) &opt_ibx_lock_wait_timeout, 0, GET_UINT,
466 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
467 
468 	{"ftwrl-wait-threshold", OPT_LOCK_WAIT_THRESHOLD,
469 	 "This option specifies the query run time threshold which is used by "
470 	 "innobackupex to detect long-running queries with a non-zero value "
471 	 "of --ftwrl-wait-timeout. FTWRL is not started until such "
472 	 "long-running queries exist. This option has no effect if "
473 	 "--ftwrl-wait-timeout is 0. Default value is 60 seconds.",
474 	 (uchar*) &opt_ibx_lock_wait_threshold,
475 	 (uchar*) &opt_ibx_lock_wait_threshold, 0, GET_UINT,
476 	 REQUIRED_ARG, 60, 0, 0, 0, 0, 0},
477 
478 	{"safe-slave-backup-timeout", OPT_SAFE_SLAVE_BACKUP_TIMEOUT,
479 	 "How many seconds --safe-slave-backup should wait for "
480 	 "Slave_open_temp_tables to become zero. (default 300)",
481 	 (uchar*) &opt_ibx_safe_slave_backup_timeout,
482 	 (uchar*) &opt_ibx_safe_slave_backup_timeout, 0, GET_UINT,
483 	 REQUIRED_ARG, 300, 0, 0, 0, 0, 0},
484 
485 
486 	/* Following command-line options are actually handled by xtrabackup.
487 	We put them here with only purpose for them to showup in
488 	innobackupex --help output */
489 
490 	{"close_files", OPT_CLOSE_FILES, "Do not keep files opened."
491 	" Use at your own risk.",
492 	 (uchar*) &ibx_xb_close_files, (uchar*) &ibx_xb_close_files, 0,
493 	 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
494 
495 	{"compress", OPT_COMPRESS, "This option instructs backup to "
496 	 "compress backup copies of InnoDB data files."
497 	 , (uchar*) &ibx_xtrabackup_compress_alg,
498 	 (uchar*) &ibx_xtrabackup_compress_alg, 0,
499 	 GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
500 
501 	{"compress-threads", OPT_COMPRESS_THREADS,
502 	 "This option specifies the number of worker threads that will be used "
503 	 "for parallel compression.",
504 	 (uchar*) &ibx_xtrabackup_compress_threads,
505 	 (uchar*) &ibx_xtrabackup_compress_threads,
506 	 0, GET_UINT, REQUIRED_ARG, 1, 1, UINT_MAX, 0, 0, 0},
507 
508 	{"compress-chunk-size", OPT_COMPRESS_CHUNK_SIZE, "Size of working "
509 	 "buffer(s) for compression threads in bytes. The default value "
510 	 "is 64K.", (uchar*) &ibx_xtrabackup_compress_chunk_size,
511 	 (uchar*) &ibx_xtrabackup_compress_chunk_size,
512 	 0, GET_ULL, REQUIRED_ARG, (1 << 16), 1024, ULONGLONG_MAX, 0, 0, 0},
513 
514 	{"export", OPT_EXPORT, " enables exporting individual tables for import "
515 	 "into another server.",
516 	 (uchar*) &ibx_xtrabackup_export, (uchar*) &ibx_xtrabackup_export,
517 	 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
518 
519 	{"extra-lsndir", OPT_EXTRA_LSNDIR, "This option specifies the "
520 	 "directory in which to save an extra copy of the "
521 	 "\"xtrabackup_checkpoints\" file. The option accepts a string "
522 	 "argument.",
523 	 (uchar*) &ibx_xtrabackup_extra_lsndir,
524 	 (uchar*) &ibx_xtrabackup_extra_lsndir,
525 	 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
526 
527 	{"incremental-basedir", OPT_INCREMENTAL_BASEDIR, "This option "
528 	 "specifies the directory containing the full backup that is the base "
529 	 "dataset for the incremental backup.  The option accepts a string "
530 	 "argument. It is used with the --incremental option.",
531 	 (uchar*) &ibx_xtrabackup_incremental_basedir,
532 	 (uchar*) &ibx_xtrabackup_incremental_basedir,
533 	 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
534 
535 	{"incremental-dir", OPT_INCREMENTAL_DIR, "This option specifies the "
536 	 "directory where the incremental backup will be combined with the "
537 	 "full backup to make a new full backup.  The option accepts a string "
538 	 "argument. It is used with the --incremental option.",
539 	 (uchar*) &ibx_xtrabackup_incremental_dir,
540 	 (uchar*) &ibx_xtrabackup_incremental_dir,
541 	 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
542 
543 	{"incremental-force-scan", OPT_INCREMENTAL_FORCE_SCAN,
544 	 "Perform full scan of data files "
545 	 "for taking an incremental backup even if full changed page bitmap "
546 	 "data is available to enable the backup without the full scan.",
547 	 (uchar*)&ibx_xtrabackup_incremental_force_scan,
548 	 (uchar*)&ibx_xtrabackup_incremental_force_scan, 0, GET_BOOL, NO_ARG,
549 	 0, 0, 0, 0, 0, 0},
550 
551 	{"log-copy-interval", OPT_LOG_COPY_INTERVAL, "This option specifies "
552 	 "time interval between checks done by log copying thread in "
553 	 "milliseconds.", (uchar*) &ibx_xtrabackup_log_copy_interval,
554 	 (uchar*) &ibx_xtrabackup_log_copy_interval,
555 	 0, GET_LONG, REQUIRED_ARG, 1000, 0, LONG_MAX, 0, 1, 0},
556 
557 	{"incremental-lsn", OPT_INCREMENTAL, "This option specifies the log "
558 	 "sequence number (LSN) to use for the incremental backup.  The option "
559 	 "accepts a string argument. It is used with the --incremental option. "
560 	 "It is used instead of specifying --incremental-basedir. For "
561 	 "databases created by MySQL and Percona Server 5.0-series versions, "
562 	 "specify the LSN as two 32-bit integers in high:low format. For "
563 	 "databases created in 5.1 and later, specify the LSN as a single "
564 	 "64-bit integer.",
565 	 (uchar*) &ibx_xtrabackup_incremental,
566 	 (uchar*) &ibx_xtrabackup_incremental,
567 	 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
568 
569 	{"parallel", OPT_PARALLEL, "On backup, this option specifies the "
570 	 "number of threads to use to back "
571 	 "up files concurrently.  The option accepts an integer argument.",
572 	 (uchar*) &ibx_xtrabackup_parallel, (uchar*) &ibx_xtrabackup_parallel,
573 	 0, GET_INT, REQUIRED_ARG, 1, 1, INT_MAX, 0, 0, 0},
574 
575 
576 	{"stream", OPT_STREAM, "This option specifies the format in which to "
577 	 "do the streamed backup.  The option accepts a string argument. The "
578 	 "backup will be done to STDOUT in the specified format. Currently, "
579 	 "the only supported formats are tar and mbstream/xbstream.",
580 	 (uchar*) &ibx_xtrabackup_stream_str,
581 	 (uchar*) &ibx_xtrabackup_stream_str, 0, GET_STR,
582 	 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
583 
584 	{"tables-file", OPT_TABLES_FILE, "This option specifies the file in "
585 	 "which there are a list of names of the form database.  The option "
586 	 "accepts a string argument.table, one per line.",
587 	 (uchar*) &ibx_xtrabackup_tables_file,
588 	 (uchar*) &ibx_xtrabackup_tables_file,
589 	 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
590 
591 	{"throttle", OPT_THROTTLE, "This option specifies a number of I/O "
592 	 "operations (pairs of read+write) per second.  It accepts an integer "
593 	 "argument.",
594 	 (uchar*) &ibx_xtrabackup_throttle, (uchar*) &ibx_xtrabackup_throttle,
595 	 0, GET_LONG, REQUIRED_ARG, 0, 0, LONG_MAX, 0, 1, 0},
596 
597 	{"tmpdir", 't', "This option specifies the location where a temporary "
598 	 "files will be stored. If the option is not specified, the default is "
599 	 "to use the value of tmpdir read from the server configuration.",
600 	 (uchar*) &ibx_opt_mysql_tmpdir,
601 	 (uchar*) &ibx_opt_mysql_tmpdir, 0, GET_STR, REQUIRED_ARG,
602 	 0, 0, 0, 0, 0, 0},
603 
604 	{"use-memory", OPT_USE_MEMORY, "This option accepts a string argument "
605 	 "that specifies the amount of memory in bytes to use "
606 	 "for crash recovery while preparing a backup. Multiples are supported "
607 	 "providing the unit (e.g. 1MB, 1GB). It is used only with the option "
608 	 "--apply-log.",
609 	 (uchar*) &ibx_xtrabackup_use_memory,
610 	 (uchar*) &ibx_xtrabackup_use_memory,
611 	 0, GET_LL, REQUIRED_ARG, 100*1024*1024L, 1024*1024L, LONGLONG_MAX, 0,
612 	 1024*1024L, 0},
613 
614 	{"innodb-force-recovery", OPT_INNODB_FORCE_RECOVERY,
615 	 "This option starts up the embedded InnoDB instance in crash "
616 	 "recovery mode to ignore page corruption; should be used "
617 	 "with the \"--apply-log\" option, in emergencies only. The "
618 	 "default value is 0. Refer to \"innodb_force_recovery\" server "
619 	 "system variable documentation for more details.",
620 	 (uchar*)&xtrabackup_innodb_force_recovery,
621 	 (uchar*)&xtrabackup_innodb_force_recovery,
622 	 0, GET_ULONG, OPT_ARG, 0, 0, SRV_FORCE_IGNORE_CORRUPT, 0, 0, 0},
623 
624 	{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
625 };
626 
627 
usage(void)628 static void usage(void)
629 {
630 	puts("Open source backup tool\n\
631 \n\
632 Copyright (C) 2009-2015 Percona LLC and/or its affiliates.\n\
633 Portions Copyright (C) 2000, 2011, MySQL AB & Innobase Oy. All Rights Reserved.\n\
634 \n\
635 This program is free software; you can redistribute it and/or\n\
636 modify it under the terms of the GNU General Public License\n\
637 as published by the Free Software Foundation version 2\n\
638 of the License.\n\
639 \n\
640 This program is distributed in the hope that it will be useful,\n\
641 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
642 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
643 GNU General Public License for more details.\n\
644 \n\
645 You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n\n");
646 
647 	puts("innobackupex - Non-blocking backup tool for InnoDB, XtraDB and HailDB databases\n\
648 \n\
649 SYNOPOSIS\n\
650 \n\
651 innobackupex [--compress] [--compress-threads=NUMBER-OF-THREADS] [--compress-chunk-size=CHUNK-SIZE]\n\
652              [--include=REGEXP] [--user=NAME]\n\
653              [--password=WORD] [--port=PORT] [--socket=SOCKET]\n\
654              [--no-timestamp] [--ibbackup=IBBACKUP-BINARY]\n\
655              [--slave-info] [--galera-info] [--stream=tar|mbstream|xbstream]\n\
656              [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME]\n\
657              [--databases=LIST] [--no-lock] \n\
658              [--tmpdir=DIRECTORY] [--tables-file=FILE]\n\
659              [--history=NAME]\n\
660              [--incremental] [--incremental-basedir]\n\
661              [--incremental-dir] [--incremental-force-scan] [--incremental-lsn]\n\
662              [--incremental-history-name=NAME] [--incremental-history-uuid=UUID]\n\
663              [--close-files]\n\
664              BACKUP-ROOT-DIR\n\
665 \n\
666 innobackupex --apply-log [--use-memory=B]\n\
667              [--defaults-file=MY.CNF]\n\
668              [--export] [--ibbackup=IBBACKUP-BINARY]\n\
669              [--innodb-force-recovery=1]\n\
670              BACKUP-DIR\n\
671 \n\
672 innobackupex --copy-back [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME] BACKUP-DIR\n\
673 \n\
674 innobackupex --move-back [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME] BACKUP-DIR\n\
675 \n\
676 innobackupex [--decompress]\n\
677              [--parallel=NUMBER-OF-FORKS] BACKUP-DIR\n\
678 \n\
679 DESCRIPTION\n\
680 \n\
681 The first command line above makes a hot backup of a database.\n\
682 By default it creates a backup directory (named by the current date\n\
683 	and time) in the given backup root directory.  With the --no-timestamp\n\
684 option it does not create a time-stamped backup directory, but it puts\n\
685 the backup in the given directory (which must not exist).  This\n\
686 command makes a complete backup of all MyISAM and InnoDB tables and\n\
687 indexes in all databases or in all of the databases specified with the\n\
688 --databases option.  The created backup contains .frm, .MRG, .MYD,\n\
689 .MYI, .MAD, .MAI, .TRG, .TRN, .ARM, .ARZ, .CSM, CSV, .opt, .par, and\n\
690 InnoDB data and log files.  The MY.CNF options file defines the\n\
691 location of the database.\n\
692 \n\
693 The --apply-log command prepares a backup for starting a MySQL\n\
694 server on the backup. This command recovers InnoDB data files as specified\n\
695 in BACKUP-DIR/backup-my.cnf using BACKUP-DIR/ib_logfile0,\n\
696 and creates new InnoDB log files as specified in BACKUP-DIR/backup-my.cnf.\n\
697 The BACKUP-DIR should be the path to a backup directory\n\
698 \n\
699 The --copy-back command copies data, index, and log files\n\
700 from the backup directory back to their original locations.\n\
701 The MY.CNF options file defines the original location of the database.\n\
702 The BACKUP-DIR is the path to a backup directory.\n\
703 \n\
704 The --move-back command is similar to --copy-back with the only difference that\n\
705 it moves files to their original locations rather than copies them. As this\n\
706 option removes backup files, it must be used with caution. It may be useful in\n\
707 cases when there is not enough free disk space to copy files.\n\
708 \n\
709 The --decompress command will decompress a backup made\n\
710 with the --compress option. The\n\
711 --parallel option will allow multiple files to be decompressed\n\
712 simultaneously. In order to decompress, the qpress utility MUST be installed\n\
713 and accessible within the path. This process will remove the original\n\
714 compressed files and leave the results in the same location.\n\
715 \n\
716 On success the exit code innobackupex is 0. A non-zero exit code \n\
717 indicates an error.\n");
718 	printf("Usage: [%s [--defaults-file=#] --backup | %s [--defaults-file=#] --prepare] [OPTIONS]\n", my_progname, my_progname);
719 	my_print_help(ibx_long_options);
720 }
721 
722 
723 static
724 my_bool
ibx_get_one_option(const struct my_option * opt,const char * argument,const char *)725 ibx_get_one_option(const struct my_option *opt,
726                    const char *argument, const char *)
727 {
728 	switch(opt->id) {
729 	case '?':
730 		usage();
731 		exit(0);
732 		break;
733 	case 'v':
734 		printf("innobackupex version %s %s (%s)",
735 			MYSQL_SERVER_VERSION,
736 			SYSTEM_TYPE, MACHINE_TYPE);
737 		exit(0);
738 		break;
739 	case OPT_HISTORY:
740 		if (argument) {
741 			opt_ibx_history = argument;
742 		} else {
743 			opt_ibx_history = "";
744 		}
745 		break;
746 	case OPT_STREAM:
747 		if (!strcasecmp(argument, "mbstream") ||
748 		    !strcasecmp(argument, "xbstream"))
749 			xtrabackup_stream_fmt = XB_STREAM_FMT_XBSTREAM;
750 		else {
751 			ibx_msg("Invalid --stream argument: %s\n", argument);
752 			return 1;
753 		}
754 		xtrabackup_stream = TRUE;
755 		break;
756 	case OPT_COMPRESS:
757 		if (argument == NULL)
758 			xtrabackup_compress_alg = "quicklz";
759 		else if (strcasecmp(argument, "quicklz"))
760 		{
761 			ibx_msg("Invalid --compress argument: %s\n", argument);
762 			return 1;
763 		}
764 		xtrabackup_compress = TRUE;
765 		break;
766 	case 'p':
767     opt_ibx_password= argument;
768 		break;
769         }
770 	return(0);
771 }
772 
773 bool
make_backup_dir()774 make_backup_dir()
775 {
776 	time_t t = time(NULL);
777 	char buf[100];
778 
779 	if (!opt_ibx_notimestamp && !ibx_xtrabackup_stream_str) {
780 		strftime(buf, sizeof(buf), "%Y-%m-%d_%H-%M-%S", localtime(&t));
781 		ut_a(asprintf(&ibx_backup_directory, "%s/%s",
782 				ibx_position_arg, buf) != -1);
783 	} else {
784 		ibx_backup_directory = strdup(ibx_position_arg);
785 	}
786 
787 	if (!directory_exists(ibx_backup_directory, true)) {
788 		return(false);
789 	}
790 
791 	return(true);
792 }
793 
794 bool
ibx_handle_options(int * argc,char *** argv)795 ibx_handle_options(int *argc, char ***argv)
796 {
797 	int i, n_arguments;
798 
799 	if (handle_options(argc, argv, ibx_long_options, ibx_get_one_option)) {
800 		return(false);
801 	}
802 
803 	if (opt_ibx_apply_log) {
804 		ibx_mode = IBX_MODE_APPLY_LOG;
805 	} else if (opt_ibx_copy_back) {
806 		ibx_mode = IBX_MODE_COPY_BACK;
807 	} else if (opt_ibx_move_back) {
808 		ibx_mode = IBX_MODE_MOVE_BACK;
809 	} else if (opt_ibx_decompress) {
810 		ibx_mode = IBX_MODE_DECRYPT_DECOMPRESS;
811 	} else {
812 		ibx_mode = IBX_MODE_BACKUP;
813 	}
814 
815 	/* find and save position argument */
816 	i = 0;
817 	n_arguments = 0;
818 	while (i < *argc) {
819 		char *opt = (*argv)[i];
820 
821 		if (strncmp(opt, "--", 2) != 0
822 		    && !(strlen(opt) == 2 && opt[0] == '-')) {
823 			if (ibx_position_arg != NULL
824 				&& ibx_position_arg != opt) {
825 				ibx_msg("Error: extra argument found %s\n",
826 					opt);
827 			}
828 			ibx_position_arg = opt;
829 			++n_arguments;
830 		}
831 		++i;
832 	}
833 
834 	*argc -= n_arguments;
835 	if (n_arguments > 1) {
836 		return(false);
837 	}
838 
839 	if (ibx_position_arg == NULL) {
840 		ibx_msg("Missing argument\n");
841 		return(false);
842 	}
843 
844 	/* set argv[0] to be the program name */
845 	--(*argv);
846 	++(*argc);
847 
848 	return(true);
849 }
850 
851 /*********************************************************************//**
852 Parse command-line options, connect to MySQL server,
853 detect server capabilities, etc.
854 @return	true on success. */
855 bool
ibx_init()856 ibx_init()
857 {
858 	const char *run;
859 
860 	/*=====================*/
861 	xtrabackup_copy_back = opt_ibx_copy_back;
862 	xtrabackup_move_back = opt_ibx_move_back;
863 	opt_galera_info = opt_ibx_galera_info;
864 	opt_slave_info = opt_ibx_slave_info;
865 	opt_no_lock = opt_ibx_no_lock;
866 	opt_safe_slave_backup = opt_ibx_safe_slave_backup;
867 	opt_rsync = opt_ibx_rsync;
868 	opt_force_non_empty_dirs = opt_ibx_force_non_empty_dirs;
869 	opt_noversioncheck = opt_ibx_noversioncheck;
870 	opt_no_backup_locks = opt_ibx_no_backup_locks;
871 	opt_decompress = opt_ibx_decompress;
872 
873 	opt_incremental_history_name = opt_ibx_incremental_history_name;
874 	opt_incremental_history_uuid = opt_ibx_incremental_history_uuid;
875 
876 	opt_user = opt_ibx_user;
877 	opt_password = opt_ibx_password;
878 	opt_host = opt_ibx_host;
879 	opt_defaults_group = opt_ibx_defaults_group;
880 	opt_socket = opt_ibx_socket;
881 	opt_port = opt_ibx_port;
882 
883 	opt_lock_wait_query_type = opt_ibx_lock_wait_query_type;
884 	opt_kill_long_query_type = opt_ibx_kill_long_query_type;
885 
886 	opt_kill_long_queries_timeout = opt_ibx_kill_long_queries_timeout;
887 	opt_lock_wait_timeout = opt_ibx_lock_wait_timeout;
888 	opt_lock_wait_threshold = opt_ibx_lock_wait_threshold;
889 	opt_debug_sleep_before_unlock = opt_ibx_debug_sleep_before_unlock;
890 	opt_safe_slave_backup_timeout = opt_ibx_safe_slave_backup_timeout;
891 
892 	opt_history = opt_ibx_history;
893 
894 	/* setup xtrabackup options */
895 	xb_close_files = ibx_xb_close_files;
896 	xtrabackup_compress_alg = ibx_xtrabackup_compress_alg;
897 	xtrabackup_compress_threads = ibx_xtrabackup_compress_threads;
898 	xtrabackup_compress_chunk_size = ibx_xtrabackup_compress_chunk_size;
899 	xtrabackup_export = ibx_xtrabackup_export;
900 	xtrabackup_extra_lsndir = ibx_xtrabackup_extra_lsndir;
901 	xtrabackup_incremental_basedir = ibx_xtrabackup_incremental_basedir;
902 	xtrabackup_incremental_dir = ibx_xtrabackup_incremental_dir;
903 	xtrabackup_incremental_force_scan =
904 					ibx_xtrabackup_incremental_force_scan;
905 	xtrabackup_log_copy_interval = ibx_xtrabackup_log_copy_interval;
906 	xtrabackup_incremental = ibx_xtrabackup_incremental;
907 	xtrabackup_parallel = ibx_xtrabackup_parallel;
908 	xtrabackup_stream_str = ibx_xtrabackup_stream_str;
909 	xtrabackup_tables_file = ibx_xtrabackup_tables_file;
910 	xtrabackup_throttle = ibx_xtrabackup_throttle;
911 	opt_mysql_tmpdir = ibx_opt_mysql_tmpdir;
912 	xtrabackup_use_memory = ibx_xtrabackup_use_memory;
913 
914 	if (!opt_ibx_incremental
915 	    && (xtrabackup_incremental
916 	    	|| xtrabackup_incremental_basedir
917 	    	|| opt_ibx_incremental_history_name
918 	    	|| opt_ibx_incremental_history_uuid)) {
919 		ibx_msg("Error: --incremental-lsn, --incremental-basedir, "
920 			"--incremental-history-name and "
921 			"--incremental-history-uuid require the "
922 			"--incremental option.\n");
923 		return(false);
924 	}
925 
926 	if (opt_ibx_databases != NULL) {
927 		if (is_path_separator(*opt_ibx_databases)) {
928 			xtrabackup_databases_file = opt_ibx_databases;
929 		} else {
930 			xtrabackup_databases = opt_ibx_databases;
931 		}
932 	}
933 
934 	/* --tables and --tables-file options are xtrabackup only */
935 	ibx_partial_backup = (opt_ibx_include || opt_ibx_databases);
936 
937 	if (ibx_mode == IBX_MODE_BACKUP) {
938 
939 		if (!make_backup_dir()) {
940 			return(false);
941 		}
942 	}
943 
944 	/* --binlog-info is xtrabackup only, so force
945 	--binlog-info=ON. i.e. behavior before the feature had been
946 	implemented */
947 	opt_binlog_info = BINLOG_INFO_ON;
948 
949 	switch (ibx_mode) {
950 	case IBX_MODE_APPLY_LOG:
951 		xtrabackup_prepare = TRUE;
952 		xtrabackup_target_dir = ibx_position_arg;
953 		run = "apply-log";
954 		break;
955 	case IBX_MODE_BACKUP:
956 		xtrabackup_backup = TRUE;
957 		xtrabackup_target_dir = ibx_backup_directory;
958 		if (opt_ibx_include != NULL) {
959 			xtrabackup_tables = opt_ibx_include;
960 		}
961 		run = "backup";
962 		break;
963 	case IBX_MODE_COPY_BACK:
964 		xtrabackup_copy_back = TRUE;
965 		xtrabackup_target_dir = ibx_position_arg;
966 		run = "copy-back";
967 		break;
968 	case IBX_MODE_MOVE_BACK:
969 		xtrabackup_move_back = TRUE;
970 		xtrabackup_target_dir = ibx_position_arg;
971 		run = "move-back";
972 		break;
973 	case IBX_MODE_DECRYPT_DECOMPRESS:
974 		xtrabackup_decrypt_decompress = TRUE;
975 		xtrabackup_target_dir = ibx_position_arg;
976 		run = "decompress";
977 		break;
978 	default:
979 		ut_error;
980 	}
981 
982 	ibx_msg("Starting the %s operation\n\n"
983 		"IMPORTANT: Please check that the %s run completes "
984 		"successfully.\n"
985 		"           At the end of a successful %s run innobackupex\n"
986 		"           prints \"completed OK!\".\n\n", run, run, run);
987 
988 
989 	return(true);
990 }
991 
992 void
ibx_cleanup()993 ibx_cleanup()
994 {
995 	free(ibx_backup_directory);
996 }
997