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);
493 fprintf(stderr,
"ERROR: innobase_rec_to_mysql called\n");
507 fprintf(stderr,
"ERROR: innobase_rec_reset called\n");
525 fil_system_t *system;
534 datafiles_iter_new(fil_system_t *f_system)
539 it->mutex = OS_MUTEX_CREATE();
541 it->system = f_system;
555 *space_changed = FALSE;
557 if (it->node == NULL) {
563 if (it->node != NULL)
567 it->space = (it->space == NULL) ?
571 while (it->space != NULL &&
575 if (it->space == NULL)
577 *space_changed = TRUE;
605 static void print_version(
void)
607 printf(
"%s Ver %s Rev %s for %s %s (%s)\n" ,my_progname,
608 XTRABACKUP_VERSION, XTRABACKUP_REVISION,
"Drizzle",
609 TARGET_OS, TARGET_CPU);
612 static void usage(
void)
614 puts(
"Open source backup tool for InnoDB and XtraDB\n\
616 Copyright (C) 2009 Percona Inc.\n\
618 This program is free software; you can redistribute it and/or\n\
619 modify it under the terms of the GNU General Public License\n\
620 as published by the Free Software Foundation version 2\n\
623 This program is distributed in the hope that it will be useful,\n\
624 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
625 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
626 GNU General Public License for more details.\n\
628 You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n");
630 printf(
"Usage: [%s [--defaults-file=#] --backup | %s [--defaults-file=#] --prepare] [OPTIONS]\n",my_progname,my_progname);
642 fprintf(stderr,
"xtrabackup: thd_is_replication_slave_thread() is called\n");
652 fprintf(stderr,
"xtrabackup: thd_has_edited_nontrans_tables() is called\n");
662 fprintf(stderr,
"xtrabackup: thd_is_select() is called\n");
673 fprintf(stderr,
"xtrabackup: innobase_mysql_print_thd() is called\n");
687 cs = all_charsets[cset];
689 *mbminlen = cs->mbminlen;
690 *mbmaxlen = cs->mbmaxlen;
693 *mbminlen = *mbmaxlen = 0;
706 fprintf(stderr,
"xtrabackup: innobase_convert_from_table_id() is called\n");
718 fprintf(stderr,
"xtrabackup: innobase_convert_from_id() is called\n");
726 return my_charset_utf8_general_ci.strcasecmp(a, b);
733 my_charset_utf8_general_ci.casedn_str(a);
743 fprintf(stderr,
"xtrabackup: innobase_get_stmt() is called\n");
750 char filename[FN_REFLEN];
752 int fd = internal::create_temp_file(filename, opt_mysql_tmpdir,
755 O_BINARY | O_TRUNC | O_SEQUENTIAL |
756 O_TEMPORARY | O_SHORT_LIVED |
758 O_CREAT | O_EXCL | O_RDWR);
776 fprintf(stderr,
"xtrabackup: Got error %d on dup\n",fd2);
815 if (UNIV_UNLIKELY(idlen > buflen)) {
818 memcpy(buf, s, idlen);
830 for (; idlen; idlen--) {
832 if (UNIV_UNLIKELY(c == q)) {
833 if (UNIV_UNLIKELY(buflen < 3)) {
841 if (UNIV_UNLIKELY(buflen < 2)) {
871 const char* bufend = buf + buflen;
874 const char* slash = (
const char*) memchr(
id,
'/', idlen);
883 if (UNIV_LIKELY(s < bufend)) {
892 const char temp_index_suffix[]=
"--temporary--";
896 if (s - buf + (
sizeof temp_index_suffix - 1) < buflen) {
897 memcpy(s, temp_index_suffix,
898 sizeof temp_index_suffix - 1);
899 s +=
sizeof temp_index_suffix - 1;
924 const unsigned char* a,
925 unsigned int a_length,
927 const unsigned char* b,
928 unsigned int b_length);
937 const unsigned char* a,
938 unsigned int a_length,
939 const unsigned char* b,
940 unsigned int b_length)
943 enum_field_types mysql_tp;
946 assert(a_length != UNIV_SQL_NULL);
947 assert(b_length != UNIV_SQL_NULL);
949 mysql_tp = (enum_field_types) mysql_type;
953 case DRIZZLE_TYPE_BLOB:
954 case DRIZZLE_TYPE_VARCHAR:
960 if (charset_number == default_charset_info->number) {
961 charset = default_charset_info;
963 charset = get_charset(charset_number);
965 if (charset == NULL) {
966 fprintf(stderr,
"xtrabackup needs charset %lu for doing "
967 "a comparison, but MySQL cannot "
968 "find that charset.",
969 (ulong) charset_number);
979 ret = charset->coll->strnncollsp(charset,
984 }
else if (ret > 0) {
1007 charset = get_charset((uint) charset_id);
1010 ut_ad(charset->mbmaxlen);
1014 n_chars = prefix_len / charset->mbmaxlen;
1021 if (charset->mbmaxlen > 1) {
1040 char_length = my_charpos(charset, str,
1041 str + data_len, (
int) n_chars);
1042 if (char_length > data_len) {
1043 char_length = data_len;
1046 if (data_len < prefix_len) {
1047 char_length = data_len;
1049 char_length = prefix_len;
1053 return(char_length);
1068 fprintf(stderr,
"xtrabackup: innobase_raw_format() is called\n");
1079 return(innobase_lock_wait_timeout);
1108 innobase_get_slow_log()
1119 get_bit_shift(ulint value)
1126 for (shift = 0; !(value & 1UL); shift++) {
1129 return (value >> 1) ? 0 : shift;
1133 innodb_init_param(
void)
1136 static char current_dir[3];
1141 get_charset_name(0);
1145 srv_page_size_shift = 0;
1147 if (innobase_page_size != (1 << 14)) {
1148 int n_shift = get_bit_shift(innobase_page_size);
1150 if (n_shift >= 12 && n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX) {
1152 "InnoDB: Warning: innodb_page_size has been "
1153 "changed from default value 16384.\n");
1154 srv_page_size_shift = n_shift;
1155 srv_page_size = 1 << n_shift;
1157 "InnoDB: The universal page size of the "
1158 "database is set to %lu.\n", srv_page_size);
1160 fprintf(stderr,
"InnoDB: Error: invalid value of "
1161 "innobase_page_size: %lu", innobase_page_size);
1165 srv_page_size_shift = 14;
1166 srv_page_size = (1 << srv_page_size_shift);
1169 srv_log_block_size = 0;
1170 if (innobase_log_block_size != 512) {
1171 uint n_shift = get_bit_shift(innobase_log_block_size);;
1174 "InnoDB: Warning: innodb_log_block_size has "
1175 "been changed from its default value. "
1176 "(###EXPERIMENTAL### operation)\n");
1178 srv_log_block_size = (1 << n_shift);
1180 "InnoDB: The log block size is set to %lu.\n",
1181 srv_log_block_size);
1184 srv_log_block_size = 512;
1187 if (!srv_log_block_size) {
1189 "InnoDB: Error: %lu is not valid value for "
1190 "innodb_log_block_size.\n", innobase_log_block_size);
1194 srv_fast_checksum = (ibool) innobase_fast_checksum;
1198 if (
sizeof(ulint) == 4) {
1199 if (xtrabackup_use_memory > UINT32_MAX) {
1201 "xtrabackup: use-memory can't be over 4GB"
1202 " on 32-bit systems\n");
1205 if (innobase_buffer_pool_size > UINT32_MAX) {
1207 "xtrabackup: innobase_buffer_pool_size can't be over 4GB"
1208 " on 32-bit systems\n");
1213 if (innobase_log_file_size > UINT32_MAX) {
1215 "xtrabackup: innobase_log_file_size can't be over 4GB"
1216 " on 32-bit systemsi\n");
1231 current_dir[0] = FN_CURLIB;
1232 current_dir[1] = FN_LIBCHAR;
1234 default_path = current_dir;
1241 if (xtrabackup_backup || xtrabackup_stats) {
1242 fprintf(stderr,
"xtrabackup: Target instance is assumed as followings.\n");
1244 fprintf(stderr,
"xtrabackup: Temporary instance for recovery is set as followings.\n");
1251 srv_data_home = ((xtrabackup_backup || xtrabackup_stats) && innobase_data_home_dir
1252 ? innobase_data_home_dir : default_path);
1253 fprintf(stderr,
"xtrabackup: innodb_data_home_dir = %s\n", srv_data_home);
1259 if (!innobase_data_file_path) {
1260 innobase_data_file_path = (
char*)
"ibdata1:10M:autoextend";
1262 fprintf(stderr,
"xtrabackup: innodb_data_file_path = %s\n",
1263 innobase_data_file_path);
1268 internal_innobase_data_file_path = strdup(innobase_data_file_path);
1271 internal_innobase_data_file_path);
1274 "xtrabackup: syntax error in innodb_data_file_path\n");
1276 free(internal_innobase_data_file_path);
1280 if (xtrabackup_prepare) {
1284 for (i=0; i < srv_n_data_files; i++) {
1287 p = srv_data_file_names[i];
1288 while ((p = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1291 srv_data_file_names[i] = p;
1297 srv_doublewrite_file = innobase_doublewrite_file;
1299 srv_extra_undoslots = (ibool) innobase_extra_undoslots;
1307 if (!((xtrabackup_backup || xtrabackup_stats) && innobase_log_group_home_dir)) {
1308 innobase_log_group_home_dir = default_path;
1310 if (xtrabackup_prepare && xtrabackup_incremental_dir) {
1311 innobase_log_group_home_dir = xtrabackup_incremental_dir;
1313 fprintf(stderr,
"xtrabackup: innodb_log_group_home_dir = %s\n",
1314 innobase_log_group_home_dir);
1316 #ifdef UNIV_LOG_ARCHIVE
1321 innobase_log_arch_dir = innobase_log_group_home_dir;
1323 srv_arch_dir = innobase_log_arch_dir;
1329 if (ret == FALSE || innobase_mirrored_log_groups != 1) {
1330 fprintf(stderr,
"xtrabackup: syntax error in innodb_log_group_home_dir, or a "
1331 "wrong number of mirrored log groups\n");
1333 goto mem_free_and_error;
1336 srv_adaptive_flushing = FALSE;
1337 srv_use_sys_malloc = TRUE;
1343 srv_file_flush_method_str = innobase_unix_file_flush_method;
1345 srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
1346 srv_n_log_files = (ulint) innobase_log_files_in_group;
1347 srv_log_file_size = (ulint) innobase_log_file_size;
1348 fprintf(stderr,
"xtrabackup: innodb_log_files_in_group = %ld\n",
1350 fprintf(stderr,
"xtrabackup: innodb_log_file_size = %ld\n",
1353 #ifdef UNIV_LOG_ARCHIVE
1354 srv_log_archive_on = (ulint) innobase_log_archive;
1356 srv_log_buffer_size = (ulint) innobase_log_buffer_size;
1364 srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
1366 srv_n_file_io_threads = (ulint) innobase_file_io_threads;
1368 srv_n_read_io_threads = (ulint) innobase_read_io_threads;
1369 srv_n_write_io_threads = (ulint) innobase_write_io_threads;
1371 srv_force_recovery = (ulint) innobase_force_recovery;
1373 srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
1374 srv_use_checksums = (ibool) innobase_use_checksums;
1376 btr_search_enabled = innobase_adaptive_hash_index ?
true :
false;
1378 os_use_large_pages = (ibool) innobase_use_large_pages;
1379 os_large_page_size = (ulint) innobase_large_page_size;
1387 srv_max_n_open_files = (ulint) innobase_open_files;
1388 srv_innodb_status = (ibool) innobase_create_status_file;
1390 srv_print_verbose_log = 1;
1396 data_mysql_default_charset_coll = (ulint)default_charset_info->number;
1398 ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
1424 srv_use_native_aio = FALSE;
1430 srv_use_native_aio = TRUE;
1435 srv_use_native_aio = TRUE;
1436 srv_use_native_conditions = TRUE;
1440 #elif defined(LINUX_NATIVE_AIO)
1442 if (srv_use_native_aio) {
1445 " InnoDB: Using Linux native AIO\n");
1451 srv_use_native_aio = FALSE;
1458 fprintf(stderr,
"xtrabackup: innodb_init_param(): Error occured.\n");
1469 if (err != DB_SUCCESS) {
1470 free(internal_innobase_data_file_path);
1488 fprintf(stderr,
"xtrabackup: innodb_init(): Error occured.\n");
1495 srv_fast_shutdown = (ulint) innobase_fast_shutdown;
1498 fprintf(stderr,
"xtrabackup: starting shutdown with innodb_fast_shutdown = %lu\n",
1504 free(internal_innobase_data_file_path);
1517 fprintf(stderr,
"xtrabackup: innodb_end(): Error occured.\n");
1523 xtrabackup_read_metadata(
char *filename)
1527 fp = fopen(filename,
"r");
1529 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filename);
1533 if (fscanf(fp,
"backup_type = %29s\n", metadata_type)
1536 if (fscanf(fp,
"from_lsn = %"PRIu64
"\n", &metadata_from_lsn)
1539 if (fscanf(fp,
"to_lsn = %"PRIu64
"\n", &metadata_to_lsn)
1542 if (fscanf(fp,
"last_lsn = %"PRIu64
"\n", &metadata_last_lsn)
1544 metadata_last_lsn = 0;
1553 xtrabackup_write_metadata(
char *filename)
1557 fp = fopen(filename,
"w");
1559 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filename);
1563 if (fprintf(fp,
"backup_type = %s\n", metadata_type)
1566 if (fprintf(fp,
"from_lsn = %"PRIu64
"\n", metadata_from_lsn)
1569 if (fprintf(fp,
"to_lsn = %"PRIu64
"\n", metadata_to_lsn)
1572 if (fprintf(fp,
"last_lsn = %"PRIu64
"\n", metadata_last_lsn)
1591 fp = fopen(filepath,
"r");
1597 if (fscanf(fp,
"page_size = %lu\n", &info->page_size) != 1)
1609 xb_write_delta_metadata(
const char *filepath,
const xb_delta_info_t *info)
1613 fp = fopen(filepath,
"w");
1615 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filepath);
1619 if (fprintf(fp,
"page_size = %lu\n", info->page_size) < 0)
1629 xtrabackup_io_throttling(
void)
1631 if (xtrabackup_throttle && (io_ticket--) < 0) {
1633 os_event_wait(wait_throttle);
1639 #define COPY_CHUNK 64
1642 xtrabackup_copy_datafile(
fil_node_t* node, uint thread_n)
1646 char dst_path[FN_REFLEN];
1647 char meta_path[FN_REFLEN];
1653 ulint page_in_buffer= 0;
1654 ulint incremental_buffers = 0;
1656 ulint page_size_shift;
1663 if (xtrabackup_tables && (!trx_sys_sys_space(node->
space->
id)))
1665 if (xtrabackup_tables && (node->
space->
id != 0))
1669 int p_len, regres= 0;
1676 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1681 p_len = strlen(p) - strlen(
".ibd");
1693 for (i = 0; i < tables_regex_num; i++) {
1694 regres = regexec(&tables_regex[i], prev, 1, tables_regmatch, 0);
1695 if (regres != REG_NOMATCH)
1700 *(p - 1) = SRV_PATH_SEPARATOR;
1702 if ( regres == REG_NOMATCH ) {
1703 printf(
"[%02u] Copying %s is skipped.\n",
1704 thread_n, node->
name);
1710 if (xtrabackup_tables_file && (!trx_sys_sys_space(node->
space->
id)))
1712 if (xtrabackup_tables_file && (node->
space->
id != 0))
1723 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1728 p_len = strlen(p) - strlen(
".ibd");
1743 !strcmp(table->name, prev));
1748 printf(
"[%02u] Copying %s is skipped.\n",
1749 thread_n, node->
name);
1755 zip_size = fil_space_get_zip_size(node->
space->
id);
1756 if (zip_size == ULINT_UNDEFINED) {
1757 fprintf(stderr,
"[%02u] xtrabackup: Warning: "
1758 "Failed to determine page size for %s.\n"
1759 "[%02u] xtrabackup: Warning: We assume the table was "
1760 "dropped during xtrabackup execution and ignore the "
1761 "file.\n", thread_n, node->
name, thread_n);
1763 }
else if (zip_size) {
1764 page_size = zip_size;
1765 page_size_shift = get_bit_shift(page_size);
1766 fprintf(stderr,
"[%02u] %s is compressed with page size = "
1767 "%lu bytes\n", thread_n, node->
name, page_size);
1768 if (page_size_shift < 10 || page_size_shift > 14) {
1769 fprintf(stderr,
"[%02u] xtrabackup: Error: Invalid "
1770 "page size.\n", thread_n);
1774 page_size = UNIV_PAGE_SIZE;
1775 page_size_shift = UNIV_PAGE_SIZE_SHIFT;
1779 if (trx_sys_sys_space(node->
space->
id))
1787 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1791 sprintf(dst_path,
"%s/%s", xtrabackup_target_dir, p);
1794 sprintf(dst_path,
"%s%s", xtrabackup_target_dir, strstr(node->
name, SRV_PATH_SEPARATOR_STR));
1797 if (xtrabackup_incremental) {
1798 snprintf(meta_path,
sizeof(meta_path),
1799 "%s%s", dst_path, XB_DELTA_INFO_SUFFIX);
1800 strcat(dst_path,
".delta");
1803 bzero(incremental_buffer, (page_size/4) * page_size);
1808 info.page_size = page_size;
1813 src_file = os_file_create_simple_no_error_handling(
1816 OS_FILE_READ_ONLY, &success);
1822 "[%02u] xtrabackup: Warning: cannot open %s\n"
1823 "[%02u] xtrabackup: Warning: We assume the "
1824 "table was dropped during xtrabackup execution "
1825 "and ignore the file.\n",
1826 thread_n, node->
name, thread_n);
1837 #ifdef USE_POSIX_FADVISE
1838 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
1839 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1844 dst_file = os_file_create(
1846 dst_path, OS_FILE_CREATE,
1852 fprintf(stderr,
"[%02u] xtrabackup: error: "
1853 "cannot open %s\n", thread_n, dst_path);
1857 #ifdef USE_POSIX_FADVISE
1858 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
1862 printf(
"[%02u] Copying %s \n to %s\n", thread_n,
1863 node->
name, dst_path);
1865 buf2 = (
unsigned char*)
ut_malloc(COPY_CHUNK * page_size + UNIV_PAGE_SIZE);
1866 page = (
unsigned char*)
ut_align(buf2, UNIV_PAGE_SIZE);
1868 success = os_file_read(src_file, page, 0, 0, UNIV_PAGE_SIZE);
1875 for (offset = 0; offset < file_size; offset += COPY_CHUNK * page_size) {
1878 ulint retry_count = 10;
1880 if ((ulint)(file_size - offset) > COPY_CHUNK * page_size) {
1881 chunk = COPY_CHUNK * page_size;
1883 chunk = (ulint)(file_size - offset);
1887 xtrabackup_io_throttling();
1889 success = os_file_read(src_file, page,
1890 (ulint)(offset & 0xFFFFFFFFUL),
1891 (ulint)(offset >> 32), chunk);
1897 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1898 if (buf_page_is_corrupted(page + chunk_offset, zip_size))
1902 trx_sys_sys_space(node->
space->
id)
1906 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1908 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1909 < FSP_EXTENT_SIZE * 3) {
1913 ut_a(page_size == UNIV_PAGE_SIZE);
1914 fprintf(stderr,
"[%02u] xtrabackup: "
1915 "Page %lu seems double write "
1916 "buffer. passing the check.\n",
1919 (IB_INT64)chunk_offset) >>
1923 if (retry_count == 0) {
1925 "[%02u] xtrabackup: "
1926 "Error: 10 retries "
1927 "resulted in fail. This"
1933 fprintf(stderr,
"[%02u] xtrabackup: "
1934 "Database page corruption "
1935 "detected at page %lu. "
1939 (IB_INT64)chunk_offset)
1940 >> page_size_shift));
1946 if (xtrabackup_incremental) {
1947 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1950 if (ut_dulint_cmp(incremental_lsn,
1951 MACH_READ_64(page + chunk_offset +
FIL_PAGE_LSN)) < 0) {
1953 IB_INT64 offset_on_page;
1955 if (page_in_buffer == page_size/4) {
1957 success = os_file_write(dst_path, dst_file, incremental_buffer,
1958 ((incremental_buffers * (page_size/4))
1959 << page_size_shift) & 0xFFFFFFFFUL,
1960 (incremental_buffers * (page_size/4))
1961 >> (32 - page_size_shift),
1962 page_in_buffer * page_size);
1967 incremental_buffers++;
1970 bzero(incremental_buffer, (page_size/4) * page_size);
1976 offset_on_page = ((offset + (IB_INT64)chunk_offset) >> page_size_shift);
1977 ut_a(offset_on_page >> 32 == 0);
1979 mach_write_to_4(incremental_buffer + page_in_buffer * 4, (ulint)offset_on_page);
1980 memcpy(incremental_buffer + page_in_buffer * page_size,
1981 page + chunk_offset, page_size);
1988 success = os_file_write(dst_path, dst_file, page,
1989 (ulint)(offset & 0xFFFFFFFFUL),
1990 (ulint)(offset >> 32), chunk);
1998 if (xtrabackup_incremental) {
2000 if (page_in_buffer != page_size/4) {
2001 mach_write_to_4(incremental_buffer + page_in_buffer * 4, 0xFFFFFFFFUL);
2007 success = os_file_write(dst_path, dst_file, incremental_buffer,
2008 ((incremental_buffers * (page_size/4))
2009 << page_size_shift) & 0xFFFFFFFFUL,
2010 (incremental_buffers * (page_size/4))
2011 >> (32 - page_size_shift),
2012 page_in_buffer * page_size);
2016 if (!xb_write_delta_metadata(meta_path, &info)) {
2017 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2018 "failed to write meta info for %s\n",
2019 thread_n, dst_path);
2024 success = os_file_flush(dst_file);
2043 printf(
"[%02u] ...done\n", thread_n);
2045 os_file_close(src_file);
2047 os_file_close(dst_file);
2051 if (src_file != -1 && !node->
open)
2052 os_file_close(src_file);
2054 os_file_close(dst_file);
2057 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2058 "xtrabackup_copy_datafile() failed.\n", thread_n);
2062 if (src_file != -1 && !node->
open)
2063 os_file_close(src_file);
2065 os_file_close(dst_file);
2068 fprintf(stderr,
"[%02u] xtrabackup: Warning: skipping file %s.\n",
2069 thread_n, node->
name);
2074 xtrabackup_copy_logfile(LSN64 from_lsn,
bool is_last)
2078 LSN64 group_scanned_lsn;
2079 LSN64 contiguous_lsn;
2083 if (!xtrabackup_stream)
2084 ut_a(dst_log != -1);
2087 contiguous_lsn = ut_dulint_align_down(from_lsn,
2103 start_lsn = contiguous_lsn;
2108 xtrabackup_io_throttling();
2111 group, start_lsn, end_lsn);
2123 ulint scanned_checkpoint_no = 0;
2127 log_block = log_sys->
buf;
2128 scanned_lsn = start_lsn;
2135 || !log_block_checksum_is_ok_or_old_format(log_block)) {
2138 && log_block_checksum_is_ok_or_old_format(log_block)) {
2140 ">> ###Warning###: The copying transaction log migh be overtaken already by the target.\n"
2141 ">> : Waiting log block no %lu, but the bumber is already %lu.\n"
2142 ">> : If the number equals %lu + n * %lu, it should be overtaken already.\n",
2151 && !log_block_checksum_is_ok_or_old_format(
2154 "xtrabackup: Log block no %lu at lsn %"PRIu64
" has\n"
2155 "xtrabackup: ok header, but checksum field contains %lu, should be %lu\n",
2177 if (ut_dulint_cmp(scanned_lsn, contiguous_lsn) > 0) {
2178 contiguous_lsn = scanned_lsn;
2185 (scanned_checkpoint_no > 0)
2187 < scanned_checkpoint_no)
2188 && (scanned_checkpoint_no
2199 scanned_lsn = ut_dulint_add(scanned_lsn, data_len);
2211 group_scanned_lsn = scanned_lsn;
2224 write_size = ut_dulint_minus(
2231 if (!xtrabackup_stream) {
2232 success = os_file_write(dst_log_path, dst_log, log_sys->
buf,
2233 (ulint)(log_copy_offset & 0xFFFFFFFFUL),
2234 (ulint)(log_copy_offset >> 32), write_size);
2237 ulint stdout_write_size = write_size;
2238 if (finished && !is_last
2242 if (stdout_write_size) {
2243 ret = write(fileno(stdout), log_sys->
buf, stdout_write_size);
2244 if (ret == stdout_write_size) {
2247 fprintf(stderr,
"write: %lu > %lu\n", stdout_write_size, ret);
2255 log_copy_offset += write_size;
2257 if (finished && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE)
2264 if (!xtrabackup_stream) {
2265 fprintf(stderr,
"xtrabackup: Error: os_file_write to %s\n", dst_log_path);
2267 fprintf(stderr,
"xtrabackup: Error: write to stdout\n");
2279 start_lsn = end_lsn;
2287 fprintf(stderr,
">> log scanned up to (%"PRIu64
")\n",group->
scanned_lsn);
2292 log_copy_scanned_lsn = group_scanned_lsn;
2295 ut_a(group == NULL);
2299 if (!xtrabackup_stream) {
2300 success = os_file_flush(dst_log);
2313 if (!xtrabackup_stream)
2314 os_file_close(dst_log);
2315 fprintf(stderr,
"xtrabackup: Error: xtrabackup_copy_logfile() failed.\n");
2320 #define SLEEPING_PERIOD 5
2333 if (!xtrabackup_stream)
2334 ut_a(dst_log != -1);
2336 log_copying_running = TRUE;
2338 while(log_copying) {
2342 if(counter >= SLEEPING_PERIOD * 5) {
2343 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, FALSE))
2350 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, TRUE))
2353 log_copying_succeed = TRUE;
2355 log_copying_running = FALSE;
2372 ut_a(xtrabackup_backup);
2374 while (log_copying) {
2382 io_ticket = xtrabackup_throttle;
2387 xtrabackup_throttle = 0;
2411 segment = *((ulint*)arg);
2414 fil_aio_wait(segment);
2435 xtrabackup_create_output_dir(
2440 char path[FN_REFLEN];
2444 ptr1 = strstr(space->
name, SRV_PATH_SEPARATOR_STR);
2446 ptr2 = strstr(ptr1 + 1, SRV_PATH_SEPARATOR_STR);
2451 if(!trx_sys_sys_space(space->
id) && ptr2)
2453 if(space->
id && ptr2)
2458 snprintf(path,
sizeof(path),
"%s%s", xtrabackup_target_dir,
2460 *ptr2 = SRV_PATH_SEPARATOR;
2462 if (mkdir(path, 0777) != 0 && errno != EEXIST) {
2464 "xtrabackup: Error: cannot mkdir %d: %s\n",
2476 data_copy_thread_func(
2481 uint num = ctxt->num;
2483 ibool space_changed;
2486 while ((node = datafiles_iter_next(ctxt->it, &space_changed)) != NULL) {
2487 space = node->
space;
2489 if (space_changed && xtrabackup_create_output_dir(space))
2493 if(xtrabackup_copy_datafile(node, num)) {
2494 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2495 "failed to copy datafile.\n",
2506 OS_THREAD_DUMMY_RETURN;
2511 xtrabackup_backup_func(
void)
2513 struct stat stat_info;
2516 #ifdef USE_POSIX_FADVISE
2517 fprintf(stderr,
"xtrabackup: uses posix_fadvise().\n");
2522 if (chdir(mysql_real_data_home) != 0)
2524 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
2527 fprintf(stderr,
"xtrabackup: cd to %s\n", mysql_real_data_home);
2529 mysql_data_home= mysql_data_home_buff;
2530 mysql_data_home[0]=FN_CURLIB;
2531 mysql_data_home[1]=0;
2534 srv_read_only = TRUE;
2537 if(innodb_init_param())
2540 if (srv_file_flush_method_str == NULL) {
2546 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"fsync")) {
2549 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DSYNC")) {
2552 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DIRECT")) {
2554 fprintf(stderr,
"xtrabackup: use O_DIRECT\n");
2555 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"littlesync")) {
2558 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"nosync")) {
2561 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"normal")) {
2563 os_aio_use_native_aio = FALSE;
2565 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"unbuffered")) {
2567 os_aio_use_native_aio = FALSE;
2569 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
2570 "async_unbuffered")) {
2575 "xtrabackup: Unrecognized value %s for innodb_flush_method\n",
2576 srv_file_flush_method_str);
2580 if (srv_buf_pool_size >= 1000 * 1024 * 1024) {
2586 srv_max_n_threads = 50000;
2589 }
else if (srv_buf_pool_size >= 8 * 1024 * 1024) {
2591 srv_max_n_threads = 10000;
2593 srv_max_n_threads = 1000;
2602 nr = srv_n_data_files;
2604 for (i = 0; i < nr; i++) {
2605 srv_data_file_sizes[i] = srv_data_file_sizes[i]
2606 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2609 srv_last_file_size_max = srv_last_file_size_max
2610 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2612 srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
2614 srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
2623 ibool create_new_db;
2625 ibool create_new_doublewrite_file;
2627 ibool log_file_created;
2628 ibool log_created = FALSE;
2629 ibool log_opened = FALSE;
2630 LSN64 min_flushed_lsn;
2631 LSN64 max_flushed_lsn;
2632 ulint sum_of_new_sizes;
2639 #define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
2640 #define SRV_MAX_N_PENDING_SYNC_IOS 100
2642 srv_n_file_io_threads = 2 + srv_n_read_io_threads + srv_n_write_io_threads;
2644 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD,
2645 srv_n_read_io_threads,
2646 srv_n_write_io_threads,
2647 SRV_MAX_N_PENDING_SYNC_IOS);
2649 fil_init(srv_file_per_table ? 50000 : 5000,
2650 srv_max_n_open_files);
2657 for (i = 0; i < srv_n_file_io_threads; i++) {
2665 err = open_or_create_data_files(&create_new_db,
2667 &create_new_doublewrite_file,
2669 &min_flushed_lsn, &max_flushed_lsn,
2671 if (err != DB_SUCCESS) {
2673 "xtrabackup: Could not open or create data files.\n"
2674 "xtrabackup: If you tried to add new data files, and it failed here,\n"
2675 "xtrabackup: you should now edit innodb_data_file_path in my.cnf back\n"
2676 "xtrabackup: to what it was, and remove the new ibdata files InnoDB created\n"
2677 "xtrabackup: in this failed attempt. InnoDB only wrote those files full of\n"
2678 "xtrabackup: zeros, but did not yet use them in any way. But be careful: do not\n"
2679 "xtrabackup: remove old data files which contain your precious data!\n");
2686 if (create_new_db) {
2687 fprintf(stderr,
"xtrabackup: Something wrong with source files...\n");
2691 for (i = 0; i < srv_n_log_files; i++) {
2692 err = open_or_create_log_file(create_new_db, &log_file_created,
2694 if (err != DB_SUCCESS) {
2700 if (log_file_created) {
2705 if ((log_opened && create_new_db)
2706 || (log_opened && log_created)) {
2708 "xtrabackup: Error: all log files must be created at the same time.\n"
2709 "xtrabackup: All log files must be created also in database creation.\n"
2710 "xtrabackup: If you want bigger or smaller log files, shut down the\n"
2711 "xtrabackup: database and make sure there were no errors in shutdown.\n"
2712 "xtrabackup: Then delete the existing log files. Edit the .cnf file\n"
2713 "xtrabackup: and start the database again.\n");
2721 if (log_file_created) {
2722 fprintf(stderr,
"xtrabackup: Something wrong with source files...\n");
2726 fil_load_single_table_tablespaces();
2731 if (xtrabackup_extra_lsndir
2732 && (stat(xtrabackup_extra_lsndir,&stat_info) != 0)
2733 && (mkdir(xtrabackup_extra_lsndir,0777) != 0)){
2734 fprintf(stderr,
"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_extra_lsndir);
2739 if (!xtrabackup_stream) {
2742 if (stat(xtrabackup_target_dir,&stat_info) != 0
2743 && (mkdir(xtrabackup_target_dir,0777) != 0)){
2744 fprintf(stderr,
"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_target_dir);
2749 fprintf(stderr,
"xtrabackup: Stream mode.\n");
2755 fil_system_t* f_system = fil_system;
2761 boost::scoped_array<byte> log_hdr_buf_(
2762 new byte[LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE]);
2772 log_hdr_buf = (byte*)
ut_align(log_hdr_buf_.get(),
2783 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2785 if (err != DB_SUCCESS) {
2793 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2794 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2799 0, 0, LOG_FILE_HDR_SIZE,
2800 log_hdr_buf, max_cp_group);
2803 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2805 if (err != DB_SUCCESS) {
2813 if(ut_dulint_cmp(checkpoint_no_start,
2814 MACH_READ_64(buf + LOG_CHECKPOINT_NO)) != 0) {
2815 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2816 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2817 goto reread_log_header;
2820 if (!xtrabackup_stream) {
2823 sprintf(dst_log_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
2826 dst_log = os_file_create(
2828 dst_log_path, OS_FILE_CREATE,
2836 "xtrabackup: error: cannot open %s\n",
2841 #ifdef USE_POSIX_FADVISE
2842 posix_fadvise(dst_log, 0, 0, POSIX_FADV_DONTNEED);
2848 strcpy((
char*) log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2851 (
char*) log_hdr_buf + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
2852 + (
sizeof "xtrabkup ") - 1));
2854 if (!xtrabackup_stream) {
2855 success = os_file_write(dst_log_path, dst_log, log_hdr_buf,
2856 0, 0, LOG_FILE_HDR_SIZE);
2859 if ((write(fileno(stdout), log_hdr_buf, LOG_FILE_HDR_SIZE)
2860 - LOG_FILE_HDR_SIZE) == 0)
2868 log_copy_offset += LOG_FILE_HDR_SIZE;
2871 os_file_close(dst_log);
2879 if(xtrabackup_throttle) {
2882 io_ticket = xtrabackup_throttle;
2890 if(xtrabackup_copy_logfile(checkpoint_lsn_start, FALSE))
2898 if (!xtrabackup_stream) {
2907 printf(
"xtrabackup: Starting %u threads for parallel "
2908 "data files transfer\n", parallel);
2910 it = datafiles_iter_new(f_system);
2913 "xtrabackup: Error: "
2914 "datafiles_iter_new() failed.\n");
2924 count_mutex = OS_MUTEX_CREATE();
2926 for (i = 0; i < parallel; i++) {
2927 data_threads[i].it = it;
2928 data_threads[i].num = i+1;
2929 data_threads[i].count = &count;
2930 data_threads[i].count_mutex = count_mutex;
2933 &data_threads[i].
id);
2950 datafiles_iter_free(it);
2959 if (xtrabackup_suspend_at_end) {
2961 char suspend_path[FN_REFLEN];
2962 ibool success, exists;
2963 os_file_type_t type;
2965 sprintf(suspend_path,
"%s%s", xtrabackup_target_dir,
2966 "/xtrabackup_suspended");
2970 suspend_file = os_file_create(
2972 suspend_path, OS_FILE_OVERWRITE,
2976 fprintf(stderr,
"xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
2979 if (suspend_file != -1)
2980 os_file_close(suspend_file);
2989 xtrabackup_suspend_at_end = FALSE;
2993 latest_cp = ut_dulint_zero;
2999 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
3001 if (err != DB_SUCCESS) {
3002 fprintf(stderr,
"xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
3008 latest_cp = MACH_READ_64(log_sys->
checkpoint_buf + LOG_CHECKPOINT_LSN);
3010 if (!xtrabackup_stream) {
3011 printf(
"xtrabackup: The latest check point (for incremental): '%"PRIu64
"'\n",
3014 fprintf(stderr,
"xtrabackup: The latest check point (for incremental): '%"PRIu64
"'\n",
3020 log_copying = FALSE;
3021 if (!xtrabackup_stream) {
3022 printf(
"xtrabackup: Stopping log copying thread");
3023 while (log_copying_running) {
3029 while (log_copying_running)
3035 char filename[FN_REFLEN];
3037 if(!xtrabackup_incremental) {
3038 strcpy(metadata_type,
"full-backuped");
3039 metadata_from_lsn = ut_dulint_zero;
3041 strcpy(metadata_type,
"incremental");
3042 metadata_from_lsn = incremental_lsn;
3044 metadata_to_lsn = latest_cp;
3045 metadata_last_lsn = log_copy_scanned_lsn;
3047 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
3048 if (xtrabackup_write_metadata(filename))
3049 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
3051 if(xtrabackup_extra_lsndir) {
3052 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3053 if (xtrabackup_write_metadata(filename))
3054 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3058 if (!log_copying_succeed) {
3059 fprintf(stderr,
"xtrabackup: Error: log_copying_thread failed.\n");
3063 if (!xtrabackup_stream)
3064 os_file_close(dst_log);
3069 if (!xtrabackup_stream) {
3070 printf(
"xtrabackup: Transaction log of lsn (%"PRIu64
") to (%"PRIu64
") was copied.\n",
3071 checkpoint_lsn_start, log_copy_scanned_lsn);
3073 fprintf(stderr,
"xtrabackup: Transaction log of lsn (%"PRIu64
") to (%"PRIu64
") was copied.\n",
3074 checkpoint_lsn_start, log_copy_scanned_lsn);
3075 if(xtrabackup_extra_lsndir) {
3076 char filename[FN_REFLEN];
3077 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3078 if (xtrabackup_write_metadata(filename))
3079 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3086 xtrabackup_stats_level(
3095 ulint right_page_no;
3102 ulint* offsets = NULL;
3104 uint64_t n_pages, n_pages_extern;
3105 uint64_t sum_data, sum_data_extern;
3109 n_pages = sum_data = n_recs = 0;
3110 n_pages_extern = sum_data_extern = 0;
3116 fprintf(stdout,
" leaf pages: ");
3118 fprintf(stdout,
" level %lu pages: ", level);
3123 block = btr_root_block_get(index, &mtr);
3124 page = buf_block_get_frame(block);
3127 zip_size = fil_space_get_zip_size(space);
3138 node_ptr = page_cur_get_rec(&cursor);
3139 offsets = rec_get_offsets(node_ptr, index, offsets,
3140 ULINT_UNDEFINED, &heap);
3142 block = btr_node_ptr_get_child(node_ptr, index, offsets, &mtr);
3143 page = buf_block_get_frame(block);
3167 ulint offsets_[REC_OFFS_NORMAL_SIZE];
3168 ulint* local_offsets = offsets_;
3170 *offsets_ = (
sizeof offsets_) /
sizeof *offsets_;
3181 local_offsets = rec_get_offsets(cur.
rec, index, local_offsets,
3182 ULINT_UNDEFINED, &local_heap);
3185 for (i = 0; i < n_fields; i++) {
3198 data = rec_get_nth_field(cur.
rec, local_offsets, i, &local_len);
3208 fprintf(stderr,
"\nWarning: several record may share same external page.\n");
3213 local_block =
btr_block_get(space_id, zip_size, page_no, RW_S_LATCH, &local_mtr);
3214 local_page = buf_block_get_frame(local_block);
3216 blob_header = local_page + offset;
3217 #define BTR_BLOB_HDR_PART_LEN 0
3218 #define BTR_BLOB_HDR_NEXT_PAGE_NO 4
3234 sum_data_extern += part_len;
3255 block =
btr_block_get(space, zip_size, right_page_no, RW_X_LATCH, &mtr);
3256 page = buf_block_get_frame(block);
3262 page_size = zip_size;
3264 page_size = UNIV_PAGE_SIZE;
3268 fprintf(stdout,
"recs=%"PRIu64
", ", n_recs);
3270 fprintf(stdout,
"pages=%"PRIu64
", data=%"PRIu64
" bytes, data/pages=%"PRIu64
"%%",
3272 ((sum_data * 100)/ page_size)/n_pages);
3275 if (level == 0 && n_pages_extern) {
3278 fprintf(stdout,
" external pages: ");
3280 fprintf(stdout,
"pages=%"PRIu64
", data=%"PRIu64
" bytes, data/pages=%"PRIu64
"%%",
3281 n_pages_extern, sum_data_extern,
3282 ((sum_data_extern * 100)/ page_size)/n_pages_extern);
3288 xtrabackup_stats_level(index, level - 1);
3295 xtrabackup_stats_func(
void)
3301 if (chdir(mysql_real_data_home) != 0)
3303 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3306 fprintf(stderr,
"xtrabackup: cd to %s\n", mysql_real_data_home);
3308 mysql_data_home= mysql_data_home_buff;
3309 mysql_data_home[0]=FN_CURLIB;
3310 mysql_data_home[1]=0;
3313 srv_read_only = TRUE;
3314 srv_fake_write = TRUE;
3317 if(innodb_init_param())
3322 for (n = 0; n < srv_n_log_files; n++) {
3323 char logname[FN_REFLEN];
3325 os_file_type_t type;
3327 sprintf(logname,
"ib_logfile%lu", (ulong) n);
3329 type != OS_FILE_TYPE_FILE) {
3330 fprintf(stderr,
"xtrabackup: Error: "
3331 "Cannot find log file %s.\n", logname);
3332 fprintf(stderr,
"xtrabackup: Error: "
3333 "to use the statistics feature, you need a "
3334 "clean copy of the database including "
3335 "correctly sized log files, so you need to "
3336 "execute with --prepare twice to use this "
3337 "functionality on a backup.\n");
3342 fprintf(stderr,
"xtrabackup: Starting 'read-only' InnoDB instance to gather index statistics.\n"
3343 "xtrabackup: Using %"PRIu64
" bytes for buffer pool (set by --use-memory parameter)\n",
3344 xtrabackup_use_memory);
3349 fprintf(stdout,
"\n\n<INDEX STATISTICS>\n");
3366 mutex_enter(&kernel_mutex);
3367 srv_fatal_semaphore_wait_threshold += 72000;
3368 mutex_exit(&kernel_mutex);
3370 mutex_enter(&(dict_sys->
mutex));
3391 mutex_exit(&(dict_sys->
mutex));
3395 mutex_enter(&kernel_mutex);
3396 srv_fatal_semaphore_wait_threshold -= 72000;
3397 mutex_exit(&kernel_mutex);
3402 field = rec_get_nth_field_old(rec, 0, &len);
3409 char* table_name =
mem_strdupl((
char*) field, len);
3411 btr_pcur_store_position(&pcur, &mtr);
3419 if (xtrabackup_tables) {
3424 p = strstr(table->
name, SRV_PATH_SEPARATOR_STR);
3429 for (i = 0; i < tables_regex_num; i++) {
3430 regres = regexec(&tables_regex[i], table->
name, 1, tables_regmatch, 0);
3431 if (regres != REG_NOMATCH)
3436 *p = SRV_PATH_SEPARATOR;
3438 if ( regres == REG_NOMATCH )
3442 if (xtrabackup_tables_file) {
3448 ut_ad(xtable->name),
3449 !strcmp(xtable->name, table->
name));
3456 if (table == NULL) {
3457 fputs(
"InnoDB: Failed to load table ", stderr);
3466 if (dict_table_get_first_index(table)) {
3468 dict_update_statistics(table, TRUE, FALSE);
3469 #elif defined(INNODB_VERSION_SHORT)
3470 dict_update_statistics(table, TRUE);
3472 dict_update_statistics_low(table, TRUE);
3479 while (index != NULL) {
3491 " table: %s, index: %s, space id: %lu, root page: %lu"
3493 "\n estimated statistics in dictionary:\n"
3494 " key vals: %lu, leaf pages: %lu, size pages: %lu\n"
3495 " real statistics:\n",
3497 (ulong) index->
space,
3498 (ulong) index->
page,
3499 (ulong) fil_space_get_zip_size(index->
space),
3512 root = btr_root_get(index, &local_mtr);
3516 xtrabackup_stats_level(index, page_level);
3547 xtrabackup_init_temp_log(
void)
3550 char src_path[FN_REFLEN];
3551 char dst_path[FN_REFLEN];
3556 byte* log_buf_ = NULL;
3562 LSN64 checkpoint_no;
3566 max_no = ut_dulint_zero;
3568 if(!xtrabackup_incremental_dir) {
3569 sprintf(dst_path,
"%s%s", xtrabackup_target_dir,
"/ib_logfile0");
3570 sprintf(src_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
3572 sprintf(dst_path,
"%s%s", xtrabackup_incremental_dir,
"/ib_logfile0");
3573 sprintf(src_path,
"%s%s", xtrabackup_incremental_dir,
"/xtrabackup_logfile");
3579 src_file = os_file_create_simple_no_error_handling(
3582 OS_FILE_READ_WRITE , &success);
3588 "xtrabackup: Warning: cannot open %s. will try to find.\n",
3592 src_file = os_file_create_simple_no_error_handling(
3595 OS_FILE_READ_WRITE , &success);
3599 " xtrabackup: Fatal error: cannot find %s.\n",
3605 log_buf_ = (
unsigned char*)
ut_malloc(LOG_FILE_HDR_SIZE * 2);
3606 log_buf = (
unsigned char*)
ut_align(log_buf_, LOG_FILE_HDR_SIZE);
3608 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3613 if (
ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3614 (byte*)
"xtrabkup", (
sizeof "xtrabkup") - 1) == 0) {
3616 " xtrabackup: 'ib_logfile0' seems to be 'xtrabackup_logfile'. will retry.\n");
3621 os_file_close(src_file);
3625 success = os_file_rename(
3627 dst_path, src_path);
3636 " xtrabackup: Fatal error: cannot find %s.\n",
3642 os_file_close(src_file);
3648 #ifdef USE_POSIX_FADVISE
3649 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3650 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3661 log_buf_ = (
unsigned char*)
ut_malloc(UNIV_PAGE_SIZE * 129);
3662 log_buf = (
unsigned char*)
ut_align(log_buf_, UNIV_PAGE_SIZE);
3665 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3670 if (
ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3671 (byte*)
"xtrabkup", (
sizeof "xtrabkup") - 1) != 0 ) {
3672 printf(
"xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.\n");
3681 for (field = LOG_CHECKPOINT_1; field <= LOG_CHECKPOINT_2;
3682 field += LOG_CHECKPOINT_2 - LOG_CHECKPOINT_1) {
3683 if (!recv_check_cp_is_consistent(log_buf + field))
3684 goto not_consistent;
3686 checkpoint_no = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_NO);
3688 if (ut_dulint_cmp(checkpoint_no, max_no) >= 0) {
3689 max_no = checkpoint_no;
3690 max_lsn = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_LSN);
3709 if (ut_dulint_cmp(max_no, ut_dulint_zero) == 0) {
3710 fprintf(stderr,
"xtrabackup: No valid checkpoint found.\n");
3716 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN, max_lsn);
3718 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3719 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3721 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_ARCHIVED_LSN,
3722 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3723 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE))));
3725 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_1, LOG_CHECKPOINT_CHECKSUM_1);
3726 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3728 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN,
3729 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3730 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3732 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN, max_lsn);
3734 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3735 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
3737 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_ARCHIVED_LSN,
3738 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3739 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE))));
3741 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_2, LOG_CHECKPOINT_CHECKSUM_1);
3742 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3744 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN,
3745 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3746 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3749 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3756 if (file_size % UNIV_PAGE_SIZE) {
3757 memset(log_buf, 0, UNIV_PAGE_SIZE);
3758 success = os_file_write(src_path, src_file, log_buf,
3759 (ulint)(file_size & 0xFFFFFFFFUL),
3760 (ulint)(file_size >> 32),
3761 UNIV_PAGE_SIZE - (file_size % UNIV_PAGE_SIZE));
3773 memset(log_buf, 0, UNIV_PAGE_SIZE * 128);
3774 expand = file_size / UNIV_PAGE_SIZE / 8;
3776 for (; expand > 128; expand -= 128) {
3777 success = os_file_write(src_path, src_file, log_buf,
3778 (ulint)(file_size & 0xFFFFFFFFUL),
3779 (ulint)(file_size >> 32),
3780 UNIV_PAGE_SIZE * 128);
3784 file_size += UNIV_PAGE_SIZE * 128;
3788 success = os_file_write(src_path, src_file, log_buf,
3789 (ulint)(file_size & 0xFFFFFFFFUL),
3790 (ulint)(file_size >> 32),
3791 expand * UNIV_PAGE_SIZE);
3795 file_size += UNIV_PAGE_SIZE * expand;
3800 if (file_size < 2*1024*1024L) {
3801 memset(log_buf, 0, UNIV_PAGE_SIZE);
3802 while (file_size < 2*1024*1024L) {
3803 success = os_file_write(src_path, src_file, log_buf,
3804 (ulint)(file_size & 0xFFFFFFFFUL),
3805 (ulint)(file_size >> 32),
3810 file_size += UNIV_PAGE_SIZE;
3815 printf(
"xtrabackup: xtrabackup_logfile detected: size=%"PRIu64
", start_lsn=(%"PRIu64
")\n",
3816 file_size, max_lsn);
3818 os_file_close(src_file);
3822 innobase_log_group_home_dir_backup = innobase_log_group_home_dir;
3823 innobase_log_file_size_backup = innobase_log_file_size;
3824 innobase_log_files_in_group_backup = innobase_log_files_in_group;
3827 innobase_log_group_home_dir = NULL;
3828 innobase_log_file_size = file_size;
3829 innobase_log_files_in_group = 1;
3831 srv_thread_concurrency = 0;
3834 success = os_file_rename(
3836 src_path, dst_path);
3840 xtrabackup_logfile_is_renamed = TRUE;
3847 os_file_close(src_file);
3854 os_file_close(src_file);
3857 fprintf(stderr,
"xtrabackup: Error: xtrabackup_init_temp_log() failed.\n");
3869 const char *delta_path,
3873 size_t len = strlen(delta_path);
3875 if (len <= 6 || strcmp(delta_path + len - 6,
".delta")) {
3878 memcpy(meta_path, delta_path, len - 6);
3879 strcpy(meta_path + len - 6, XB_DELTA_INFO_SUFFIX);
3885 xtrabackup_apply_delta(
3886 const char* dirname,
3888 const char* filename,
3894 char src_path[FN_REFLEN];
3895 char dst_path[FN_REFLEN];
3896 char meta_path[FN_REFLEN];
3899 ibool last_buffer = FALSE;
3900 ulint page_in_buffer;
3901 ulint incremental_buffers = 0;
3905 ulint page_size_shift;
3907 ut_a(xtrabackup_incremental);
3910 snprintf(src_path,
sizeof(src_path),
"%s/%s/%s",
3911 dirname, dbname, filename);
3912 snprintf(dst_path,
sizeof(dst_path),
"%s/%s/%s",
3913 xtrabackup_real_target_dir, dbname, filename);
3915 snprintf(src_path,
sizeof(src_path),
"%s/%s",
3917 snprintf(dst_path,
sizeof(dst_path),
"%s/%s",
3918 xtrabackup_real_target_dir, filename);
3920 dst_path[strlen(dst_path) - 6] =
'\0';
3922 if (!get_meta_path(src_path, meta_path)) {
3930 if (!xb_read_delta_metadata(meta_path, &info)) {
3934 page_size = info.page_size;
3935 page_size_shift = get_bit_shift(page_size);
3936 fprintf(stderr,
"xtrabackup: page size for %s is %lu bytes\n",
3937 src_path, page_size);
3938 if (page_size_shift < 10 ||
3939 page_size_shift > UNIV_PAGE_SIZE_SHIFT_MAX) {
3941 "xtrabackup: error: invalid value of page_size "
3942 "(%lu bytes) read from %s\n", page_size, meta_path);
3946 src_file = os_file_create_simple_no_error_handling(
3952 "xtrabackup: error: cannot open %s\n",
3957 #ifdef USE_POSIX_FADVISE
3958 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3959 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3966 dst_file = os_file_create_simple_no_error_handling(
3972 "xtrabackup: error: cannot open %s\n",
3977 #ifdef USE_POSIX_FADVISE
3978 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
3985 printf(
"Applying %s ...\n", src_path);
3987 while (!last_buffer) {
3988 ulint cluster_header;
3992 success = os_file_read(src_file, incremental_buffer,
3993 ((incremental_buffers * (page_size / 4))
3994 << page_size_shift) & 0xFFFFFFFFUL,
3995 (incremental_buffers * (page_size / 4))
3996 >> (32 - page_size_shift),
4003 switch(cluster_header) {
4011 "xtrabackup: error: %s seems not .delta file.\n",
4016 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4023 ut_a(last_buffer || page_in_buffer == page_size / 4);
4026 success = os_file_read(src_file, incremental_buffer,
4027 ((incremental_buffers * (page_size / 4))
4028 << page_size_shift) & 0xFFFFFFFFUL,
4029 (incremental_buffers * (page_size / 4))
4030 >> (32 - page_size_shift),
4031 page_in_buffer * page_size);
4036 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4038 ulint offset_on_page;
4040 offset_on_page =
mach_read_from_4(incremental_buffer + page_in_buffer * 4);
4042 if (offset_on_page == 0xFFFFFFFFUL)
4052 success = os_file_write(dst_path, dst_file,
4053 incremental_buffer +
4054 page_in_buffer * page_size,
4055 (offset_on_page << page_size_shift) &
4057 offset_on_page >> (32 - page_size_shift),
4064 incremental_buffers++;
4068 os_file_close(src_file);
4070 os_file_close(dst_file);
4075 os_file_close(src_file);
4077 os_file_close(dst_file);
4078 fprintf(stderr,
"xtrabackup: Error: xtrabackup_apply_delta() failed.\n");
4083 xtrabackup_apply_deltas(
bool check_newer)
4086 char dbpath[FN_REFLEN];
4091 ulint err = DB_SUCCESS;
4092 static char current_dir[2];
4094 current_dir[0] = FN_CURLIB;
4096 srv_data_home = current_dir;
4101 if (dbdir != NULL) {
4102 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dbdir,
4105 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4106 goto next_file_item_1;
4109 if (strlen(fileinfo.
name) > 6
4110 && 0 == strcmp(fileinfo.
name +
4111 strlen(fileinfo.
name) - 6,
4113 xtrabackup_apply_delta(
4114 xtrabackup_incremental_dir, NULL,
4115 fileinfo.
name, check_newer);
4118 ret = fil_file_readdir_next_file(&err,
4119 xtrabackup_incremental_dir, dbdir,
4125 fprintf(stderr,
"xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4132 fprintf(stderr,
"xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4135 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dir,
4138 if (dbinfo.
type == OS_FILE_TYPE_FILE
4139 || dbinfo.
type == OS_FILE_TYPE_UNKNOWN) {
4141 goto next_datadir_item;
4144 sprintf(dbpath,
"%s/%s", xtrabackup_incremental_dir,
4150 if (dbdir != NULL) {
4152 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
4156 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4158 goto next_file_item_2;
4161 if (strlen(fileinfo.
name) > 6
4162 && 0 == strcmp(fileinfo.
name +
4163 strlen(fileinfo.
name) - 6,
4167 xtrabackup_apply_delta(
4168 xtrabackup_incremental_dir, dbinfo.
name,
4169 fileinfo.
name, check_newer);
4172 ret = fil_file_readdir_next_file(&err,
4180 ret = fil_file_readdir_next_file(&err,
4181 xtrabackup_incremental_dir,
4190 xtrabackup_close_temp_log(
bool clear_flag)
4193 char src_path[FN_REFLEN];
4194 char dst_path[FN_REFLEN];
4198 byte* log_buf_ = NULL;
4201 if (!xtrabackup_logfile_is_renamed)
4205 innobase_log_group_home_dir = innobase_log_group_home_dir_backup;
4206 innobase_log_file_size = innobase_log_file_size_backup;
4207 innobase_log_files_in_group = innobase_log_files_in_group_backup;
4210 if(!xtrabackup_incremental_dir) {
4211 sprintf(dst_path,
"%s%s", xtrabackup_target_dir,
"/ib_logfile0");
4212 sprintf(src_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
4214 sprintf(dst_path,
"%s%s", xtrabackup_incremental_dir,
"/ib_logfile0");
4215 sprintf(src_path,
"%s%s", xtrabackup_incremental_dir,
"/xtrabackup_logfile");
4221 success = os_file_rename(
4223 dst_path, src_path);
4227 xtrabackup_logfile_is_renamed = FALSE;
4233 src_file = os_file_create_simple_no_error_handling(
4236 OS_FILE_READ_WRITE, &success);
4241 #ifdef USE_POSIX_FADVISE
4242 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
4249 log_buf_ = (
unsigned char*)
ut_malloc(LOG_FILE_HDR_SIZE * 2);
4250 log_buf = (
unsigned char*)
ut_align(log_buf_, LOG_FILE_HDR_SIZE);
4252 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4257 memset(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
' ', 4);
4259 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4264 os_file_close(src_file);
4270 os_file_close(src_file);
4273 fprintf(stderr,
"xtrabackup: Error: xtrabackup_close_temp_log() failed.\n");
4278 xtrabackup_prepare_func(
void)
4282 if (chdir(xtrabackup_real_target_dir) != 0)
4284 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", xtrabackup_real_target_dir);
4287 fprintf(stderr,
"xtrabackup: cd to %s\n", xtrabackup_real_target_dir);
4289 xtrabackup_target_dir= mysql_data_home_buff;
4290 mysql_data_home_buff[0]=FN_CURLIB;
4291 mysql_data_home_buff[1]=0;
4295 char filename[FN_REFLEN];
4297 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4299 if (xtrabackup_read_metadata(filename))
4300 fprintf(stderr,
"xtrabackup: error: xtrabackup_read_metadata()\n");
4302 if (!strcmp(metadata_type,
"full-backuped")) {
4303 fprintf(stderr,
"xtrabackup: This target seems to be not prepared yet.\n");
4304 }
else if (!strcmp(metadata_type,
"full-prepared")) {
4305 fprintf(stderr,
"xtrabackup: This target seems to be already prepared.\n");
4308 fprintf(stderr,
"xtrabackup: This target seems not to have correct metadata...\n");
4311 if (xtrabackup_incremental) {
4313 "xtrabackup: error: applying incremental backup needs target prepared.\n");
4317 if (xtrabackup_incremental
4318 && ut_dulint_cmp(metadata_to_lsn, incremental_lsn) != 0) {
4320 "xtrabackup: error: This incremental backup seems not to be proper for the target.\n"
4321 "xtrabackup: Check 'to_lsn' of the target and 'from_lsn' of the incremental.\n");
4327 srv_max_n_threads = 1000;
4332 srv_page_size_shift = 14;
4333 srv_page_size = (1 << srv_page_size_shift);
4338 if(xtrabackup_init_temp_log())
4341 if(xtrabackup_incremental)
4342 xtrabackup_apply_deltas(TRUE);
4353 if(innodb_init_param())
4356 srv_apply_log_only = (ibool) xtrabackup_apply_log_only;
4359 if(srv_n_file_io_threads < 10) {
4360 srv_n_file_io_threads = 10;
4363 fprintf(stderr,
"xtrabackup: Starting InnoDB instance for recovery.\n"
4364 "xtrabackup: Using %"PRIu64
" bytes for buffer pool (set by --use-memory parameter)\n",
4365 xtrabackup_use_memory);
4409 fil_system_t* f_system = fil_system;
4412 mutex_enter(&(f_system->
mutex));
4415 while (space != NULL) {
4424 mutex_exit(&(f_system->
mutex));
4428 mtr_s_lock(fil_space_get_latch(space->
id, &flags), &mtr);
4432 0, RW_S_LATCH, &mtr);
4434 + buf_block_get_frame(block);
4442 fil_extend_space_to_desired_size(&actual_size, space->
id, size);
4444 mutex_enter(&(f_system->
mutex));
4450 mutex_exit(&(f_system->
mutex));
4455 if (xtrabackup_export) {
4456 printf(
"xtrabackup: export option is specified.\n");
4457 if (innobase_file_per_table) {
4458 fil_system_t* f_system = fil_system;
4462 char info_file_path[FN_REFLEN];
4464 char table_name[FN_REFLEN];
4469 buf = (byte*)
ut_malloc(UNIV_PAGE_SIZE * 2);
4470 page = (byte*)
ut_align(buf, UNIV_PAGE_SIZE);
4473 innobase_fast_shutdown = 0;
4475 mutex_enter(&(f_system->
mutex));
4478 while (space != NULL) {
4482 || trx_sys_sys_space(space->
id)
4493 while (node != NULL) {
4495 char *next, *prev, *p;
4501 strncpy(info_file_path, node->
name, FN_REFLEN);
4502 len = strlen(info_file_path);
4503 info_file_path[len - 3] =
'e';
4504 info_file_path[len - 2] =
'x';
4505 info_file_path[len - 1] =
'p';
4509 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
4514 info_file_path[len - 4] = 0;
4515 strncpy(table_name, prev, FN_REFLEN);
4517 info_file_path[len - 4] =
'.';
4519 mutex_exit(&(f_system->
mutex));
4520 mutex_enter(&(dict_sys->
mutex));
4525 "xtrabackup: error: cannot find dictionary record of table %s\n", table_name);
4528 index = dict_table_get_first_index(table);
4532 "xtrabackup: error: sorry, cannot export over 31 indexes for now.\n");
4537 bzero(page, UNIV_PAGE_SIZE);
4541 strncpy((
char*)page + 12, table_name, 500);
4544 "xtrabackup: export metadata of table '%s' to file `%s` (%lu indexes)\n",
4545 table_name, info_file_path, n_index);
4553 strncpy((
char*)page + n_index * 512 + 12, index->
name, 500);
4556 "xtrabackup: name=%s, id.low=%lu, page=%lu\n",
4558 (ulint)(index->
id & 0xFFFFFFFFUL),
4560 (ulint) index->
page);
4562 index = dict_table_get_next_index(index);
4567 info_file = os_file_create(
4569 info_file_path, OS_FILE_OVERWRITE,
4575 success = os_file_write(info_file_path, info_file, page,
4576 0, 0, UNIV_PAGE_SIZE);
4581 success = os_file_flush(info_file);
4587 if (info_file != -1) {
4588 os_file_close(info_file);
4591 mutex_exit(&(dict_sys->
mutex));
4592 mutex_enter(&(f_system->
mutex));
4599 mutex_exit(&(f_system->
mutex));
4603 printf(
"xtrabackup: export option is for file_per_table only, disabled.\n");
4608 printf(
"\n[notice (again)]\n"
4609 " If you use binary log and don't use any hack of group commit,\n"
4610 " the binary log position seems to be:\n");
4619 fp = fopen(
"xtrabackup_binlog_pos_innodb",
"w");
4621 fprintf(fp,
"%s\t%llu\n",
4628 printf(
"xtrabackup: failed to open 'xtrabackup_binlog_pos_innodb'\n");
4633 if ((xtrabackup_incremental
4634 && ut_dulint_cmp(srv_start_lsn, incremental_last_lsn) < 0)
4635 ||(!xtrabackup_incremental
4636 && ut_dulint_cmp(srv_start_lsn, metadata_last_lsn) < 0)) {
4637 printf(
"xtrabackup: ########################################################\n"
4638 "xtrabackup: # !!WARNING!! #\n"
4639 "xtrabackup: # The transaction log file should be wrong or corrupt. #\n"
4640 "xtrabackup: # The log was not applied to the intended LSN! #\n"
4641 "xtrabackup: ########################################################\n");
4642 if (xtrabackup_incremental) {
4643 printf(
"xtrabackup: The intended lsn is %"PRIu64
"\n",
4644 incremental_last_lsn);
4646 printf(
"xtrabackup: The intended lsn is %"PRIu64
"\n",
4664 if(xtrabackup_close_temp_log(TRUE))
4669 char filename[FN_REFLEN];
4671 strcpy(metadata_type,
"full-prepared");
4673 if(xtrabackup_incremental
4674 && ut_dulint_cmp(metadata_to_lsn, incremental_to_lsn) < 0)
4676 metadata_to_lsn = incremental_to_lsn;
4677 metadata_last_lsn = incremental_last_lsn;
4680 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4681 if (xtrabackup_write_metadata(filename))
4682 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
4684 if(xtrabackup_extra_lsndir) {
4685 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4686 if (xtrabackup_write_metadata(filename))
4687 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4691 if(!xtrabackup_create_ib_logfile)
4696 printf(
"\n[notice]\nWe cannot call InnoDB second time during the process lifetime.\n");
4697 printf(
"Please re-execte to create ib_logfile*. Sorry.\n");
4714 xtrabackup_close_temp_log(FALSE);
4721 int main(
int argc,
char **argv)
4723 po::options_description commandline_options(_(
"Options used only in command line"));
4724 commandline_options.add_options()
4725 (
"target-dir", po::value<std::string>(), _(
"destination directory"))
4726 (
"backup", po::value<bool>(&xtrabackup_backup)->default_value(
false)->zero_tokens(), _(
"take backup to target-dir"))
4727 (
"stats", po::value<bool>(&xtrabackup_stats)->default_value(
false)->zero_tokens(), _(
"calc statistic of datadir (offline mysqld is recommended)"))
4728 (
"prepare", po::value<bool>(&xtrabackup_prepare)->default_value(
false)->zero_tokens(), _(
"prepare a backup for starting mysql server on the backup."))
4729 (
"export", po::value<bool>(&xtrabackup_export)->default_value(
false)->zero_tokens(), _(
"create files to import to another database when prepare."))
4730 (
"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."))
4731 (
"print-param", po::value<bool>(&xtrabackup_print_param)->default_value(
false)->zero_tokens(), _(
"print parameter of mysqld needed for copyback."))
4732 (
"use-memory", po::value<uint64_t>(&xtrabackup_use_memory)->default_value(100*1024*1024), _(
"The value is used instead of buffer_pool_size"))
4733 (
"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'"))
4734 (
"throttle", po::value<long>(&xtrabackup_throttle), _(
"limit count of IO operations (pairs of read&write) per second to IOS values (for '--backup')"))
4735 (
"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')."))
4736 (
"extra-lsndir", po::value<std::string>(), _(
"(for --backup): save an extra copy of the xtrabackup_checkpoints file in this directory."))
4737 (
"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!"))
4738 (
"incremental-basedir", po::value<std::string>(), _(
"(for --backup): copy only .ibd pages newer than backup at specified directory."))
4739 (
"incremental-dir", po::value<std::string>(), _(
"(for --prepare): apply .delta files and logfile in the specified directory."))
4740 (
"tables", po::value<std::string>(), _(
"filtering by regexp for table names."))
4741 (
"tables-file", po::value<std::string>(), _(
"filtering by list of the exact database.table name in the file."))
4742 (
"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. ###"))
4743 (
"datadir,h", po::value<std::string>(), _(
"Path to the database root."))
4744 (
"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."))
4745 (
"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."))
4746 (
"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."))
4747 (
"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."))
4748 (
"innodb-autoextend-increment", po::value<uint32_t>(&srv_auto_extend_increment)->default_value(8), _(
"Data file autoextend increment in megabytes"))
4749 (
"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."))
4750 (
"innodb-checksums", po::value<bool>(&innobase_use_checksums)->default_value(
true), _(
"Enable InnoDB checksums validation (enabled by default). Disable with --skip-innodb-checksums."))
4751 (
"innodb-data-file-path", po::value<std::string>(), _(
"Path to individual files and their sizes."))
4752 (
"innodb-data-home-dir", po::value<std::string>(), _(
"The common part for InnoDB table spaces."))
4753 (
"innodb-doublewrite", po::value<bool>(&innobase_use_doublewrite)->default_value(
true), _(
"Enable InnoDB doublewrite buffer (enabled by default). Disable with --skip-innodb-doublewrite."))
4754 (
"innodb-file-io-threads", po::value<long>(&innobase_file_io_threads)->default_value(4), _(
"Number of file I/O threads in InnoDB."))
4755 (
"innodb-file-per-table", po::value<bool>(&innobase_file_per_table), _(
"Stores each InnoDB table to an .ibd file in the database dir."))
4756 (
"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)."))
4757 (
"innodb-flush-method", po::value<std::string>(), _(
"With which method to flush data."))
4759 (
"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."))
4760 (
"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."))
4761 (
"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."))
4762 (
"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."))
4763 (
"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."))
4764 (
"innodb-log-group-home-dir", po::value<std::string>(), _(
"Path to InnoDB log files."))
4765 (
"innodb-max_dirty-pages-pct", po::value<ulong>(&srv_max_buf_pool_modified_pct)->default_value(90), _(
"Percentage of dirty pages allowed in bufferpool."))
4766 (
"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."))
4768 (
"innodb-page-size", po::value<uint32_t>(&innobase_page_size)->default_value(1 << 14), _(
"The universal page size of the database."))
4769 (
"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!"))
4770 (
"innodb-fast-checksum", po::value<bool>(&innobase_fast_checksum), _(
"Change the algorithm of checksum for the whole of datapage to 4-bytes word based."))
4771 (
"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."))
4772 (
"innodb-doublewrite-file", po::value<char *>(&innobase_doublewrite_file), _(
"Path to special datafile for doublewrite buffer. (default is "": not used)"))
4776 po::variables_map vm;
4778 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
4779 po::store(po::command_line_parser(argc, argv).options(commandline_options).style(style).run(), vm);
4782 if (vm.count(
"target-dir"))
4783 xtrabackup_target_dir= vm[
"target-dir"].as<std::string>().c_str();
4785 if (vm.count(
"extra-lsndir"))
4786 xtrabackup_extra_lsndir= vm[
"extra-lsndir"].as<std::string>().c_str();
4788 if (vm.count(
"incremental-lsn"))
4789 xtrabackup_incremental= vm[
"incremental-lsn"].as<std::string>().c_str();
4791 if (vm.count(
"incremental-basedir"))
4792 xtrabackup_incremental_basedir= vm[
"incremental-basedir"].as<std::string>().c_str();
4794 boost::scoped_ptr<char> xtrabackup_tables_autoptr(
new char[(vm.count(
"tables")) ? vm[
"tables"].as<std::string>().length() + 1: 0]);
4795 if (vm.count(
"tables"))
4797 xtrabackup_tables= xtrabackup_tables_autoptr.get();
4798 strcpy(xtrabackup_tables, vm[
"tables"].as<std::string>().c_str());
4801 if (vm.count(
"tables-file"))
4802 xtrabackup_tables_file= vm[
"tables-file"].as<std::string>().c_str();
4804 if (vm.count(
"tmpdir"))
4805 opt_mysql_tmpdir= vm[
"tmpdir"].as<std::string>().c_str();
4807 if (vm.count(
"innodb-data-file-path"))
4808 innobase_data_file_path= vm[
"innodb-data-file-path"].as<std::string>().c_str();
4810 boost::scoped_ptr<char> xtrabackup_incremental_dir_autoptr(
new char[(vm.count(
"incremental-dir")) ? vm[
"incremental-dir"].as<std::string>().length() + 1: 0]);
4811 if (vm.count(
"incremental-dir"))
4813 xtrabackup_incremental_dir= xtrabackup_incremental_dir_autoptr.get();
4814 strcpy(xtrabackup_incremental_dir, vm[
"incremental-dir"].as<std::string>().c_str());
4817 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]);
4818 if (vm.count(
"innodb-data-home-dir"))
4820 innobase_data_home_dir= innobase_data_home_dir_autoptr.get();
4821 strcpy(innobase_data_home_dir, vm[
"innodb-data-home-dir"].as<std::string>().c_str());
4824 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]);
4825 if (vm.count(
"innodb-flush-method"))
4827 innobase_unix_file_flush_method= innobase_flush_method_autoptr.get();
4828 strcpy(innobase_unix_file_flush_method, vm[
"innodb-flush-method"].as<std::string>().c_str());
4831 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]);
4833 if (vm.count(
"innodb-log-group-home-dir"))
4835 innobase_log_group_home_dir= innobase_log_group_home_dir_autoptr.get();
4836 strcpy(innobase_log_group_home_dir, vm[
"innodb-log-group-home-dir"].as<std::string>().c_str());
4839 xtrabackup_use_memory-= xtrabackup_use_memory % (1024*1024);
4840 if (xtrabackup_use_memory < (1024*1024)) {
4841 fprintf(stderr,
"xtrabackup: use-memory out of range\n");
4846 fprintf(stderr,
"xtrabackup: parallel needs to be greater than 0\n");
4850 innobase_additional_mem_pool_size-= innobase_additional_mem_pool_size % 1024;
4851 if (innobase_additional_mem_pool_size < (512*1024)) {
4852 fprintf(stderr,
"xtrabackup: innodb-additional-mem-pool-size out of range\n");
4856 if ((srv_auto_extend_increment < 1) || (srv_auto_extend_increment > 8)) {
4857 fprintf(stderr,
"xtrabackup: innodb-auto-extend-increment out of range\n");
4861 innobase_buffer_pool_size-= innobase_buffer_pool_size % (1024*1024);
4862 if (innobase_buffer_pool_size < (1024*1024)) {
4863 fprintf(stderr,
"xtrabackup: innodb-buffer-pool-size out of range\n");
4867 if ((innobase_file_io_threads < 4) || (innobase_file_io_threads > 64)) {
4868 fprintf(stderr,
"xtrabackup: innodb-file-io-threads out of range\n");
4872 if (srv_flush_log_at_trx_commit > 2) {
4873 fprintf(stderr,
"xtrabackup: innodb-flush-log-at-trx-commit out of range\n");
4877 if (innobase_force_recovery > 6) {
4878 fprintf(stderr,
"xtrabackup: innodb-force-recovery out of range\n");
4882 if ((innobase_lock_wait_timeout < 1) || (innobase_lock_wait_timeout > (1024*1024*1024))) {
4883 fprintf(stderr,
"xtrabackup: innodb-lock-wait-timeout out of range\n");
4887 innobase_log_buffer_size-= innobase_log_buffer_size % 1024;
4888 if (innobase_additional_mem_pool_size < (256*1024)) {
4889 fprintf(stderr,
"xtrabackup: innodb-log-buffer-size out of range\n");
4893 if (innobase_additional_mem_pool_size < (1024*1024)) {
4894 fprintf(stderr,
"xtrabackup: innodb-log-file-size out of range\n");
4898 if ((innobase_log_files_in_group < 2) || (innobase_log_files_in_group > (100))) {
4899 fprintf(stderr,
"xtrabackup: innodb-log-files-in-group out of range\n");
4903 if (srv_max_buf_pool_modified_pct > 100) {
4904 fprintf(stderr,
"xtrabackup: innodb-max-buf-pool-modified-pct out of range\n");
4908 if (innobase_open_files < 10) {
4909 fprintf(stderr,
"xtrabackup: innodb-open-files out of range\n");
4913 if ((innobase_page_size < (1 << 12)) || (innobase_page_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4914 fprintf(stderr,
"xtrabackup: innodb-page-size out of range\n");
4918 if ((innobase_log_block_size < (512)) || (innobase_log_block_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4919 fprintf(stderr,
"xtrabackup: innodb-log-block-size out of range\n");
4923 if (vm.count(
"datadir"))
4925 mysql_data_home_arg.assign(vm[
"datadir"].as<std::string>());
4929 mysql_data_home_arg.assign(LOCALSTATEDIR);
4932 mysql_data_home= (
char*)malloc(mysql_data_home_arg.length());
4933 strcpy(mysql_data_home, mysql_data_home_arg.c_str());
4935 if ((!xtrabackup_prepare) && (strcmp(mysql_data_home,
"./") == 0)) {
4936 if (!xtrabackup_print_param)
4938 printf(
"\nxtrabackup: Error: Please set parameter 'datadir'\n");
4942 if (xtrabackup_tables) {
4948 tables_regex_num = 1;
4950 p = xtrabackup_tables;
4951 while ((p = strchr(p,
',')) != NULL) {
4956 tables_regex = (regex_t*)
ut_malloc(
sizeof(regex_t) * tables_regex_num);
4958 p = xtrabackup_tables;
4959 for (i=0; i < tables_regex_num; i++) {
4960 next = strchr(p,
',');
4961 ut_a(next || i == tables_regex_num - 1);
4964 if (i != tables_regex_num - 1)
4967 regerror(regcomp(&tables_regex[i],p,REG_EXTENDED),
4968 &tables_regex[i],errbuf,
sizeof(errbuf));
4969 fprintf(stderr,
"xtrabackup: tables regcomp(%s): %s\n",p,errbuf);
4971 if (i != tables_regex_num - 1)
4977 if (xtrabackup_tables_file) {
4978 char name_buf[NAME_LEN*2+2];
4981 if (xtrabackup_stream) {
4982 fprintf(stderr,
"xtrabackup: Warning: --tables_file option doesn't affect with --stream.\n");
4983 xtrabackup_tables_file = NULL;
4984 goto skip_tables_file_register;
4987 name_buf[NAME_LEN*2+1] =
'\0';
4990 tables_hash = hash_create(1000);
4993 fp = fopen(xtrabackup_tables_file,
"r");
4995 fprintf(stderr,
"xtrabackup: cannot open %s\n", xtrabackup_tables_file);
5002 if ( fgets(name_buf, NAME_LEN*2+1, fp) == 0 ) {
5006 while (*p !=
'\0') {
5012 p = strchr(name_buf,
'\n');
5021 strcpy(table->name, name_buf);
5026 printf(
"xtrabackup: table '%s' is registered to the list.\n", table->name);
5029 skip_tables_file_register:
5033 srv_page_size_shift = UNIV_PAGE_SIZE_SHIFT_MAX;
5034 srv_page_size = UNIV_PAGE_SIZE_MAX;
5035 srv_log_block_size = 512;
5037 if (xtrabackup_backup && xtrabackup_incremental) {
5044 incremental_lsn = strtoll(xtrabackup_incremental, &endchar, 10);
5045 if (*endchar !=
'\0')
5049 fprintf(stderr,
"xtrabackup: value '%s' may be wrong format for incremental option.\n",
5050 xtrabackup_incremental);
5055 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5056 UNIV_PAGE_SIZE_MAX);
5057 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5058 UNIV_PAGE_SIZE_MAX);
5059 }
else if (xtrabackup_backup && xtrabackup_incremental_basedir) {
5060 char filename[FN_REFLEN];
5062 sprintf(filename,
"%s/%s", xtrabackup_incremental_basedir, XTRABACKUP_METADATA_FILENAME);
5064 if (xtrabackup_read_metadata(filename)) {
5066 "xtrabackup: error: failed to read metadata from %s\n",
5071 incremental_lsn = metadata_to_lsn;
5072 xtrabackup_incremental = xtrabackup_incremental_basedir;
5075 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5076 UNIV_PAGE_SIZE_MAX);
5077 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5078 UNIV_PAGE_SIZE_MAX);
5079 }
else if (xtrabackup_prepare && xtrabackup_incremental_dir) {
5080 char filename[FN_REFLEN];
5082 sprintf(filename,
"%s/%s", xtrabackup_incremental_dir, XTRABACKUP_METADATA_FILENAME);
5084 if (xtrabackup_read_metadata(filename)) {
5086 "xtrabackup: error: failed to read metadata from %s\n",
5091 incremental_lsn = metadata_from_lsn;
5092 incremental_to_lsn = metadata_to_lsn;
5093 incremental_last_lsn = metadata_last_lsn;
5094 xtrabackup_incremental = xtrabackup_incremental_dir;
5097 incremental_buffer_base = (byte*) malloc((UNIV_PAGE_SIZE / 4 + 1) *
5099 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5103 incremental_buffer_base = (byte*) malloc((1 + 1) * UNIV_PAGE_SIZE_MAX);
5104 incremental_buffer = (byte*)
ut_align(incremental_buffer_base,
5105 UNIV_PAGE_SIZE_MAX);
5107 xtrabackup_incremental = NULL;
5111 if (xtrabackup_print_param) {
5112 printf(
"# This MySQL options file was generated by XtraBackup.\n");
5113 printf(
"[mysqld]\n");
5114 printf(
"datadir = \"%s\"\n", mysql_data_home);
5115 printf(
"tmpdir = \"%s\"\n", opt_mysql_tmpdir);
5116 printf(
"innodb_data_home_dir = \"%s\"\n",
5117 innobase_data_home_dir ? innobase_data_home_dir : mysql_data_home);
5118 printf(
"innodb_data_file_path = \"%s\"\n",
5119 innobase_data_file_path ? innobase_data_file_path :
"ibdata1:10M:autoextend");
5120 printf(
"innodb_log_group_home_dir = \"%s\"\n",
5121 innobase_log_group_home_dir ? innobase_log_group_home_dir : mysql_data_home);
5122 printf(
"innodb_log_files_in_group = %ld\n", innobase_log_files_in_group);
5123 printf(
"innodb_log_file_size = %"PRIu64
"\n", (uint64_t)innobase_log_file_size);
5124 printf(
"innodb_flush_method = \"%s\"\n",
5125 (innobase_unix_file_flush_method != NULL) ?
5126 innobase_unix_file_flush_method :
"");
5130 if (!xtrabackup_stream) {
5132 if (xtrabackup_incremental) {
5133 printf(
"incremental backup from %"PRIu64
" is enabled.\n",
5137 if (xtrabackup_backup) {
5138 xtrabackup_suspend_at_end = TRUE;
5139 fprintf(stderr,
"xtrabackup: suspend-at-end is enabled.\n");
5147 if (xtrabackup_backup) num++;
5148 if (xtrabackup_stats) num++;
5149 if (xtrabackup_prepare) num++;
5157 if (xtrabackup_backup)
5158 xtrabackup_backup_func();
5161 if (xtrabackup_stats)
5162 xtrabackup_stats_func();
5165 if (xtrabackup_prepare)
5166 xtrabackup_prepare_func();
5168 free(incremental_buffer_base);
5170 if (xtrabackup_tables) {
5174 for (i = 0; i < tables_regex_num; i++) {
5175 regfree(&tables_regex[i]);
5180 if (xtrabackup_tables_file) {
5203 hash_table_free(tables_hash);