22 #ifndef XTRABACKUP_VERSION
23 #define XTRABACKUP_VERSION "undefined"
25 #ifndef XTRABACKUP_REVISION
26 #define XTRABACKUP_REVISION "undefined"
31 #include <drizzled/internal/my_sys.h>
32 #include <drizzled/charset.h>
33 #include <drizzled/gettext.h>
34 #include <drizzled/constrained_value.h>
35 #include <drizzled/configmake.h>
36 #include <drizzled/error/priority_t.h>
40 #include <boost/program_options.hpp>
41 #include <boost/scoped_array.hpp>
42 #include <boost/scoped_ptr.hpp>
46 #define my_progname "xtrabackup"
48 #define MYSQL_VERSION_ID 50507
75 #ifdef INNODB_VERSION_SHORT
81 #define IB_INT64 ib_int64_t
82 #define LSN64 ib_uint64_t
83 #define MACH_READ_64 mach_read_from_8
84 #define MACH_WRITE_64 mach_write_to_8
85 #define OS_MUTEX_CREATE() os_mutex_create()
86 #define ut_dulint_zero 0
87 #define ut_dulint_cmp(A, B) (A > B ? 1 : (A == B ? 0 : -1))
88 #define ut_dulint_add(A, B) (A + B)
89 #define ut_dulint_minus(A, B) (A - B)
90 #define ut_dulint_align_down(A, B) (A & ~((ib_int64_t)B - 1))
91 #define ut_dulint_align_up(A, B) ((A + B - 1) & ~((ib_int64_t)B - 1))
94 #define SRV_PATH_SEPARATOR '\\'
95 #define SRV_PATH_SEPARATOR_STR "\\"
97 #define SRV_PATH_SEPARATOR '/'
98 #define SRV_PATH_SEPARATOR_STR "/"
101 #ifndef UNIV_PAGE_SIZE_MAX
102 #define UNIV_PAGE_SIZE_MAX UNIV_PAGE_SIZE
104 #ifndef UNIV_PAGE_SIZE_SHIFT_MAX
105 #define UNIV_PAGE_SIZE_SHIFT_MAX UNIV_PAGE_SIZE_SHIFT
108 using namespace drizzled;
109 namespace po=boost::program_options;
112 bool errmsg_printf (error::priority_t,
char const *format, ...);
114 bool errmsg_printf (error::priority_t,
char const *format, ...)
118 va_start(args, format);
119 rv= vfprintf(stderr, format, args);
121 fprintf(stderr,
"\n");
127 #include "xtrabackup_api.h"
132 #ifdef POSIX_FADV_NORMAL
133 #define USE_POSIX_FADVISE
158 ulint n_pending_flushes;
162 ib_int64_t modification_counter;
164 ib_int64_t flush_counter;
178 ib_int64_t tablespace_version;
192 ibool stop_ibuf_merges;
195 ibool is_being_deleted;
211 ulint n_reserved_extents;
214 ulint n_pending_flushes;
217 ulint n_pending_ibuf_merges;
224 hash_node_t name_hash;
225 #ifndef UNIV_HOTBACKUP
232 ibool is_in_unflushed_spaces;
245 #ifndef UNIV_HOTBACKUP
276 ib_int64_t modification_counter;
278 ulint max_assigned_id;
284 ib_int64_t tablespace_version;
300 extern fil_system_t* fil_system;
305 bool innodb_inited= 0;
308 char xtrabackup_real_target_dir[FN_REFLEN] =
"./xtrabackup_backupfiles/";
309 const char *xtrabackup_target_dir= xtrabackup_real_target_dir;
310 bool xtrabackup_backup =
false;
311 bool xtrabackup_stats =
false;
312 bool xtrabackup_prepare =
false;
313 bool xtrabackup_print_param =
false;
315 bool xtrabackup_export =
false;
316 bool xtrabackup_apply_log_only =
false;
318 bool xtrabackup_suspend_at_end =
false;
319 uint64_t xtrabackup_use_memory = 100*1024*1024L;
320 bool xtrabackup_create_ib_logfile =
false;
322 long xtrabackup_throttle = 0;
326 bool xtrabackup_stream =
false;
327 const char *xtrabackup_incremental = NULL;
328 LSN64 incremental_lsn;
329 LSN64 incremental_to_lsn;
330 LSN64 incremental_last_lsn;
331 byte* incremental_buffer = NULL;
332 byte* incremental_buffer_base = NULL;
334 const char *xtrabackup_incremental_basedir = NULL;
335 const char *xtrabackup_extra_lsndir = NULL;
336 char *xtrabackup_incremental_dir = NULL;
338 char *xtrabackup_tables = NULL;
339 int tables_regex_num;
340 regex_t *tables_regex;
341 regmatch_t tables_regmatch[1];
343 const char *xtrabackup_tables_file = NULL;
348 hash_node_t name_hash;
353 static ulint thread_nr[SRV_MAX_N_IO_THREADS + 6 + 64];
356 static ulint thread_nr[SRV_MAX_N_IO_THREADS + 6];
360 LSN64 checkpoint_lsn_start;
361 LSN64 checkpoint_no_start;
362 LSN64 log_copy_scanned_lsn;
363 IB_INT64 log_copy_offset = 0;
364 ibool log_copying = TRUE;
365 ibool log_copying_running = FALSE;
366 ibool log_copying_succeed = FALSE;
368 ibool xtrabackup_logfile_is_renamed = FALSE;
373 #define XTRABACKUP_METADATA_FILENAME "xtrabackup_checkpoints"
374 char metadata_type[30] =
"";
376 ib_uint64_t metadata_from_lsn = 0;
377 ib_uint64_t metadata_to_lsn = 0;
378 ib_uint64_t metadata_last_lsn = 0;
380 #define XB_DELTA_INFO_SUFFIX ".meta"
384 char dst_log_path[FN_REFLEN];
387 char mysql_real_data_home[FN_REFLEN] =
"./";
388 char *mysql_data_home= mysql_real_data_home;
389 std::string mysql_data_home_arg;
390 static char mysql_data_home_buff[2];
392 const char *opt_mysql_tmpdir = NULL;
396 #define HA_INNOBASE_ROWS_IN_TABLE 10000
397 #define HA_INNOBASE_RANGE_COUNT 100
399 ulong innobase_large_page_size = 0;
404 long innobase_additional_mem_pool_size = 1*1024*1024L;
405 long innobase_buffer_pool_awe_mem_mb = 0;
406 long innobase_file_io_threads = 4;
407 long innobase_read_io_threads = 4;
408 long innobase_write_io_threads = 4;
409 long innobase_force_recovery = 0;
410 long innobase_lock_wait_timeout = 50;
411 long innobase_log_buffer_size = 1024*1024L;
412 long innobase_log_files_in_group = 2;
413 long innobase_log_files_in_group_backup;
414 long innobase_mirrored_log_groups = 1;
415 long innobase_open_files = 300L;
417 long innobase_page_size = (1 << 14);
418 static ulong innobase_log_block_size = 512;
419 bool innobase_fast_checksum =
false;
420 bool innobase_extra_undoslots =
false;
421 char* innobase_doublewrite_file = NULL;
423 uint64_t innobase_buffer_pool_size = 8*1024*1024L;
426 static log_file_constraint innobase_log_file_size;
428 uint64_t innobase_log_file_size_backup;
433 char* innobase_data_home_dir = NULL;
434 const char* innobase_data_file_path = NULL;
435 char* innobase_log_group_home_dir = NULL;
436 char* innobase_log_group_home_dir_backup = NULL;
437 char* innobase_log_arch_dir = NULL;
440 char* innobase_unix_file_flush_method = NULL;
445 ulong innobase_fast_shutdown = 1;
446 bool innobase_log_archive = FALSE;
447 bool innobase_use_doublewrite = TRUE;
448 bool innobase_use_checksums = TRUE;
449 bool innobase_use_large_pages = FALSE;
450 bool innobase_file_per_table = FALSE;
451 bool innobase_locks_unsafe_for_binlog = FALSE;
452 bool innobase_rollback_on_timeout = FALSE;
453 bool innobase_create_status_file = FALSE;
454 bool innobase_adaptive_hash_index = TRUE;
456 static char *internal_innobase_data_file_path = NULL;
463 #define INNOBASE_WAKE_INTERVAL 32
464 ulong innobase_active_counter = 0;
472 return static_cast<const CHARSET_INFO*
>(cs)->isspace(char_to_test);
481 const char* path_name)
483 const char* name = path_name + drizzled::internal::dirname_length(path_name);
485 return((name) ? name :
"null");
506 fprintf(stderr,
"ERROR: innobase_rec_to_mysql called\n");
520 fprintf(stderr,
"ERROR: innobase_rec_reset called\n");
538 fil_system_t *system;
547 datafiles_iter_new(fil_system_t *f_system)
552 it->mutex = OS_MUTEX_CREATE();
554 it->system = f_system;
568 *space_changed = FALSE;
570 if (it->node == NULL) {
576 if (it->node != NULL)
580 it->space = (it->space == NULL) ?
584 while (it->space != NULL &&
588 if (it->space == NULL)
590 *space_changed = TRUE;
618 static void print_version(
void)
620 printf(
"%s Ver %s Rev %s for %s %s (%s)\n" ,my_progname,
621 XTRABACKUP_VERSION, XTRABACKUP_REVISION,
"Drizzle",
622 TARGET_OS, TARGET_CPU);
625 static void usage(
void)
627 puts(
"Open source backup tool for InnoDB and XtraDB\n\
629 Copyright (C) 2009 Percona Inc.\n\
631 This program is free software; you can redistribute it and/or\n\
632 modify it under the terms of the GNU General Public License\n\
633 as published by the Free Software Foundation version 2\n\
636 This program is distributed in the hope that it will be useful,\n\
637 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
638 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
639 GNU General Public License for more details.\n\
641 You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n");
643 printf(
"Usage: [%s [--defaults-file=#] --backup | %s [--defaults-file=#] --prepare] [OPTIONS]\n",my_progname,my_progname);
655 fprintf(stderr,
"xtrabackup: thd_is_replication_slave_thread() is called\n");
665 fprintf(stderr,
"xtrabackup: thd_has_edited_nontrans_tables() is called\n");
675 fprintf(stderr,
"xtrabackup: thd_is_select() is called\n");
686 fprintf(stderr,
"xtrabackup: innobase_mysql_print_thd() is called\n");
700 cs = all_charsets[cset];
702 *mbminlen = cs->mbminlen;
703 *mbmaxlen = cs->mbmaxlen;
706 *mbminlen = *mbmaxlen = 0;
719 fprintf(stderr,
"xtrabackup: innobase_convert_from_table_id() is called\n");
731 fprintf(stderr,
"xtrabackup: innobase_convert_from_id() is called\n");
739 return my_charset_utf8_general_ci.strcasecmp(a, b);
746 my_charset_utf8_general_ci.casedn_str(a);
756 fprintf(stderr,
"xtrabackup: innobase_get_stmt() is called\n");
763 char filename[FN_REFLEN];
765 int fd = internal::create_temp_file(filename, opt_mysql_tmpdir,
768 O_BINARY | O_TRUNC | O_SEQUENTIAL |
769 O_TEMPORARY | O_SHORT_LIVED |
771 O_CREAT | O_EXCL | O_RDWR);
789 fprintf(stderr,
"xtrabackup: Got error %d on dup\n",fd2);
828 if (UNIV_UNLIKELY(idlen > buflen)) {
831 memcpy(buf, s, idlen);
843 for (; idlen; idlen--) {
845 if (UNIV_UNLIKELY(c == q)) {
846 if (UNIV_UNLIKELY(buflen < 3)) {
854 if (UNIV_UNLIKELY(buflen < 2)) {
884 const char* bufend = buf + buflen;
887 const char* slash = (
const char*) memchr(
id,
'/', idlen);
896 if (UNIV_LIKELY(s < bufend)) {
905 const char temp_index_suffix[]=
"--temporary--";
909 if (s - buf + (
sizeof temp_index_suffix - 1) < buflen) {
910 memcpy(s, temp_index_suffix,
911 sizeof temp_index_suffix - 1);
912 s +=
sizeof temp_index_suffix - 1;
937 const unsigned char* a,
938 unsigned int a_length,
940 const unsigned char* b,
941 unsigned int b_length);
950 const unsigned char* a,
951 unsigned int a_length,
952 const unsigned char* b,
953 unsigned int b_length)
956 enum_field_types mysql_tp;
959 assert(a_length != UNIV_SQL_NULL);
960 assert(b_length != UNIV_SQL_NULL);
962 mysql_tp = (enum_field_types) mysql_type;
966 case DRIZZLE_TYPE_BLOB:
967 case DRIZZLE_TYPE_VARCHAR:
973 if (charset_number == default_charset_info->number) {
974 charset = default_charset_info;
976 charset = get_charset(charset_number);
978 if (charset == NULL) {
979 fprintf(stderr,
"xtrabackup needs charset %lu for doing "
980 "a comparison, but MySQL cannot "
981 "find that charset.",
982 (ulong) charset_number);
992 ret = charset->coll->strnncollsp(charset,
997 }
else if (ret > 0) {
1020 charset = get_charset((uint) charset_id);
1023 ut_ad(charset->mbmaxlen);
1027 n_chars = prefix_len / charset->mbmaxlen;
1034 if (charset->mbmaxlen > 1) {
1053 char_length = my_charpos(charset, str,
1054 str + data_len, (
int) n_chars);
1055 if (char_length > data_len) {
1056 char_length = data_len;
1059 if (data_len < prefix_len) {
1060 char_length = data_len;
1062 char_length = prefix_len;
1066 return(char_length);
1081 fprintf(stderr,
"xtrabackup: innobase_raw_format() is called\n");
1092 return(innobase_lock_wait_timeout);
1121 innobase_get_slow_log()
1132 get_bit_shift(ulint value)
1139 for (shift = 0; !(value & 1UL); shift++) {
1142 return (value >> 1) ? 0 : shift;
1146 innodb_init_param(
void)
1149 static char current_dir[3];
1154 get_charset_name(0);
1158 srv_page_size_shift = 0;
1160 if (innobase_page_size != (1 << 14)) {
1161 int n_shift = get_bit_shift(innobase_page_size);
1163 if (n_shift >= 12 && n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX) {
1165 "InnoDB: Warning: innodb_page_size has been "
1166 "changed from default value 16384.\n");
1167 srv_page_size_shift = n_shift;
1168 srv_page_size = 1 << n_shift;
1170 "InnoDB: The universal page size of the "
1171 "database is set to %lu.\n", srv_page_size);
1173 fprintf(stderr,
"InnoDB: Error: invalid value of "
1174 "innobase_page_size: %lu", innobase_page_size);
1178 srv_page_size_shift = 14;
1179 srv_page_size = (1 << srv_page_size_shift);
1182 srv_log_block_size = 0;
1183 if (innobase_log_block_size != 512) {
1184 uint n_shift = get_bit_shift(innobase_log_block_size);;
1187 "InnoDB: Warning: innodb_log_block_size has "
1188 "been changed from its default value. "
1189 "(###EXPERIMENTAL### operation)\n");
1191 srv_log_block_size = (1 << n_shift);
1193 "InnoDB: The log block size is set to %lu.\n",
1194 srv_log_block_size);
1197 srv_log_block_size = 512;
1200 if (!srv_log_block_size) {
1202 "InnoDB: Error: %lu is not valid value for "
1203 "innodb_log_block_size.\n", innobase_log_block_size);
1207 srv_fast_checksum = (ibool) innobase_fast_checksum;
1211 if (
sizeof(ulint) == 4) {
1212 if (xtrabackup_use_memory > UINT32_MAX) {
1214 "xtrabackup: use-memory can't be over 4GB"
1215 " on 32-bit systems\n");
1218 if (innobase_buffer_pool_size > UINT32_MAX) {
1220 "xtrabackup: innobase_buffer_pool_size can't be over 4GB"
1221 " on 32-bit systems\n");
1226 if (innobase_log_file_size > UINT32_MAX) {
1228 "xtrabackup: innobase_log_file_size can't be over 4GB"
1229 " on 32-bit systemsi\n");
1244 current_dir[0] = FN_CURLIB;
1245 current_dir[1] = FN_LIBCHAR;
1247 default_path = current_dir;
1254 if (xtrabackup_backup || xtrabackup_stats) {
1255 fprintf(stderr,
"xtrabackup: Target instance is assumed as followings.\n");
1257 fprintf(stderr,
"xtrabackup: Temporary instance for recovery is set as followings.\n");
1264 srv_data_home = ((xtrabackup_backup || xtrabackup_stats) && innobase_data_home_dir
1265 ? innobase_data_home_dir : default_path);
1266 fprintf(stderr,
"xtrabackup: innodb_data_home_dir = %s\n", srv_data_home);
1272 if (!innobase_data_file_path) {
1273 innobase_data_file_path = (
char*)
"ibdata1:10M:autoextend";
1275 fprintf(stderr,
"xtrabackup: innodb_data_file_path = %s\n",
1276 innobase_data_file_path);
1281 internal_innobase_data_file_path = strdup(innobase_data_file_path);
1284 internal_innobase_data_file_path);
1287 "xtrabackup: syntax error in innodb_data_file_path\n");
1289 free(internal_innobase_data_file_path);
1293 if (xtrabackup_prepare) {
1297 for (i=0; i < srv_n_data_files; i++) {
1300 p = srv_data_file_names[i];
1301 while ((p = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1304 srv_data_file_names[i] = p;
1310 srv_doublewrite_file = innobase_doublewrite_file;
1312 srv_extra_undoslots = (ibool) innobase_extra_undoslots;
1320 if (!((xtrabackup_backup || xtrabackup_stats) && innobase_log_group_home_dir)) {
1321 innobase_log_group_home_dir = default_path;
1323 if (xtrabackup_prepare && xtrabackup_incremental_dir) {
1324 innobase_log_group_home_dir = xtrabackup_incremental_dir;
1326 fprintf(stderr,
"xtrabackup: innodb_log_group_home_dir = %s\n",
1327 innobase_log_group_home_dir);
1329 #ifdef UNIV_LOG_ARCHIVE
1334 innobase_log_arch_dir = innobase_log_group_home_dir;
1336 srv_arch_dir = innobase_log_arch_dir;
1342 if (ret == FALSE || innobase_mirrored_log_groups != 1) {
1343 fprintf(stderr,
"xtrabackup: syntax error in innodb_log_group_home_dir, or a "
1344 "wrong number of mirrored log groups\n");
1346 goto mem_free_and_error;
1349 srv_adaptive_flushing = FALSE;
1350 srv_use_sys_malloc = TRUE;
1356 srv_file_flush_method_str = innobase_unix_file_flush_method;
1358 srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
1359 srv_n_log_files = (ulint) innobase_log_files_in_group;
1360 srv_log_file_size = (ulint) innobase_log_file_size;
1361 fprintf(stderr,
"xtrabackup: innodb_log_files_in_group = %ld\n",
1363 fprintf(stderr,
"xtrabackup: innodb_log_file_size = %ld\n",
1366 #ifdef UNIV_LOG_ARCHIVE
1367 srv_log_archive_on = (ulint) innobase_log_archive;
1369 srv_log_buffer_size = (ulint) innobase_log_buffer_size;
1377 srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
1379 srv_n_file_io_threads = (ulint) innobase_file_io_threads;
1381 srv_n_read_io_threads = (ulint) innobase_read_io_threads;
1382 srv_n_write_io_threads = (ulint) innobase_write_io_threads;
1384 srv_force_recovery = (ulint) innobase_force_recovery;
1386 srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
1387 srv_use_checksums = (ibool) innobase_use_checksums;
1389 btr_search_enabled = innobase_adaptive_hash_index ?
true :
false;
1391 os_use_large_pages = (ibool) innobase_use_large_pages;
1392 os_large_page_size = (ulint) innobase_large_page_size;
1400 srv_max_n_open_files = (ulint) innobase_open_files;
1401 srv_innodb_status = (ibool) innobase_create_status_file;
1403 srv_print_verbose_log = 1;
1409 data_mysql_default_charset_coll = (ulint)default_charset_info->number;
1411 ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
1428 switch (os_get_os_version()) {
1437 srv_use_native_aio = FALSE;
1443 srv_use_native_aio = TRUE;
1448 srv_use_native_aio = TRUE;
1449 srv_use_native_conditions = TRUE;
1453 #elif defined(LINUX_NATIVE_AIO)
1455 if (srv_use_native_aio) {
1458 " InnoDB: Using Linux native AIO\n");
1464 srv_use_native_aio = FALSE;
1471 fprintf(stderr,
"xtrabackup: innodb_init_param(): Error occured.\n");
1482 if (err != DB_SUCCESS) {
1483 free(internal_innobase_data_file_path);
1501 fprintf(stderr,
"xtrabackup: innodb_init(): Error occured.\n");
1508 srv_fast_shutdown = (ulint) innobase_fast_shutdown;
1511 fprintf(stderr,
"xtrabackup: starting shutdown with innodb_fast_shutdown = %lu\n",
1517 free(internal_innobase_data_file_path);
1530 fprintf(stderr,
"xtrabackup: innodb_end(): Error occured.\n");
1536 xtrabackup_read_metadata(
char *filename)
1540 fp = fopen(filename,
"r");
1542 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filename);
1546 if (fscanf(fp,
"backup_type = %29s\n", metadata_type)
1549 if (fscanf(fp,
"from_lsn = %"PRIu64
"\n", &metadata_from_lsn)
1552 if (fscanf(fp,
"to_lsn = %"PRIu64
"\n", &metadata_to_lsn)
1555 if (fscanf(fp,
"last_lsn = %"PRIu64
"\n", &metadata_last_lsn)
1557 metadata_last_lsn = 0;
1566 xtrabackup_write_metadata(
char *filename)
1570 fp = fopen(filename,
"w");
1572 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filename);
1576 if (fprintf(fp,
"backup_type = %s\n", metadata_type)
1579 if (fprintf(fp,
"from_lsn = %"PRIu64
"\n", metadata_from_lsn)
1582 if (fprintf(fp,
"to_lsn = %"PRIu64
"\n", metadata_to_lsn)
1585 if (fprintf(fp,
"last_lsn = %"PRIu64
"\n", metadata_last_lsn)
1604 fp = fopen(filepath,
"r");
1610 if (fscanf(fp,
"page_size = %lu\n", &info->page_size) != 1)
1622 xb_write_delta_metadata(
const char *filepath,
const xb_delta_info_t *info)
1626 fp = fopen(filepath,
"w");
1628 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filepath);
1632 if (fprintf(fp,
"page_size = %lu\n", info->page_size) < 0)
1642 xtrabackup_io_throttling(
void)
1644 if (xtrabackup_throttle && (io_ticket--) < 0) {
1646 os_event_wait(wait_throttle);
1652 #define COPY_CHUNK 64
1655 xtrabackup_copy_datafile(
fil_node_t* node, uint thread_n)
1659 char dst_path[FN_REFLEN];
1660 char meta_path[FN_REFLEN];
1666 ulint page_in_buffer= 0;
1667 ulint incremental_buffers = 0;
1669 ulint page_size_shift;
1676 if (xtrabackup_tables && (!trx_sys_sys_space(node->
space->
id)))
1678 if (xtrabackup_tables && (node->
space->
id != 0))
1682 int p_len, regres= 0;
1689 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1694 p_len = strlen(p) - strlen(
".ibd");
1706 for (i = 0; i < tables_regex_num; i++) {
1707 regres = regexec(&tables_regex[i], prev, 1, tables_regmatch, 0);
1708 if (regres != REG_NOMATCH)
1713 *(p - 1) = SRV_PATH_SEPARATOR;
1715 if ( regres == REG_NOMATCH ) {
1716 printf(
"[%02u] Copying %s is skipped.\n",
1717 thread_n, node->
name);
1723 if (xtrabackup_tables_file && (!trx_sys_sys_space(node->
space->
id)))
1725 if (xtrabackup_tables_file && (node->
space->
id != 0))
1736 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1741 p_len = strlen(p) - strlen(
".ibd");
1756 !strcmp(table->name, prev));
1761 printf(
"[%02u] Copying %s is skipped.\n",
1762 thread_n, node->
name);
1768 zip_size = fil_space_get_zip_size(node->
space->
id);
1769 if (zip_size == ULINT_UNDEFINED) {
1770 fprintf(stderr,
"[%02u] xtrabackup: Warning: "
1771 "Failed to determine page size for %s.\n"
1772 "[%02u] xtrabackup: Warning: We assume the table was "
1773 "dropped during xtrabackup execution and ignore the "
1774 "file.\n", thread_n, node->
name, thread_n);
1776 }
else if (zip_size) {
1777 page_size = zip_size;
1778 page_size_shift = get_bit_shift(page_size);
1779 fprintf(stderr,
"[%02u] %s is compressed with page size = "
1780 "%lu bytes\n", thread_n, node->
name, page_size);
1781 if (page_size_shift < 10 || page_size_shift > 14) {
1782 fprintf(stderr,
"[%02u] xtrabackup: Error: Invalid "
1783 "page size.\n", thread_n);
1787 page_size = UNIV_PAGE_SIZE;
1788 page_size_shift = UNIV_PAGE_SIZE_SHIFT;
1792 if (trx_sys_sys_space(node->
space->
id))
1800 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1804 sprintf(dst_path,
"%s/%s", xtrabackup_target_dir, p);
1807 sprintf(dst_path,
"%s%s", xtrabackup_target_dir, strstr(node->
name, SRV_PATH_SEPARATOR_STR));
1810 if (xtrabackup_incremental) {
1811 snprintf(meta_path,
sizeof(meta_path),
1812 "%s%s", dst_path, XB_DELTA_INFO_SUFFIX);
1813 strcat(dst_path,
".delta");
1816 bzero(incremental_buffer, (page_size/4) * page_size);
1821 info.page_size = page_size;
1826 src_file = os_file_create_simple_no_error_handling(
1829 OS_FILE_READ_ONLY, &success);
1835 "[%02u] xtrabackup: Warning: cannot open %s\n"
1836 "[%02u] xtrabackup: Warning: We assume the "
1837 "table was dropped during xtrabackup execution "
1838 "and ignore the file.\n",
1839 thread_n, node->
name, thread_n);
1850 #ifdef USE_POSIX_FADVISE
1851 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
1852 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1857 dst_file = os_file_create(
1859 dst_path, OS_FILE_CREATE,
1865 fprintf(stderr,
"[%02u] xtrabackup: error: "
1866 "cannot open %s\n", thread_n, dst_path);
1870 #ifdef USE_POSIX_FADVISE
1871 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
1875 printf(
"[%02u] Copying %s \n to %s\n", thread_n,
1876 node->
name, dst_path);
1878 buf2 = (
unsigned char*)
ut_malloc(COPY_CHUNK * page_size + UNIV_PAGE_SIZE);
1879 page = (
unsigned char*)
ut_align(buf2, UNIV_PAGE_SIZE);
1881 success = os_file_read(src_file, page, 0, 0, UNIV_PAGE_SIZE);
1888 for (offset = 0; offset < file_size; offset += COPY_CHUNK * page_size) {
1891 ulint retry_count = 10;
1893 if ((ulint)(file_size - offset) > COPY_CHUNK * page_size) {
1894 chunk = COPY_CHUNK * page_size;
1896 chunk = (ulint)(file_size - offset);
1900 xtrabackup_io_throttling();
1902 success = os_file_read(src_file, page,
1903 (ulint)(offset & 0xFFFFFFFFUL),
1904 (ulint)(offset >> 32), chunk);
1910 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1911 if (buf_page_is_corrupted(page + chunk_offset, zip_size))
1915 trx_sys_sys_space(node->
space->
id)
1919 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1921 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1922 < FSP_EXTENT_SIZE * 3) {
1926 ut_a(page_size == UNIV_PAGE_SIZE);
1927 fprintf(stderr,
"[%02u] xtrabackup: "
1928 "Page %lu seems double write "
1929 "buffer. passing the check.\n",
1932 (IB_INT64)chunk_offset) >>
1936 if (retry_count == 0) {
1938 "[%02u] xtrabackup: "
1939 "Error: 10 retries "
1940 "resulted in fail. This"
1946 fprintf(stderr,
"[%02u] xtrabackup: "
1947 "Database page corruption "
1948 "detected at page %lu. "
1952 (IB_INT64)chunk_offset)
1953 >> page_size_shift));
1959 if (xtrabackup_incremental) {
1960 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1963 if (ut_dulint_cmp(incremental_lsn,
1964 MACH_READ_64(page + chunk_offset +
FIL_PAGE_LSN)) < 0) {
1966 IB_INT64 offset_on_page;
1968 if (page_in_buffer == page_size/4) {
1970 success = os_file_write(dst_path, dst_file, incremental_buffer,
1971 ((incremental_buffers * (page_size/4))
1972 << page_size_shift) & 0xFFFFFFFFUL,
1973 (incremental_buffers * (page_size/4))
1974 >> (32 - page_size_shift),
1975 page_in_buffer * page_size);
1980 incremental_buffers++;
1983 bzero(incremental_buffer, (page_size/4) * page_size);
1989 offset_on_page = ((offset + (IB_INT64)chunk_offset) >> page_size_shift);
1990 ut_a(offset_on_page >> 32 == 0);
1992 mach_write_to_4(incremental_buffer + page_in_buffer * 4, (ulint)offset_on_page);
1993 memcpy(incremental_buffer + page_in_buffer * page_size,
1994 page + chunk_offset, page_size);
2001 success = os_file_write(dst_path, dst_file, page,
2002 (ulint)(offset & 0xFFFFFFFFUL),
2003 (ulint)(offset >> 32), chunk);
2011 if (xtrabackup_incremental) {
2013 if (page_in_buffer != page_size/4) {
2014 mach_write_to_4(incremental_buffer + page_in_buffer * 4, 0xFFFFFFFFUL);
2020 success = os_file_write(dst_path, dst_file, incremental_buffer,
2021 ((incremental_buffers * (page_size/4))
2022 << page_size_shift) & 0xFFFFFFFFUL,
2023 (incremental_buffers * (page_size/4))
2024 >> (32 - page_size_shift),
2025 page_in_buffer * page_size);
2029 if (!xb_write_delta_metadata(meta_path, &info)) {
2030 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2031 "failed to write meta info for %s\n",
2032 thread_n, dst_path);
2037 success = os_file_flush(dst_file);
2056 printf(
"[%02u] ...done\n", thread_n);
2058 os_file_close(src_file);
2060 os_file_close(dst_file);
2064 if (src_file != -1 && !node->
open)
2065 os_file_close(src_file);
2067 os_file_close(dst_file);
2070 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2071 "xtrabackup_copy_datafile() failed.\n", thread_n);
2075 if (src_file != -1 && !node->
open)
2076 os_file_close(src_file);
2078 os_file_close(dst_file);
2081 fprintf(stderr,
"[%02u] xtrabackup: Warning: skipping file %s.\n",
2082 thread_n, node->
name);
2087 xtrabackup_copy_logfile(LSN64 from_lsn,
bool is_last)
2091 LSN64 group_scanned_lsn;
2092 LSN64 contiguous_lsn;
2096 if (!xtrabackup_stream)
2097 ut_a(dst_log != -1);
2100 contiguous_lsn = ut_dulint_align_down(from_lsn,
2116 start_lsn = contiguous_lsn;
2121 xtrabackup_io_throttling();
2124 group, start_lsn, end_lsn);
2136 ulint scanned_checkpoint_no = 0;
2140 log_block = log_sys->
buf;
2141 scanned_lsn = start_lsn;
2148 || !log_block_checksum_is_ok_or_old_format(log_block)) {
2151 && log_block_checksum_is_ok_or_old_format(log_block)) {
2153 ">> ###Warning###: The copying transaction log migh be overtaken already by the target.\n"
2154 ">> : Waiting log block no %lu, but the bumber is already %lu.\n"
2155 ">> : If the number equals %lu + n * %lu, it should be overtaken already.\n",
2164 && !log_block_checksum_is_ok_or_old_format(
2167 "xtrabackup: Log block no %lu at lsn %"PRIu64
" has\n"
2168 "xtrabackup: ok header, but checksum field contains %lu, should be %lu\n",
2190 if (ut_dulint_cmp(scanned_lsn, contiguous_lsn) > 0) {
2191 contiguous_lsn = scanned_lsn;
2198 (scanned_checkpoint_no > 0)
2200 < scanned_checkpoint_no)
2201 && (scanned_checkpoint_no
2212 scanned_lsn = ut_dulint_add(scanned_lsn, data_len);
2224 group_scanned_lsn = scanned_lsn;
2237 write_size = ut_dulint_minus(
2244 if (!xtrabackup_stream) {
2245 success = os_file_write(dst_log_path, dst_log, log_sys->
buf,
2246 (ulint)(log_copy_offset & 0xFFFFFFFFUL),
2247 (ulint)(log_copy_offset >> 32), write_size);
2250 ulint stdout_write_size = write_size;
2251 if (finished && !is_last
2255 if (stdout_write_size) {
2256 ret = write(fileno(stdout), log_sys->
buf, stdout_write_size);
2257 if (ret == stdout_write_size) {
2260 fprintf(stderr,
"write: %lu > %lu\n", stdout_write_size, ret);
2268 log_copy_offset += write_size;
2270 if (finished && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE)
2277 if (!xtrabackup_stream) {
2278 fprintf(stderr,
"xtrabackup: Error: os_file_write to %s\n", dst_log_path);
2280 fprintf(stderr,
"xtrabackup: Error: write to stdout\n");
2292 start_lsn = end_lsn;
2300 fprintf(stderr,
">> log scanned up to (%"PRIu64
")\n",group->
scanned_lsn);
2305 log_copy_scanned_lsn = group_scanned_lsn;
2308 ut_a(group == NULL);
2312 if (!xtrabackup_stream) {
2313 success = os_file_flush(dst_log);
2326 if (!xtrabackup_stream)
2327 os_file_close(dst_log);
2328 fprintf(stderr,
"xtrabackup: Error: xtrabackup_copy_logfile() failed.\n");
2333 #define SLEEPING_PERIOD 5
2346 if (!xtrabackup_stream)
2347 ut_a(dst_log != -1);
2349 log_copying_running = TRUE;
2351 while(log_copying) {
2355 if(counter >= SLEEPING_PERIOD * 5) {
2356 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, FALSE))
2363 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, TRUE))
2366 log_copying_succeed = TRUE;
2368 log_copying_running = FALSE;
2385 ut_a(xtrabackup_backup);
2387 while (log_copying) {
2395 io_ticket = xtrabackup_throttle;
2400 xtrabackup_throttle = 0;
2424 segment = *((ulint*)arg);
2427 fil_aio_wait(segment);
2448 xtrabackup_create_output_dir(
2453 char path[FN_REFLEN];
2457 ptr1 = strstr(space->
name, SRV_PATH_SEPARATOR_STR);
2459 ptr2 = strstr(ptr1 + 1, SRV_PATH_SEPARATOR_STR);
2464 if(!trx_sys_sys_space(space->
id) && ptr2)
2466 if(space->
id && ptr2)
2471 snprintf(path,
sizeof(path),
"%s%s", xtrabackup_target_dir,
2473 *ptr2 = SRV_PATH_SEPARATOR;
2475 if (mkdir(path, 0777) != 0 && errno != EEXIST) {
2477 "xtrabackup: Error: cannot mkdir %d: %s\n",
2489 data_copy_thread_func(
2494 uint num = ctxt->num;
2496 ibool space_changed;
2499 while ((node = datafiles_iter_next(ctxt->it, &space_changed)) != NULL) {
2500 space = node->
space;
2502 if (space_changed && xtrabackup_create_output_dir(space))
2506 if(xtrabackup_copy_datafile(node, num)) {
2507 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2508 "failed to copy datafile.\n",
2519 OS_THREAD_DUMMY_RETURN;
2524 xtrabackup_backup_func(
void)
2526 struct stat stat_info;
2529 #ifdef USE_POSIX_FADVISE
2530 fprintf(stderr,
"xtrabackup: uses posix_fadvise().\n");
2535 if (chdir(mysql_real_data_home) != 0)
2537 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
2540 fprintf(stderr,
"xtrabackup: cd to %s\n", mysql_real_data_home);
2542 mysql_data_home= mysql_data_home_buff;
2543 mysql_data_home[0]=FN_CURLIB;
2544 mysql_data_home[1]=0;
2547 srv_read_only = TRUE;
2550 if(innodb_init_param())
2553 if (srv_file_flush_method_str == NULL) {
2559 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"fsync")) {
2562 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DSYNC")) {
2565 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DIRECT")) {
2567 fprintf(stderr,
"xtrabackup: use O_DIRECT\n");
2568 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"littlesync")) {
2571 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"nosync")) {
2574 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"normal")) {
2576 os_aio_use_native_aio = FALSE;
2578 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"unbuffered")) {
2580 os_aio_use_native_aio = FALSE;
2582 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
2583 "async_unbuffered")) {
2588 "xtrabackup: Unrecognized value %s for innodb_flush_method\n",
2589 srv_file_flush_method_str);
2593 if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
2599 srv_max_n_threads = 50000;
2602 }
else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
2604 srv_max_n_threads = 10000;
2606 srv_max_n_threads = 1000;
2615 nr = srv_n_data_files;
2617 for (i = 0; i < nr; i++) {
2618 srv_data_file_sizes[i] = srv_data_file_sizes[i]
2619 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2622 srv_last_file_size_max = srv_last_file_size_max
2623 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2625 srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
2627 srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
2636 ibool create_new_db;
2638 ibool create_new_doublewrite_file;
2640 ibool log_file_created;
2641 ibool log_created = FALSE;
2642 ibool log_opened = FALSE;
2643 LSN64 min_flushed_lsn;
2644 LSN64 max_flushed_lsn;
2645 ulint sum_of_new_sizes;
2652 #define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
2653 #define SRV_MAX_N_PENDING_SYNC_IOS 100
2655 srv_n_file_io_threads = 2 + srv_n_read_io_threads + srv_n_write_io_threads;
2657 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD,
2658 srv_n_read_io_threads,
2659 srv_n_write_io_threads,
2660 SRV_MAX_N_PENDING_SYNC_IOS);
2662 fil_init(srv_file_per_table ? 50000 : 5000,
2663 srv_max_n_open_files);
2670 for (i = 0; i < srv_n_file_io_threads; i++) {
2678 err = open_or_create_data_files(&create_new_db,
2680 &create_new_doublewrite_file,
2682 &min_flushed_lsn, &max_flushed_lsn,
2684 if (err != DB_SUCCESS) {
2686 "xtrabackup: Could not open or create data files.\n"
2687 "xtrabackup: If you tried to add new data files, and it failed here,\n"
2688 "xtrabackup: you should now edit innodb_data_file_path in my.cnf back\n"
2689 "xtrabackup: to what it was, and remove the new ibdata files InnoDB created\n"
2690 "xtrabackup: in this failed attempt. InnoDB only wrote those files full of\n"
2691 "xtrabackup: zeros, but did not yet use them in any way. But be careful: do not\n"
2692 "xtrabackup: remove old data files which contain your precious data!\n");
2699 if (create_new_db) {
2700 fprintf(stderr,
"xtrabackup: Something wrong with source files...\n");
2704 for (i = 0; i < srv_n_log_files; i++) {
2705 err = open_or_create_log_file(create_new_db, &log_file_created,
2707 if (err != DB_SUCCESS) {
2713 if (log_file_created) {
2718 if ((log_opened && create_new_db)
2719 || (log_opened && log_created)) {
2721 "xtrabackup: Error: all log files must be created at the same time.\n"
2722 "xtrabackup: All log files must be created also in database creation.\n"
2723 "xtrabackup: If you want bigger or smaller log files, shut down the\n"
2724 "xtrabackup: database and make sure there were no errors in shutdown.\n"
2725 "xtrabackup: Then delete the existing log files. Edit the .cnf file\n"
2726 "xtrabackup: and start the database again.\n");
2734 if (log_file_created) {
2735 fprintf(stderr,
"xtrabackup: Something wrong with source files...\n");
2739 fil_load_single_table_tablespaces();
2744 if (xtrabackup_extra_lsndir
2745 && (stat(xtrabackup_extra_lsndir,&stat_info) != 0)
2746 && (mkdir(xtrabackup_extra_lsndir,0777) != 0)){
2747 fprintf(stderr,
"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_extra_lsndir);
2752 if (!xtrabackup_stream) {
2755 if (stat(xtrabackup_target_dir,&stat_info) != 0
2756 && (mkdir(xtrabackup_target_dir,0777) != 0)){
2757 fprintf(stderr,
"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_target_dir);
2762 fprintf(stderr,
"xtrabackup: Stream mode.\n");
2768 fil_system_t* f_system = fil_system;
2774 boost::scoped_array<byte> log_hdr_buf_(
2775 new byte[LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE]);
2785 log_hdr_buf = (byte*)
ut_align(log_hdr_buf_.get(),
2796 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2798 if (err != DB_SUCCESS) {
2806 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2807 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2812 0, 0, LOG_FILE_HDR_SIZE,
2813 log_hdr_buf, max_cp_group);
2816 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2818 if (err != DB_SUCCESS) {
2826 if(ut_dulint_cmp(checkpoint_no_start,
2827 MACH_READ_64(buf + LOG_CHECKPOINT_NO)) != 0) {
2828 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2829 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2830 goto reread_log_header;
2833 if (!xtrabackup_stream) {
2836 sprintf(dst_log_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
2839 dst_log = os_file_create(
2841 dst_log_path, OS_FILE_CREATE,
2849 "xtrabackup: error: cannot open %s\n",
2854 #ifdef USE_POSIX_FADVISE
2855 posix_fadvise(dst_log, 0, 0, POSIX_FADV_DONTNEED);
2861 strcpy((
char*) log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2864 (
char*) log_hdr_buf + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
2865 + (
sizeof "xtrabkup ") - 1));
2867 if (!xtrabackup_stream) {
2868 success = os_file_write(dst_log_path, dst_log, log_hdr_buf,
2869 0, 0, LOG_FILE_HDR_SIZE);
2872 if ((write(fileno(stdout), log_hdr_buf, LOG_FILE_HDR_SIZE)
2873 - LOG_FILE_HDR_SIZE) == 0)
2881 log_copy_offset += LOG_FILE_HDR_SIZE;
2884 os_file_close(dst_log);
2892 if(xtrabackup_throttle) {
2895 io_ticket = xtrabackup_throttle;
2903 if(xtrabackup_copy_logfile(checkpoint_lsn_start, FALSE))
2911 if (!xtrabackup_stream) {
2920 printf(
"xtrabackup: Starting %u threads for parallel "
2921 "data files transfer\n", parallel);
2923 it = datafiles_iter_new(f_system);
2926 "xtrabackup: Error: "
2927 "datafiles_iter_new() failed.\n");
2937 count_mutex = OS_MUTEX_CREATE();
2939 for (i = 0; i < parallel; i++) {
2940 data_threads[i].it = it;
2941 data_threads[i].num = i+1;
2942 data_threads[i].count = &count;
2943 data_threads[i].count_mutex = count_mutex;
2946 &data_threads[i].
id);
2963 datafiles_iter_free(it);
2972 if (xtrabackup_suspend_at_end) {
2974 char suspend_path[FN_REFLEN];
2975 ibool success, exists;
2976 os_file_type_t type;
2978 sprintf(suspend_path,
"%s%s", xtrabackup_target_dir,
2979 "/xtrabackup_suspended");
2983 suspend_file = os_file_create(
2985 suspend_path, OS_FILE_OVERWRITE,
2989 fprintf(stderr,
"xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
2992 if (suspend_file != -1)
2993 os_file_close(suspend_file);
3002 xtrabackup_suspend_at_end = FALSE;
3006 latest_cp = ut_dulint_zero;
3012 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
3014 if (err != DB_SUCCESS) {
3015 fprintf(stderr,
"xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
3021 latest_cp = MACH_READ_64(log_sys->
checkpoint_buf + LOG_CHECKPOINT_LSN);
3023 if (!xtrabackup_stream) {
3024 printf(
"xtrabackup: The latest check point (for incremental): '%"PRIu64
"'\n",
3027 fprintf(stderr,
"xtrabackup: The latest check point (for incremental): '%"PRIu64
"'\n",
3033 log_copying = FALSE;
3034 if (!xtrabackup_stream) {
3035 printf(
"xtrabackup: Stopping log copying thread");
3036 while (log_copying_running) {
3042 while (log_copying_running)
3048 char filename[FN_REFLEN];
3050 if(!xtrabackup_incremental) {
3051 strcpy(metadata_type,
"full-backuped");
3052 metadata_from_lsn = ut_dulint_zero;
3054 strcpy(metadata_type,
"incremental");
3055 metadata_from_lsn = incremental_lsn;
3057 metadata_to_lsn = latest_cp;
3058 metadata_last_lsn = log_copy_scanned_lsn;
3060 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
3061 if (xtrabackup_write_metadata(filename))
3062 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
3064 if(xtrabackup_extra_lsndir) {
3065 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3066 if (xtrabackup_write_metadata(filename))
3067 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3071 if (!log_copying_succeed) {
3072 fprintf(stderr,
"xtrabackup: Error: log_copying_thread failed.\n");
3076 if (!xtrabackup_stream)
3077 os_file_close(dst_log);
3082 if (!xtrabackup_stream) {
3083 printf(
"xtrabackup: Transaction log of lsn (%"PRIu64
") to (%"PRIu64
") was copied.\n",
3084 checkpoint_lsn_start, log_copy_scanned_lsn);
3086 fprintf(stderr,
"xtrabackup: Transaction log of lsn (%"PRIu64
") to (%"PRIu64
") was copied.\n",
3087 checkpoint_lsn_start, log_copy_scanned_lsn);
3088 if(xtrabackup_extra_lsndir) {
3089 char filename[FN_REFLEN];
3090 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3091 if (xtrabackup_write_metadata(filename))
3092 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3099 xtrabackup_stats_level(
3108 ulint right_page_no;
3115 ulint* offsets = NULL;
3117 uint64_t n_pages, n_pages_extern;
3118 uint64_t sum_data, sum_data_extern;
3122 n_pages = sum_data = n_recs = 0;
3123 n_pages_extern = sum_data_extern = 0;
3129 fprintf(stdout,
" leaf pages: ");
3131 fprintf(stdout,
" level %lu pages: ", level);
3136 block = btr_root_block_get(index, &mtr);
3137 page = buf_block_get_frame(block);
3140 zip_size = fil_space_get_zip_size(space);
3151 node_ptr = page_cur_get_rec(&cursor);
3152 offsets = rec_get_offsets(node_ptr, index, offsets,
3153 ULINT_UNDEFINED, &heap);
3155 block = btr_node_ptr_get_child(node_ptr, index, offsets, &mtr);
3156 page = buf_block_get_frame(block);
3180 ulint offsets_[REC_OFFS_NORMAL_SIZE];
3181 ulint* local_offsets = offsets_;
3183 *offsets_ = (
sizeof offsets_) /
sizeof *offsets_;
3194 local_offsets = rec_get_offsets(cur.
rec, index, local_offsets,
3195 ULINT_UNDEFINED, &local_heap);
3198 for (i = 0; i < n_fields; i++) {
3211 data = rec_get_nth_field(cur.
rec, local_offsets, i, &local_len);
3221 fprintf(stderr,
"\nWarning: several record may share same external page.\n");
3226 local_block =
btr_block_get(space_id, zip_size, page_no, RW_S_LATCH, &local_mtr);
3227 local_page = buf_block_get_frame(local_block);
3229 blob_header = local_page + offset;
3230 #define BTR_BLOB_HDR_PART_LEN 0
3231 #define BTR_BLOB_HDR_NEXT_PAGE_NO 4
3247 sum_data_extern += part_len;
3268 block =
btr_block_get(space, zip_size, right_page_no, RW_X_LATCH, &mtr);
3269 page = buf_block_get_frame(block);
3275 page_size = zip_size;
3277 page_size = UNIV_PAGE_SIZE;
3281 fprintf(stdout,
"recs=%"PRIu64
", ", n_recs);
3283 fprintf(stdout,
"pages=%"PRIu64
", data=%"PRIu64
" bytes, data/pages=%"PRIu64
"%%",
3285 ((sum_data * 100)/ page_size)/n_pages);
3288 if (level == 0 && n_pages_extern) {
3291 fprintf(stdout,
" external pages: ");
3293 fprintf(stdout,
"pages=%"PRIu64
", data=%"PRIu64
" bytes, data/pages=%"PRIu64
"%%",
3294 n_pages_extern, sum_data_extern,
3295 ((sum_data_extern * 100)/ page_size)/n_pages_extern);
3301 xtrabackup_stats_level(index, level - 1);
3308 xtrabackup_stats_func(
void)
3314 if (chdir(mysql_real_data_home) != 0)
3316 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3319 fprintf(stderr,
"xtrabackup: cd to %s\n", mysql_real_data_home);
3321 mysql_data_home= mysql_data_home_buff;
3322 mysql_data_home[0]=FN_CURLIB;
3323 mysql_data_home[1]=0;
3326 srv_read_only = TRUE;
3327 srv_fake_write = TRUE;
3330 if(innodb_init_param())
3335 for (n = 0; n < srv_n_log_files; n++) {
3336 char logname[FN_REFLEN];
3338 os_file_type_t type;
3340 sprintf(logname,
"ib_logfile%lu", (ulong) n);
3342 type != OS_FILE_TYPE_FILE) {
3343 fprintf(stderr,
"xtrabackup: Error: "
3344 "Cannot find log file %s.\n", logname);
3345 fprintf(stderr,
"xtrabackup: Error: "
3346 "to use the statistics feature, you need a "
3347 "clean copy of the database including "
3348 "correctly sized log files, so you need to "
3349 "execute with --prepare twice to use this "
3350 "functionality on a backup.\n");
3355 fprintf(stderr,
"xtrabackup: Starting 'read-only' InnoDB instance to gather index statistics.\n"
3356 "xtrabackup: Using %"PRIu64
" bytes for buffer pool (set by --use-memory parameter)\n",
3357 xtrabackup_use_memory);
3362 fprintf(stdout,
"\n\n<INDEX STATISTICS>\n");
3379 mutex_enter(&kernel_mutex);
3380 srv_fatal_semaphore_wait_threshold += 72000;
3381 mutex_exit(&kernel_mutex);
3383 mutex_enter(&(dict_sys->
mutex));
3395 rec = btr_pcur_get_rec(&pcur);
3404 mutex_exit(&(dict_sys->
mutex));
3408 mutex_enter(&kernel_mutex);
3409 srv_fatal_semaphore_wait_threshold -= 72000;
3410 mutex_exit(&kernel_mutex);
3415 field = rec_get_nth_field_old(rec, 0, &len);
3422 char* table_name =
mem_strdupl((
char*) field, len);
3424 btr_pcur_store_position(&pcur, &mtr);
3432 if (xtrabackup_tables) {
3437 p = strstr(table->
name, SRV_PATH_SEPARATOR_STR);
3442 for (i = 0; i < tables_regex_num; i++) {
3443 regres = regexec(&tables_regex[i], table->
name, 1, tables_regmatch, 0);
3444 if (regres != REG_NOMATCH)
3449 *p = SRV_PATH_SEPARATOR;
3451 if ( regres == REG_NOMATCH )
3455 if (xtrabackup_tables_file) {
3461 ut_ad(xtable->name),
3462 !strcmp(xtable->name, table->
name));
3469 if (table == NULL) {
3470 fputs(
"InnoDB: Failed to load table ", stderr);
3479 if (dict_table_get_first_index(table)) {
3481 dict_update_statistics(table, TRUE, FALSE);
3482 #elif defined(INNODB_VERSION_SHORT)
3483 dict_update_statistics(table, TRUE);
3485 dict_update_statistics_low(table, TRUE);
3492 while (index != NULL) {
3504 " table: %s, index: %s, space id: %lu, root page: %lu"
3506 "\n estimated statistics in dictionary:\n"
3507 " key vals: %lu, leaf pages: %lu, size pages: %lu\n"
3508 " real statistics:\n",
3510 (ulong) index->
space,
3511 (ulong) index->
page,
3512 (ulong) fil_space_get_zip_size(index->
space),
3525 root = btr_root_get(index, &local_mtr);
3529 xtrabackup_stats_level(index, page_level);
3560 xtrabackup_init_temp_log(
void)
3563 char src_path[FN_REFLEN];
3564 char dst_path[FN_REFLEN];
3569 byte* log_buf_ = NULL;
3575 LSN64 checkpoint_no;
3579 max_no = ut_dulint_zero;
3581 if(!xtrabackup_incremental_dir) {
3582 sprintf(dst_path,
"%s%s", xtrabackup_target_dir,
"/ib_logfile0");
3583 sprintf(src_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
3585 sprintf(dst_path,
"%s%s", xtrabackup_incremental_dir,
"/ib_logfile0");
3586 sprintf(src_path,
"%s%s", xtrabackup_incremental_dir,
"/xtrabackup_logfile");
3592 src_file = os_file_create_simple_no_error_handling(
3595 OS_FILE_READ_WRITE , &success);
3601 "xtrabackup: Warning: cannot open %s. will try to find.\n",
3605 src_file = os_file_create_simple_no_error_handling(
3608 OS_FILE_READ_WRITE , &success);
3612 " xtrabackup: Fatal error: cannot find %s.\n",
3618 log_buf_ = (
unsigned char*)
ut_malloc(LOG_FILE_HDR_SIZE * 2);
3619 log_buf = (
unsigned char*)
ut_align(log_buf_, LOG_FILE_HDR_SIZE);
3621 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3626 if (
ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3627 (byte*)
"xtrabkup", (
sizeof "xtrabkup") - 1) == 0) {
3629 " xtrabackup: 'ib_logfile0' seems to be 'xtrabackup_logfile'. will retry.\n");
3634 os_file_close(src_file);
3638 success = os_file_rename(
3640 dst_path, src_path);
3649 " xtrabackup: Fatal error: cannot find %s.\n",
3655 os_file_close(src_file);
3661 #ifdef USE_POSIX_FADVISE
3662 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3663 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3674 log_buf_ = (
unsigned char*)
ut_malloc(UNIV_PAGE_SIZE * 129);
3675 log_buf = (
unsigned char*)
ut_align(log_buf_, UNIV_PAGE_SIZE);
3678 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3683 if (
ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3684 (byte*)
"xtrabkup", (
sizeof "xtrabkup") - 1) != 0 ) {
3685 printf(
"xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.\n");
3694 for (field = LOG_CHECKPOINT_1; field <= LOG_CHECKPOINT_2;
3695 field += LOG_CHECKPOINT_2 - LOG_CHECKPOINT_1) {
3696 if (!recv_check_cp_is_consistent(log_buf + field))
3697 goto not_consistent;
3699 checkpoint_no = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_NO);
3701 if (ut_dulint_cmp(checkpoint_no, max_no) >= 0) {
3702 max_no = checkpoint_no;
3703 max_lsn = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_LSN);
3722 if (ut_dulint_cmp(max_no, ut_dulint_zero) == 0) {
3723 fprintf(stderr,
"xtrabackup: No valid checkpoint found.\n");
3729 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN, max_lsn);
3731 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3732 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3734 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_ARCHIVED_LSN,
3735 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3736 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE))));
3738 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_1, LOG_CHECKPOINT_CHECKSUM_1);
3739 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3741 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN,
3742 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3743 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3745 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN, max_lsn);
3747 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3748 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3750 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_ARCHIVED_LSN,
3751 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3752 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE))));
3754 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_2, LOG_CHECKPOINT_CHECKSUM_1);
3755 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3757 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN,
3758 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3759 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3762 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3769 if (file_size % UNIV_PAGE_SIZE) {
3770 memset(log_buf, 0, UNIV_PAGE_SIZE);
3771 success = os_file_write(src_path, src_file, log_buf,
3772 (ulint)(file_size & 0xFFFFFFFFUL),
3773 (ulint)(file_size >> 32),
3774 UNIV_PAGE_SIZE - (file_size % UNIV_PAGE_SIZE));
3786 memset(log_buf, 0, UNIV_PAGE_SIZE * 128);
3787 expand = file_size / UNIV_PAGE_SIZE / 8;
3789 for (; expand > 128; expand -= 128) {
3790 success = os_file_write(src_path, src_file, log_buf,
3791 (ulint)(file_size & 0xFFFFFFFFUL),
3792 (ulint)(file_size >> 32),
3793 UNIV_PAGE_SIZE * 128);
3797 file_size += UNIV_PAGE_SIZE * 128;
3801 success = os_file_write(src_path, src_file, log_buf,
3802 (ulint)(file_size & 0xFFFFFFFFUL),
3803 (ulint)(file_size >> 32),
3804 expand * UNIV_PAGE_SIZE);
3808 file_size += UNIV_PAGE_SIZE * expand;
3813 if (file_size < 2*1024*1024L) {
3814 memset(log_buf, 0, UNIV_PAGE_SIZE);
3815 while (file_size < 2*1024*1024L) {
3816 success = os_file_write(src_path, src_file, log_buf,
3817 (ulint)(file_size & 0xFFFFFFFFUL),
3818 (ulint)(file_size >> 32),
3823 file_size += UNIV_PAGE_SIZE;
3828 printf(
"xtrabackup: xtrabackup_logfile detected: size=%"PRIu64
", start_lsn=(%"PRIu64
")\n",
3829 file_size, max_lsn);
3831 os_file_close(src_file);
3835 innobase_log_group_home_dir_backup = innobase_log_group_home_dir;
3836 innobase_log_file_size_backup = innobase_log_file_size;
3837 innobase_log_files_in_group_backup = innobase_log_files_in_group;
3840 innobase_log_group_home_dir = NULL;
3841 innobase_log_file_size = file_size;
3842 innobase_log_files_in_group = 1;
3844 srv_thread_concurrency = 0;
3847 success = os_file_rename(
3849 src_path, dst_path);
3853 xtrabackup_logfile_is_renamed = TRUE;
3860 os_file_close(src_file);
3867 os_file_close(src_file);
3870 fprintf(stderr,
"xtrabackup: Error: xtrabackup_init_temp_log() failed.\n");
3882 const char *delta_path,
3886 size_t len = strlen(delta_path);
3888 if (len <= 6 || strcmp(delta_path + len - 6,
".delta")) {
3891 memcpy(meta_path, delta_path, len - 6);
3892 strcpy(meta_path + len - 6, XB_DELTA_INFO_SUFFIX);
3898 xtrabackup_apply_delta(
3899 const char* dirname,
3901 const char* filename,
3907 char src_path[FN_REFLEN];
3908 char dst_path[FN_REFLEN];
3909 char meta_path[FN_REFLEN];
3912 ibool last_buffer = FALSE;
3913 ulint page_in_buffer;
3914 ulint incremental_buffers = 0;
3918 ulint page_size_shift;
3920 ut_a(xtrabackup_incremental);
3923 snprintf(src_path,
sizeof(src_path),
"%s/%s/%s",
3924 dirname, dbname, filename);
3925 snprintf(dst_path,
sizeof(dst_path),
"%s/%s/%s",
3926 xtrabackup_real_target_dir, dbname, filename);
3928 snprintf(src_path,
sizeof(src_path),
"%s/%s",
3930 snprintf(dst_path,
sizeof(dst_path),
"%s/%s",
3931 xtrabackup_real_target_dir, filename);
3933 dst_path[strlen(dst_path) - 6] =
'\0';
3935 if (!get_meta_path(src_path, meta_path)) {
3943 if (!xb_read_delta_metadata(meta_path, &info)) {
3947 page_size = info.page_size;
3948 page_size_shift = get_bit_shift(page_size);
3949 fprintf(stderr,
"xtrabackup: page size for %s is %lu bytes\n",
3950 src_path, page_size);
3951 if (page_size_shift < 10 ||
3952 page_size_shift > UNIV_PAGE_SIZE_SHIFT_MAX) {
3954 "xtrabackup: error: invalid value of page_size "
3955 "(%lu bytes) read from %s\n", page_size, meta_path);
3959 src_file = os_file_create_simple_no_error_handling(
3965 "xtrabackup: error: cannot open %s\n",
3970 #ifdef USE_POSIX_FADVISE
3971 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3972 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3979 dst_file = os_file_create_simple_no_error_handling(
3985 "xtrabackup: error: cannot open %s\n",
3990 #ifdef USE_POSIX_FADVISE
3991 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
3998 printf(
"Applying %s ...\n", src_path);
4000 while (!last_buffer) {
4001 ulint cluster_header;
4005 success = os_file_read(src_file, incremental_buffer,
4006 ((incremental_buffers * (page_size / 4))
4007 << page_size_shift) & 0xFFFFFFFFUL,
4008 (incremental_buffers * (page_size / 4))
4009 >> (32 - page_size_shift),
4016 switch(cluster_header) {
4024 "xtrabackup: error: %s seems not .delta file.\n",
4029 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4036 ut_a(last_buffer || page_in_buffer == page_size / 4);
4039 success = os_file_read(src_file, incremental_buffer,
4040 ((incremental_buffers * (page_size / 4))
4041 << page_size_shift) & 0xFFFFFFFFUL,
4042 (incremental_buffers * (page_size / 4))
4043 >> (32 - page_size_shift),
4044 page_in_buffer * page_size);
4049 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4051 ulint offset_on_page;
4053 offset_on_page =
mach_read_from_4(incremental_buffer + page_in_buffer * 4);
4055 if (offset_on_page == 0xFFFFFFFFUL)
4065 success = os_file_write(dst_path, dst_file,
4066 incremental_buffer +
4067 page_in_buffer * page_size,
4068 (offset_on_page << page_size_shift) &
4070 offset_on_page >> (32 - page_size_shift),
4077 incremental_buffers++;
4081 os_file_close(src_file);
4083 os_file_close(dst_file);
4088 os_file_close(src_file);
4090 os_file_close(dst_file);
4091 fprintf(stderr,
"xtrabackup: Error: xtrabackup_apply_delta() failed.\n");
4096 xtrabackup_apply_deltas(
bool check_newer)
4099 char dbpath[FN_REFLEN];
4104 ulint err = DB_SUCCESS;
4105 static char current_dir[2];
4107 current_dir[0] = FN_CURLIB;
4109 srv_data_home = current_dir;
4114 if (dbdir != NULL) {
4115 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dbdir,
4118 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4119 goto next_file_item_1;
4122 if (strlen(fileinfo.
name) > 6
4123 && 0 == strcmp(fileinfo.
name +
4124 strlen(fileinfo.
name) - 6,
4126 xtrabackup_apply_delta(
4127 xtrabackup_incremental_dir, NULL,
4128 fileinfo.
name, check_newer);
4131 ret = fil_file_readdir_next_file(&err,
4132 xtrabackup_incremental_dir, dbdir,
4138 fprintf(stderr,
"xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4145 fprintf(stderr,
"xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4148 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dir,
4151 if (dbinfo.
type == OS_FILE_TYPE_FILE
4152 || dbinfo.
type == OS_FILE_TYPE_UNKNOWN) {
4154 goto next_datadir_item;
4157 sprintf(dbpath,
"%s/%s", xtrabackup_incremental_dir,
4163 if (dbdir != NULL) {
4165 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
4169 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4171 goto next_file_item_2;
4174 if (strlen(fileinfo.
name) > 6
4175 && 0 == strcmp(fileinfo.
name +
4176 strlen(fileinfo.
name) - 6,
4180 xtrabackup_apply_delta(
4181 xtrabackup_incremental_dir, dbinfo.
name,
4182 fileinfo.
name, check_newer);
4185 ret = fil_file_readdir_next_file(&err,
4193 ret = fil_file_readdir_next_file(&err,
4194 xtrabackup_incremental_dir,
4203 xtrabackup_close_temp_log(
bool clear_flag)
4206 char src_path[FN_REFLEN];
4207 char dst_path[FN_REFLEN];
4211 byte* log_buf_ = NULL;
4214 if (!xtrabackup_logfile_is_renamed)
4218 innobase_log_group_home_dir = innobase_log_group_home_dir_backup;
4219 innobase_log_file_size = innobase_log_file_size_backup;
4220 innobase_log_files_in_group = innobase_log_files_in_group_backup;
4223 if(!xtrabackup_incremental_dir) {
4224 sprintf(dst_path,
"%s%s", xtrabackup_target_dir,
"/ib_logfile0");
4225 sprintf(src_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
4227 sprintf(dst_path,
"%s%s", xtrabackup_incremental_dir,
"/ib_logfile0");
4228 sprintf(src_path,
"%s%s", xtrabackup_incremental_dir,
"/xtrabackup_logfile");
4234 success = os_file_rename(
4236 dst_path, src_path);
4240 xtrabackup_logfile_is_renamed = FALSE;
4246 src_file = os_file_create_simple_no_error_handling(
4249 OS_FILE_READ_WRITE, &success);
4254 #ifdef USE_POSIX_FADVISE
4255 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
4262 log_buf_ = (
unsigned char*)
ut_malloc(LOG_FILE_HDR_SIZE * 2);
4263 log_buf = (
unsigned char*)
ut_align(log_buf_, LOG_FILE_HDR_SIZE);
4265 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4270 memset(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
' ', 4);
4272 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4277 os_file_close(src_file);
4283 os_file_close(src_file);
4286 fprintf(stderr,
"xtrabackup: Error: xtrabackup_close_temp_log() failed.\n");
4291 xtrabackup_prepare_func(
void)
4295 if (chdir(xtrabackup_real_target_dir) != 0)
4297 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", xtrabackup_real_target_dir);
4300 fprintf(stderr,
"xtrabackup: cd to %s\n", xtrabackup_real_target_dir);
4302 xtrabackup_target_dir= mysql_data_home_buff;
4303 mysql_data_home_buff[0]=FN_CURLIB;
4304 mysql_data_home_buff[1]=0;
4308 char filename[FN_REFLEN];
4310 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4312 if (xtrabackup_read_metadata(filename))
4313 fprintf(stderr,
"xtrabackup: error: xtrabackup_read_metadata()\n");
4315 if (!strcmp(metadata_type,
"full-backuped")) {
4316 fprintf(stderr,
"xtrabackup: This target seems to be not prepared yet.\n");
4317 }
else if (!strcmp(metadata_type,
"full-prepared")) {
4318 fprintf(stderr,
"xtrabackup: This target seems to be already prepared.\n");
4321 fprintf(stderr,
"xtrabackup: This target seems not to have correct metadata...\n");
4324 if (xtrabackup_incremental) {
4326 "xtrabackup: error: applying incremental backup needs target prepared.\n");
4330 if (xtrabackup_incremental
4331 && ut_dulint_cmp(metadata_to_lsn, incremental_lsn) != 0) {
4333 "xtrabackup: error: This incremental backup seems not to be proper for the target.\n"
4334 "xtrabackup: Check 'to_lsn' of the target and 'from_lsn' of the incremental.\n");
4340 srv_max_n_threads = 1000;
4345 srv_page_size_shift = 14;
4346 srv_page_size = (1 << srv_page_size_shift);
4351 if(xtrabackup_init_temp_log())
4354 if(xtrabackup_incremental)
4355 xtrabackup_apply_deltas(TRUE);
4366 if(innodb_init_param())
4369 srv_apply_log_only = (ibool) xtrabackup_apply_log_only;
4372 if(srv_n_file_io_threads < 10) {
4373 srv_n_file_io_threads = 10;
4376 fprintf(stderr,
"xtrabackup: Starting InnoDB instance for recovery.\n"
4377 "xtrabackup: Using %"PRIu64
" bytes for buffer pool (set by --use-memory parameter)\n",
4378 xtrabackup_use_memory);
4422 fil_system_t* f_system = fil_system;
4425 mutex_enter(&(f_system->
mutex));
4428 while (space != NULL) {
4437 mutex_exit(&(f_system->
mutex));
4441 mtr_s_lock(fil_space_get_latch(space->
id, &flags), &mtr);
4445 0, RW_S_LATCH, &mtr);
4447 + buf_block_get_frame(block);
4455 fil_extend_space_to_desired_size(&actual_size, space->
id, size);
4457 mutex_enter(&(f_system->
mutex));
4463 mutex_exit(&(f_system->
mutex));
4468 if (xtrabackup_export) {
4469 printf(
"xtrabackup: export option is specified.\n");
4470 if (innobase_file_per_table) {
4471 fil_system_t* f_system = fil_system;
4475 char info_file_path[FN_REFLEN];
4477 char table_name[FN_REFLEN];
4482 buf = (byte*)
ut_malloc(UNIV_PAGE_SIZE * 2);
4483 page = (byte*)
ut_align(buf, UNIV_PAGE_SIZE);
4486 innobase_fast_shutdown = 0;
4488 mutex_enter(&(f_system->
mutex));
4491 while (space != NULL) {
4495 || trx_sys_sys_space(space->
id)
4506 while (node != NULL) {
4508 char *next, *prev, *p;
4514 strncpy(info_file_path, node->
name, FN_REFLEN);
4515 len = strlen(info_file_path);
4516 info_file_path[len - 3] =
'e';
4517 info_file_path[len - 2] =
'x';
4518 info_file_path[len - 1] =
'p';
4522 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
4527 info_file_path[len - 4] = 0;
4528 strncpy(table_name, prev, FN_REFLEN);
4530 info_file_path[len - 4] =
'.';
4532 mutex_exit(&(f_system->
mutex));
4533 mutex_enter(&(dict_sys->
mutex));
4538 "xtrabackup: error: cannot find dictionary record of table %s\n", table_name);
4541 index = dict_table_get_first_index(table);
4545 "xtrabackup: error: sorry, cannot export over 31 indexes for now.\n");
4550 bzero(page, UNIV_PAGE_SIZE);
4554 strncpy((
char*)page + 12, table_name, 500);
4557 "xtrabackup: export metadata of table '%s' to file `%s` (%lu indexes)\n",
4558 table_name, info_file_path, n_index);
4566 strncpy((
char*)page + n_index * 512 + 12, index->
name, 500);
4569 "xtrabackup: name=%s, id.low=%lu, page=%lu\n",
4571 (ulint)(index->
id & 0xFFFFFFFFUL),
4573 (ulint) index->
page);
4575 index = dict_table_get_next_index(index);
4580 info_file = os_file_create(
4582 info_file_path, OS_FILE_OVERWRITE,
4588 success = os_file_write(info_file_path, info_file, page,
4589 0, 0, UNIV_PAGE_SIZE);
4594 success = os_file_flush(info_file);
4600 if (info_file != -1) {
4601 os_file_close(info_file);
4604 mutex_exit(&(dict_sys->
mutex));
4605 mutex_enter(&(f_system->
mutex));
4612 mutex_exit(&(f_system->
mutex));
4616 printf(
"xtrabackup: export option is for file_per_table only, disabled.\n");
4621 printf(
"\n[notice (again)]\n"
4622 " If you use binary log and don't use any hack of group commit,\n"
4623 " the binary log position seems to be:\n");
4632 fp = fopen(
"xtrabackup_binlog_pos_innodb",
"w");
4634 fprintf(fp,
"%s\t%llu\n",
4641 printf(
"xtrabackup: failed to open 'xtrabackup_binlog_pos_innodb'\n");
4646 if ((xtrabackup_incremental
4647 && ut_dulint_cmp(srv_start_lsn, incremental_last_lsn) < 0)
4648 ||(!xtrabackup_incremental
4649 && ut_dulint_cmp(srv_start_lsn, metadata_last_lsn) < 0)) {
4650 printf(
"xtrabackup: ########################################################\n"
4651 "xtrabackup: # !!WARNING!! #\n"
4652 "xtrabackup: # The transaction log file should be wrong or corrupt. #\n"
4653 "xtrabackup: # The log was not applied to the intended LSN! #\n"
4654 "xtrabackup: ########################################################\n");
4655 if (xtrabackup_incremental) {
4656 printf(
"xtrabackup: The intended lsn is %"PRIu64
"\n",
4657 incremental_last_lsn);
4659 printf(
"xtrabackup: The intended lsn is %"PRIu64
"\n",
4677 if(xtrabackup_close_temp_log(TRUE))
4682 char filename[FN_REFLEN];
4684 strcpy(metadata_type,
"full-prepared");
4686 if(xtrabackup_incremental
4687 && ut_dulint_cmp(metadata_to_lsn, incremental_to_lsn) < 0)
4689 metadata_to_lsn = incremental_to_lsn;
4690 metadata_last_lsn = incremental_last_lsn;
4693 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4694 if (xtrabackup_write_metadata(filename))
4695 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
4697 if(xtrabackup_extra_lsndir) {
4698 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4699 if (xtrabackup_write_metadata(filename))
4700 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4704 if(!xtrabackup_create_ib_logfile)
4709 printf(
"\n[notice]\nWe cannot call InnoDB second time during the process lifetime.\n");
4710 printf(
"Please re-execte to create ib_logfile*. Sorry.\n");
4727 xtrabackup_close_temp_log(FALSE);
4734 int main(
int argc,
char **argv)
4736 po::options_description commandline_options(_(
"Options used only in command line"));
4737 commandline_options.add_options()
4738 (
"target-dir", po::value<std::string>(), _(
"destination directory"))
4739 (
"backup", po::value<bool>(&xtrabackup_backup)->default_value(
false)->zero_tokens(), _(
"take backup to target-dir"))
4740 (
"stats", po::value<bool>(&xtrabackup_stats)->default_value(
false)->zero_tokens(), _(
"calc statistic of datadir (offline mysqld is recommended)"))
4741 (
"prepare", po::value<bool>(&xtrabackup_prepare)->default_value(
false)->zero_tokens(), _(
"prepare a backup for starting mysql server on the backup."))
4742 (
"export", po::value<bool>(&xtrabackup_export)->default_value(
false)->zero_tokens(), _(
"create files to import to another database when prepare."))
4743 (
"apply-log-only", po::value<bool>(&xtrabackup_apply_log_only)->default_value(
false)->zero_tokens(), _(
"stop recovery process not to progress LSN after applying log when prepare."))
4744 (
"print-param", po::value<bool>(&xtrabackup_print_param)->default_value(
false)->zero_tokens(), _(
"print parameter of mysqld needed for copyback."))
4745 (
"use-memory", po::value<uint64_t>(&xtrabackup_use_memory)->default_value(100*1024*1024), _(
"The value is used instead of buffer_pool_size"))
4746 (
"suspend-at-end", po::value<bool>(&xtrabackup_suspend_at_end)->default_value(
false)->zero_tokens(), _(
"creates a file 'xtrabackup_suspended' and waits until the user deletes that file at the end of '--backup'"))
4747 (
"throttle", po::value<long>(&xtrabackup_throttle), _(
"limit count of IO operations (pairs of read&write) per second to IOS values (for '--backup')"))
4748 (
"log-stream", po::value<bool>(&xtrabackup_stream)->default_value(
false)->zero_tokens(), _(
"outputs the contents of 'xtrabackup_logfile' to stdout only until the file 'xtrabackup_suspended' deleted (for '--backup')."))
4749 (
"extra-lsndir", po::value<std::string>(), _(
"(for --backup): save an extra copy of the xtrabackup_checkpoints file in this directory."))
4750 (
"incremental-lsn", po::value<std::string>(), _(
"(for --backup): copy only .ibd pages newer than specified LSN 'high:low'. ##ATTENTION##: checkpoint lsn must be used. anyone can detect your mistake. be carefully!"))
4751 (
"incremental-basedir", po::value<std::string>(), _(
"(for --backup): copy only .ibd pages newer than backup at specified directory."))
4752 (
"incremental-dir", po::value<std::string>(), _(
"(for --prepare): apply .delta files and logfile in the specified directory."))
4753 (
"tables", po::value<std::string>(), _(
"filtering by regexp for table names."))
4754 (
"tables-file", po::value<std::string>(), _(
"filtering by list of the exact database.table name in the file."))
4755 (
"create-ib-logfile", po::value<bool>(&xtrabackup_create_ib_logfile), _(
"** not work for now** creates ib_logfile* also after '--prepare'. ### If you want create ib_logfile*, only re-execute this command in same options. ###"))
4756 (
"datadir,h", po::value<std::string>(), _(
"Path to the database root."))
4757 (
"tmpdir,t", po::value<std::string>(), _(
"Path for temporary files. Several paths may be specified, separated by a colon (:), in this case they are used in a round-robin fashion."))
4758 (
"parallel", po::value<uint32_t>(¶llel)->default_value(1), _(
"Number of threads to use for parallel datafiles transfer. Does not have any effect in the stream mode. The default value is 1."))
4759 (
"innodb-adaptive-hash-index", po::value<bool>(&innobase_adaptive_hash_index)->default_value(
true), _(
"Enable InnoDB adaptive hash index (enabled by default). Disable with --skip-innodb-adaptive-hash-index."))
4760 (
"innodb-additional-mem-pool-size", po::value<long>(&innobase_additional_mem_pool_size)->default_value(1*1024*1024), _(
"Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures."))
4761 (
"innodb-autoextend-increment", po::value<uint32_t>(&srv_auto_extend_increment)->default_value(8), _(
"Data file autoextend increment in megabytes"))
4762 (
"innodb-buffer-pool-size", po::value<uint64_t>(&innobase_buffer_pool_size)->default_value(8*1024*1024), _(
"The size of the memory buffer InnoDB uses to cache data and indexes of its tables."))
4763 (
"innodb-checksums", po::value<bool>(&innobase_use_checksums)->default_value(
true), _(
"Enable InnoDB checksums validation (enabled by default). Disable with --skip-innodb-checksums."))
4764 (
"innodb-data-file-path", po::value<std::string>(), _(
"Path to individual files and their sizes."))
4765 (
"innodb-data-home-dir", po::value<std::string>(), _(
"The common part for InnoDB table spaces."))
4766 (
"innodb-doublewrite", po::value<bool>(&innobase_use_doublewrite)->default_value(
true), _(
"Enable InnoDB doublewrite buffer (enabled by default). Disable with --skip-innodb-doublewrite."))
4767 (
"innodb-file-io-threads", po::value<long>(&innobase_file_io_threads)->default_value(4), _(
"Number of file I/O threads in InnoDB."))
4768 (
"innodb-file-per-table", po::value<bool>(&innobase_file_per_table), _(
"Stores each InnoDB table to an .ibd file in the database dir."))
4769 (
"innodb-flush-log-at-trx-commit", po::value<ulong>(&srv_flush_log_at_trx_commit)->default_value(1), _(
"Set to 0 (write and flush once per second), 1 (write and flush at each commit) or 2 (write at commit, flush once per second)."))
4770 (
"innodb-flush-method", po::value<std::string>(), _(
"With which method to flush data."))
4772 (
"innodb-force-recovery", po::value<long>(&innobase_force_recovery)->default_value(0), _(
"Helps to save your data in case the disk image of the database becomes corrupt."))
4773 (
"innodb-lock-wait-timeout", po::value<long>(&innobase_lock_wait_timeout)->default_value(50), _(
"Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back."))
4774 (
"innodb-log-buffer-size", po::value<long>(&innobase_log_buffer_size)->default_value(1024*1024), _(
"The size of the buffer which InnoDB uses to write log to the log files on disk."))
4775 (
"innodb-log-file-size", po::value<log_file_constraint>(&innobase_log_file_size)->default_value(20*1024*1024L), _(
"Size of each log file in a log group."))
4776 (
"innodb-log-files-in-group", po::value<long>(&innobase_log_files_in_group)->default_value(2), _(
"Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here."))
4777 (
"innodb-log-group-home-dir", po::value<std::string>(), _(
"Path to InnoDB log files."))
4778 (
"innodb-max_dirty-pages-pct", po::value<ulong>(&srv_max_buf_pool_modified_pct)->default_value(90), _(
"Percentage of dirty pages allowed in bufferpool."))
4779 (
"innodb-open-files", po::value<long>(&innobase_open_files)->default_value(300), _(
"How many files at the maximum InnoDB keeps open at the same time."))
4781 (
"innodb-page-size", po::value<uint32_t>(&innobase_page_size)->default_value(1 << 14), _(
"The universal page size of the database."))
4782 (
"innodb-log-block-size", po::value<uint32_t>(&innobase_log_block_size)->default_value(512), _(
"###EXPERIMENTAL###: The log block size of the transaction log file. Changing for created log file is not supported. Use on your own risk!"))
4783 (
"innodb-fast-checksum", po::value<bool>(&innobase_fast_checksum), _(
"Change the algorithm of checksum for the whole of datapage to 4-bytes word based."))
4784 (
"innodb-extra-undoslots", po::value<bool>(&innobase_extra_undoslots), _(
"Enable to use about 4000 undo slots instead of default 1024. Not recommended to use, Because it is not change back to disable, once it is used."))
4785 (
"innodb-doublewrite-file", po::value<char *>(&innobase_doublewrite_file), _(
"Path to special datafile for doublewrite buffer. (default is "": not used)"))
4789 po::variables_map vm;
4791 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
4792 po::store(po::command_line_parser(argc, argv).options(commandline_options).style(style).run(), vm);
4795 if (vm.count(
"target-dir"))
4796 xtrabackup_target_dir= vm[
"target-dir"].as<std::string>().c_str();
4798 if (vm.count(
"extra-lsndir"))
4799 xtrabackup_extra_lsndir= vm[
"extra-lsndir"].as<std::string>().c_str();
4801 if (vm.count(
"incremental-lsn"))
4802 xtrabackup_incremental= vm[
"incremental-lsn"].as<std::string>().c_str();
4804 if (vm.count(
"incremental-basedir"))
4805 xtrabackup_incremental_basedir= vm[
"incremental-basedir"].as<std::string>().c_str();
4807 boost::scoped_ptr<char> xtrabackup_tables_autoptr(
new char[(vm.count(
"tables")) ? vm[
"tables"].as<std::string>().length() + 1: 0]);
4808 if (vm.count(
"tables"))
4810 xtrabackup_tables= xtrabackup_tables_autoptr.get();
4811 strcpy(xtrabackup_tables, vm[
"tables"].as<std::string>().c_str());
4814 if (vm.count(
"tables-file"))
4815 xtrabackup_tables_file= vm[
"tables-file"].as<std::string>().c_str();
4817 if (vm.count(
"tmpdir"))
4818 opt_mysql_tmpdir= vm[
"tmpdir"].as<std::string>().c_str();
4820 if (vm.count(
"innodb-data-file-path"))
4821 innobase_data_file_path= vm[
"innodb-data-file-path"].as<std::string>().c_str();
4823 boost::scoped_ptr<char> xtrabackup_incremental_dir_autoptr(
new char[(vm.count(
"incremental-dir")) ? vm[
"incremental-dir"].as<std::string>().length() + 1: 0]);
4824 if (vm.count(
"incremental-dir"))
4826 xtrabackup_incremental_dir= xtrabackup_incremental_dir_autoptr.get();
4827 strcpy(xtrabackup_incremental_dir, vm[
"incremental-dir"].as<std::string>().c_str());
4830 boost::scoped_ptr<char> innobase_data_home_dir_autoptr(
new char[(vm.count(
"innodb-data-home-dir")) ? vm[
"innodb-data-home-dir"].as<std::string>().length() + 1 : 0]);
4831 if (vm.count(
"innodb-data-home-dir"))
4833 innobase_data_home_dir= innobase_data_home_dir_autoptr.get();
4834 strcpy(innobase_data_home_dir, vm[
"innodb-data-home-dir"].as<std::string>().c_str());
4837 boost::scoped_ptr<char> innobase_flush_method_autoptr(
new char[(vm.count(
"innodb-flush-method")) ? vm[
"innodb-flush-method"].as<std::string>().length() + 1 : 0]);
4838 if (vm.count(
"innodb-flush-method"))
4840 innobase_unix_file_flush_method= innobase_flush_method_autoptr.get();
4841 strcpy(innobase_unix_file_flush_method, vm[
"innodb-flush-method"].as<std::string>().c_str());
4844 boost::scoped_ptr<char> innobase_log_group_home_dir_autoptr(
new char[(vm.count(
"innodb-log-group-home-dir")) ? vm[
"innodb-log-group-home-dir"].as<std::string>().length() + 1: 0]);
4846 if (vm.count(
"innodb-log-group-home-dir"))
4848 innobase_log_group_home_dir= innobase_log_group_home_dir_autoptr.get();
4849 strcpy(innobase_log_group_home_dir, vm[
"innodb-log-group-home-dir"].as<std::string>().c_str());
4852 xtrabackup_use_memory-= xtrabackup_use_memory % (1024*1024);
4853 if (xtrabackup_use_memory < (1024*1024)) {
4854 fprintf(stderr,
"xtrabackup: use-memory out of range\n");
4859 fprintf(stderr,
"xtrabackup: parallel needs to be greater than 0\n");
4863 innobase_additional_mem_pool_size-= innobase_additional_mem_pool_size % 1024;
4864 if (innobase_additional_mem_pool_size < (512*1024)) {
4865 fprintf(stderr,
"xtrabackup: innodb-additional-mem-pool-size out of range\n");
4869 if ((srv_auto_extend_increment < 1) || (srv_auto_extend_increment > 8)) {
4870 fprintf(stderr,
"xtrabackup: innodb-auto-extend-increment out of range\n");
4874 innobase_buffer_pool_size-= innobase_buffer_pool_size % (1024*1024);
4875 if (innobase_buffer_pool_size < (1024*1024)) {
4876 fprintf(stderr,
"xtrabackup: innodb-buffer-pool-size out of range\n");
4880 if ((innobase_file_io_threads < 4) || (innobase_file_io_threads > 64)) {
4881 fprintf(stderr,
"xtrabackup: innodb-file-io-threads out of range\n");
4885 if (srv_flush_log_at_trx_commit > 2) {
4886 fprintf(stderr,
"xtrabackup: innodb-flush-log-at-trx-commit out of range\n");
4890 if (innobase_force_recovery > 6) {
4891 fprintf(stderr,
"xtrabackup: innodb-force-recovery out of range\n");
4895 if ((innobase_lock_wait_timeout < 1) || (innobase_lock_wait_timeout > (1024*1024*1024))) {
4896 fprintf(stderr,
"xtrabackup: innodb-lock-wait-timeout out of range\n");
4900 innobase_log_buffer_size-= innobase_log_buffer_size % 1024;
4901 if (innobase_additional_mem_pool_size < (256*1024)) {
4902 fprintf(stderr,
"xtrabackup: innodb-log-buffer-size out of range\n");
4906 if (innobase_additional_mem_pool_size < (1024*1024)) {
4907 fprintf(stderr,
"xtrabackup: innodb-log-file-size out of range\n");
4911 if ((innobase_log_files_in_group < 2) || (innobase_log_files_in_group > (100))) {
4912 fprintf(stderr,
"xtrabackup: innodb-log-files-in-group out of range\n");
4916 if (srv_max_buf_pool_modified_pct > 100) {
4917 fprintf(stderr,
"xtrabackup: innodb-max-buf-pool-modified-pct out of range\n");
4921 if (innobase_open_files < 10) {
4922 fprintf(stderr,
"xtrabackup: innodb-open-files out of range\n");
4926 if ((innobase_page_size < (1 << 12)) || (innobase_page_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4927 fprintf(stderr,
"xtrabackup: innodb-page-size out of range\n");
4931 if ((innobase_log_block_size < (512)) || (innobase_log_block_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4932 fprintf(stderr,
"xtrabackup: innodb-log-block-size out of range\n");
4936 if (vm.count(
"datadir"))
4938 mysql_data_home_arg.assign(vm[
"datadir"].as<std::string>());
4942 mysql_data_home_arg.assign(LOCALSTATEDIR);
4945 mysql_data_home= (
char*)malloc(mysql_data_home_arg.length());
4946 strcpy(mysql_data_home, mysql_data_home_arg.c_str());
4948 if ((!xtrabackup_prepare) && (strcmp(mysql_data_home,
"./") == 0)) {
4949 if (!xtrabackup_print_param)
4951 printf(
"\nxtrabackup: Error: Please set parameter 'datadir'\n");
4955 if (xtrabackup_tables) {
4961 tables_regex_num = 1;
4963 p = xtrabackup_tables;
4964 while ((p = strchr(p,
',')) != NULL) {
4969 tables_regex = (regex_t*)
ut_malloc(
sizeof(regex_t) * tables_regex_num);
4971 p = xtrabackup_tables;
4972 for (i=0; i < tables_regex_num; i++) {
4973 next = strchr(p,
',');
4974 ut_a(next || i == tables_regex_num - 1);
4977 if (i != tables_regex_num - 1)
4980 regerror(regcomp(&tables_regex[i],p,REG_EXTENDED),
4981 &tables_regex[i],errbuf,
sizeof(errbuf));
4982 fprintf(stderr,
"xtrabackup: tables regcomp(%s): %s\n",p,errbuf);
4984 if (i != tables_regex_num - 1)
4990 if (xtrabackup_tables_file) {
4991 char name_buf[NAME_LEN*2+2];
4994 if (xtrabackup_stream) {
4995 fprintf(stderr,
"xtrabackup: Warning: --tables_file option doesn't affect with --stream.\n");
4996 xtrabackup_tables_file = NULL;
4997 goto skip_tables_file_register;
5000 name_buf[NAME_LEN*2+1] =
'\0';
5003 tables_hash = hash_create(1000);
5006 fp = fopen(xtrabackup_tables_file,
"r");
5008 fprintf(stderr,
"xtrabackup: cannot open %s\n", xtrabackup_tables_file);
5015 if ( fgets(name_buf, NAME_LEN*2+1, fp) == 0 ) {
5019 while (*p !=
'\0') {
5025 p = strchr(name_buf,
'\n');
5034 strcpy(table->name, name_buf);
5039 printf(
"xtrabackup: table '%s' is registered to the list.\n", table->name);
5042 skip_tables_file_register:
5046 srv_page_size_shift = UNIV_PAGE_SIZE_SHIFT_MAX;
5047 srv_page_size = UNIV_PAGE_SIZE_MAX;
5048 srv_log_block_size = 512;
5050 if (xtrabackup_backup && xtrabackup_incremental) {
5057 incremental_lsn = strtoll(xtrabackup_incremental, &endchar, 10);
5058 if (*endchar !=
'\0')
5062 fprintf(stderr,
"xtrabackup: value '%s' may be wrong format for incremental option.\n",
5063 xtrabackup_incremental);
5068 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5069 UNIV_PAGE_SIZE_MAX);
5070 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5071 UNIV_PAGE_SIZE_MAX);
5072 }
else if (xtrabackup_backup && xtrabackup_incremental_basedir) {
5073 char filename[FN_REFLEN];
5075 sprintf(filename,
"%s/%s", xtrabackup_incremental_basedir, XTRABACKUP_METADATA_FILENAME);
5077 if (xtrabackup_read_metadata(filename)) {
5079 "xtrabackup: error: failed to read metadata from %s\n",
5084 incremental_lsn = metadata_to_lsn;
5085 xtrabackup_incremental = xtrabackup_incremental_basedir;
5088 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5089 UNIV_PAGE_SIZE_MAX);
5090 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5091 UNIV_PAGE_SIZE_MAX);
5092 }
else if (xtrabackup_prepare && xtrabackup_incremental_dir) {
5093 char filename[FN_REFLEN];
5095 sprintf(filename,
"%s/%s", xtrabackup_incremental_dir, XTRABACKUP_METADATA_FILENAME);
5097 if (xtrabackup_read_metadata(filename)) {
5099 "xtrabackup: error: failed to read metadata from %s\n",
5104 incremental_lsn = metadata_from_lsn;
5105 incremental_to_lsn = metadata_to_lsn;
5106 incremental_last_lsn = metadata_last_lsn;
5107 xtrabackup_incremental = xtrabackup_incremental_dir;
5110 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE / 4 + 1) *
5112 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5116 incremental_buffer_base = (byte*) malloc((1 + 1) * UNIV_PAGE_SIZE_MAX);
5117 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5118 UNIV_PAGE_SIZE_MAX);
5120 xtrabackup_incremental = NULL;
5124 if (xtrabackup_print_param) {
5125 printf(
"# This MySQL options file was generated by XtraBackup.\n");
5126 printf(
"[mysqld]\n");
5127 printf(
"datadir = \"%s\"\n", mysql_data_home);
5128 printf(
"tmpdir = \"%s\"\n", opt_mysql_tmpdir);
5129 printf(
"innodb_data_home_dir = \"%s\"\n",
5130 innobase_data_home_dir ? innobase_data_home_dir : mysql_data_home);
5131 printf(
"innodb_data_file_path = \"%s\"\n",
5132 innobase_data_file_path ? innobase_data_file_path :
"ibdata1:10M:autoextend");
5133 printf(
"innodb_log_group_home_dir = \"%s\"\n",
5134 innobase_log_group_home_dir ? innobase_log_group_home_dir : mysql_data_home);
5135 printf(
"innodb_log_files_in_group = %ld\n", innobase_log_files_in_group);
5136 printf(
"innodb_log_file_size = %"PRIu64
"\n", (uint64_t)innobase_log_file_size);
5137 printf(
"innodb_flush_method = \"%s\"\n",
5138 (innobase_unix_file_flush_method != NULL) ?
5139 innobase_unix_file_flush_method :
"");
5143 if (!xtrabackup_stream) {
5145 if (xtrabackup_incremental) {
5146 printf(
"incremental backup from %"PRIu64
" is enabled.\n",
5150 if (xtrabackup_backup) {
5151 xtrabackup_suspend_at_end = TRUE;
5152 fprintf(stderr,
"xtrabackup: suspend-at-end is enabled.\n");
5160 if (xtrabackup_backup) num++;
5161 if (xtrabackup_stats) num++;
5162 if (xtrabackup_prepare) num++;
5170 if (xtrabackup_backup)
5171 xtrabackup_backup_func();
5174 if (xtrabackup_stats)
5175 xtrabackup_stats_func();
5178 if (xtrabackup_prepare)
5179 xtrabackup_prepare_func();
5181 free(incremental_buffer_base);
5183 if (xtrabackup_tables) {
5187 for (i = 0; i < tables_regex_num; i++) {
5188 regfree(&tables_regex[i]);
5193 if (xtrabackup_tables_file) {
5216 hash_table_free(tables_hash);