22#ifndef XTRABACKUP_VERSION
23#define XTRABACKUP_VERSION "undefined"
25#ifndef XTRABACKUP_REVISION
26#define XTRABACKUP_REVISION "undefined"
32#include <drizzled/internal/my_sys.h>
33#include <drizzled/charset.h>
34#include <drizzled/gettext.h>
35#include <drizzled/constrained_value.h>
36#include <drizzled/configmake.h>
37#include <drizzled/error/priority_t.h>
41#include <boost/program_options.hpp>
42#include <boost/scoped_array.hpp>
43#include <boost/scoped_ptr.hpp>
47#define my_progname "xtrabackup"
49#define MYSQL_VERSION_ID 50507
76#ifdef INNODB_VERSION_SHORT
82#define IB_INT64 ib_int64_t
83#define LSN64 ib_uint64_t
84#define MACH_READ_64 mach_read_from_8
85#define MACH_WRITE_64 mach_write_to_8
86#define OS_MUTEX_CREATE() os_mutex_create()
87#define ut_dulint_zero 0
88#define ut_dulint_cmp(A, B) (A > B ? 1 : (A == B ? 0 : -1))
89#define ut_dulint_add(A, B) (A + B)
90#define ut_dulint_minus(A, B) (A - B)
91#define ut_dulint_align_down(A, B) (A & ~((ib_int64_t)B - 1))
92#define ut_dulint_align_up(A, B) ((A + B - 1) & ~((ib_int64_t)B - 1))
95#define SRV_PATH_SEPARATOR '\\'
96#define SRV_PATH_SEPARATOR_STR "\\"
98#define SRV_PATH_SEPARATOR '/'
99#define SRV_PATH_SEPARATOR_STR "/"
102#ifndef UNIV_PAGE_SIZE_MAX
103#define UNIV_PAGE_SIZE_MAX UNIV_PAGE_SIZE
105#ifndef UNIV_PAGE_SIZE_SHIFT_MAX
106#define UNIV_PAGE_SIZE_SHIFT_MAX UNIV_PAGE_SIZE_SHIFT
110namespace po=boost::program_options;
112static void xb_copy_padded(
char* to,
size_t to_size,
const char* from)
114 size_t copy_size = std::min(strlen(from), to_size);
116 memset(to, 0, to_size);
117 memcpy(to, from, copy_size);
121 bool errmsg_printf (error::priority_t,
char const *format, ...);
123 bool errmsg_printf (error::priority_t,
char const *format, ...)
127 va_start(args, format);
128 rv= vfprintf(stderr, format, args);
130 fprintf(stderr,
"\n");
136#include "xtrabackup_api.h"
141 #ifdef POSIX_FADV_NORMAL
142 #define USE_POSIX_FADVISE
234 #ifndef UNIV_HOTBACKUP
254 #ifndef UNIV_HOTBACKUP
309 extern fil_system_t* fil_system;
314 bool innodb_inited= 0;
317 char xtrabackup_real_target_dir[FN_REFLEN] =
"./xtrabackup_backupfiles/";
318 const char *xtrabackup_target_dir= xtrabackup_real_target_dir;
319 bool xtrabackup_backup =
false;
320 bool xtrabackup_stats =
false;
321 bool xtrabackup_prepare =
false;
322 bool xtrabackup_print_param =
false;
324 bool xtrabackup_export =
false;
325 bool xtrabackup_apply_log_only =
false;
327 bool xtrabackup_suspend_at_end =
false;
328 uint64_t xtrabackup_use_memory = 100*1024*1024L;
329 bool xtrabackup_create_ib_logfile =
false;
331 long xtrabackup_throttle = 0;
335 bool xtrabackup_stream =
false;
336const char *xtrabackup_incremental = NULL;
337 LSN64 incremental_lsn;
338 LSN64 incremental_to_lsn;
339 LSN64 incremental_last_lsn;
340 byte* incremental_buffer = NULL;
341 byte* incremental_buffer_base = NULL;
343const char *xtrabackup_incremental_basedir = NULL;
344const char *xtrabackup_extra_lsndir = NULL;
345char *xtrabackup_incremental_dir = NULL;
347 char *xtrabackup_tables = NULL;
348 int tables_regex_num;
349 regex_t *tables_regex;
350 regmatch_t tables_regmatch[1];
352const char *xtrabackup_tables_file = NULL;
353 hash_table_t* tables_hash;
357 hash_node_t name_hash;
362 static ulint thread_nr[SRV_MAX_N_IO_THREADS + 6 + 64];
365 static ulint thread_nr[SRV_MAX_N_IO_THREADS + 6];
369 LSN64 checkpoint_lsn_start;
370 LSN64 checkpoint_no_start;
371 LSN64 log_copy_scanned_lsn;
372 IB_INT64 log_copy_offset = 0;
373 ibool log_copying = TRUE;
374 ibool log_copying_running = FALSE;
375 ibool log_copying_succeed = FALSE;
377 ibool xtrabackup_logfile_is_renamed = FALSE;
382 #define XTRABACKUP_METADATA_FILENAME "xtrabackup_checkpoints"
383 char metadata_type[30] =
"";
385 ib_uint64_t metadata_from_lsn = 0;
386 ib_uint64_t metadata_to_lsn = 0;
387 ib_uint64_t metadata_last_lsn = 0;
389 #define XB_DELTA_INFO_SUFFIX ".meta"
393 char dst_log_path[FN_REFLEN];
396 char mysql_real_data_home[FN_REFLEN] =
"./";
397 char *mysql_data_home= mysql_real_data_home;
398std::string mysql_data_home_arg;
399 static char mysql_data_home_buff[2];
401const char *opt_mysql_tmpdir = NULL;
405#define HA_INNOBASE_ROWS_IN_TABLE 10000
406#define HA_INNOBASE_RANGE_COUNT 100
408ulong innobase_large_page_size = 0;
413long innobase_additional_mem_pool_size = 1*1024*1024L;
414long innobase_buffer_pool_awe_mem_mb = 0;
415long innobase_file_io_threads = 4;
416long innobase_read_io_threads = 4;
417long innobase_write_io_threads = 4;
418long innobase_force_recovery = 0;
419long innobase_lock_wait_timeout = 50;
420long innobase_log_buffer_size = 1024*1024L;
421long innobase_log_files_in_group = 2;
422long innobase_log_files_in_group_backup;
423long innobase_mirrored_log_groups = 1;
424long innobase_open_files = 300L;
426long innobase_page_size = (1 << 14);
427static ulong innobase_log_block_size = 512;
428bool innobase_fast_checksum =
false;
429bool innobase_extra_undoslots =
false;
430char* innobase_doublewrite_file = NULL;
432uint64_t innobase_buffer_pool_size = 8*1024*1024L;
435static log_file_constraint innobase_log_file_size;
437uint64_t innobase_log_file_size_backup;
442char* innobase_data_home_dir = NULL;
443const char* innobase_data_file_path = NULL;
444char* innobase_log_group_home_dir = NULL;
445char* innobase_log_group_home_dir_backup = NULL;
446char* innobase_log_arch_dir = NULL;
449char* innobase_unix_file_flush_method = NULL;
454ulong innobase_fast_shutdown = 1;
455bool innobase_log_archive = FALSE;
456bool innobase_use_doublewrite = TRUE;
457bool innobase_use_checksums = TRUE;
458bool innobase_use_large_pages = FALSE;
459bool innobase_file_per_table = FALSE;
460bool innobase_locks_unsafe_for_binlog = FALSE;
461bool innobase_rollback_on_timeout = FALSE;
462bool innobase_create_status_file = FALSE;
463bool innobase_adaptive_hash_index = TRUE;
465static char *internal_innobase_data_file_path = NULL;
472#define INNOBASE_WAKE_INTERVAL 32
473ulong innobase_active_counter = 0;
481 return static_cast<const CHARSET_INFO*
>(cs)->isspace(char_to_test);
490 const char* path_name)
492 const char* name = path_name + drizzled::internal::dirname_length(path_name);
494 return((name) ? name :
"null");
502 const dict_index_t* ,
511 const dict_index_t* ,
515 fprintf(stderr,
"ERROR: innobase_rec_to_mysql called\n");
529 fprintf(stderr,
"ERROR: innobase_rec_reset called\n");
547 fil_system_t *system;
556datafiles_iter_new(fil_system_t *f_system)
561 it->mutex = OS_MUTEX_CREATE();
563 it->system = f_system;
577 *space_changed = FALSE;
579 if (it->node == NULL) {
585 if (it->node != NULL)
589 it->space = (it->space == NULL) ?
593 while (it->space != NULL &&
597 if (it->space == NULL)
599 *space_changed = TRUE;
627static void print_version(
void)
629 printf(
"%s Ver %s Rev %s for %s %s (%s)\n" ,my_progname,
630 XTRABACKUP_VERSION, XTRABACKUP_REVISION,
"Drizzle",
631 TARGET_OS, TARGET_CPU);
634static void usage(
void)
636 puts(
"Open source backup tool for InnoDB and XtraDB\n\
638Copyright (C) 2009 Percona Inc.\n\
640This program is free software; you can redistribute it and/or\n\
641modify it under the terms of the GNU General Public License\n\
642as published by the Free Software Foundation version 2\n\
645This program is distributed in the hope that it will be useful,\n\
646but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
647MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
648GNU General Public License for more details.\n\
650You can download full text of the license on http://www.gnu.org/licenses/gpl-2.0.txt\n");
652 printf(
"Usage: [%s [--defaults-file=#] --backup | %s [--defaults-file=#] --prepare] [OPTIONS]\n",my_progname,my_progname);
664 fprintf(stderr,
"xtrabackup: thd_is_replication_slave_thread() is called\n");
674 fprintf(stderr,
"xtrabackup: thd_has_edited_nontrans_tables() is called\n");
684 fprintf(stderr,
"xtrabackup: thd_is_select() is called\n");
695 fprintf(stderr,
"xtrabackup: innobase_mysql_print_thd() is called\n");
709 cs = all_charsets[cset];
711 *mbminlen = cs->mbminlen;
712 *mbmaxlen = cs->mbmaxlen;
715 *mbminlen = *mbmaxlen = 0;
728 fprintf(stderr,
"xtrabackup: innobase_convert_from_table_id() is called\n");
740 fprintf(stderr,
"xtrabackup: innobase_convert_from_id() is called\n");
748 return my_charset_utf8_general_ci.strcasecmp(a, b);
755 my_charset_utf8_general_ci.casedn_str(a);
765 fprintf(stderr,
"xtrabackup: innobase_get_stmt() is called\n");
772 char filename[FN_REFLEN];
774 int fd = internal::create_temp_file(filename, opt_mysql_tmpdir,
777 O_BINARY | O_TRUNC | O_SEQUENTIAL |
778 O_TEMPORARY | O_SHORT_LIVED |
780 O_CREAT | O_EXCL | O_RDWR);
798 fprintf(stderr,
"xtrabackup: Got error %d on dup\n",fd2);
837 if (UNIV_UNLIKELY(idlen > buflen)) {
840 memcpy(buf, s, idlen);
852 for (; idlen; idlen--) {
854 if (UNIV_UNLIKELY(c == q)) {
855 if (UNIV_UNLIKELY(buflen < 3)) {
863 if (UNIV_UNLIKELY(buflen < 2)) {
893 const char* bufend = buf + buflen;
896 const char* slash = (
const char*) memchr(
id,
'/', idlen);
905 if (UNIV_LIKELY(s < bufend)) {
914 const char temp_index_suffix[]=
"--temporary--";
918 if (s - buf + (
sizeof temp_index_suffix - 1) < buflen) {
919 memcpy(s, temp_index_suffix,
920 sizeof temp_index_suffix - 1);
921 s +=
sizeof temp_index_suffix - 1;
946 const unsigned char* a,
947 unsigned int a_length,
949 const unsigned char* b,
950 unsigned int b_length);
959 const unsigned char* a,
960 unsigned int a_length,
961 const unsigned char* b,
962 unsigned int b_length)
964 const CHARSET_INFO* charset;
965 enum_field_types mysql_tp;
968 assert(a_length != UNIV_SQL_NULL);
969 assert(b_length != UNIV_SQL_NULL);
971 mysql_tp = (enum_field_types) mysql_type;
975 case DRIZZLE_TYPE_BLOB:
976 case DRIZZLE_TYPE_VARCHAR:
982 if (charset_number == default_charset_info->number) {
983 charset = default_charset_info;
985 charset = get_charset(charset_number);
987 if (charset == NULL) {
988 fprintf(stderr,
"xtrabackup needs charset %lu for doing "
989 "a comparison, but MySQL cannot "
990 "find that charset.",
991 (ulong) charset_number);
1001 ret = charset->coll->strnncollsp(charset,
1006 }
else if (ret > 0) {
1027 const CHARSET_INFO* charset;
1029 charset = get_charset((uint) charset_id);
1032 ut_ad(charset->mbmaxlen);
1036 n_chars = prefix_len / charset->mbmaxlen;
1043 if (charset->mbmaxlen > 1) {
1062 char_length = my_charpos(charset, str,
1063 str + data_len, (
int) n_chars);
1064 if (char_length > data_len) {
1065 char_length = data_len;
1068 if (data_len < prefix_len) {
1069 char_length = data_len;
1071 char_length = prefix_len;
1075 return(char_length);
1090 fprintf(stderr,
"xtrabackup: innobase_raw_format() is called\n");
1101 return(innobase_lock_wait_timeout);
1130innobase_get_slow_log()
1141get_bit_shift(ulint value)
1148 for (shift = 0; !(value & 1UL); shift++) {
1151 return (value >> 1) ? 0 : shift;
1155innodb_init_param(
void)
1158 static char current_dir[3];
1163 get_charset_name(0);
1167 srv_page_size_shift = 0;
1169 if (innobase_page_size != (1 << 14)) {
1170 int n_shift = get_bit_shift(innobase_page_size);
1172 if (n_shift >= 12 && n_shift <= UNIV_PAGE_SIZE_SHIFT_MAX) {
1174 "InnoDB: Warning: innodb_page_size has been "
1175 "changed from default value 16384.\n");
1176 srv_page_size_shift = n_shift;
1177 srv_page_size = 1 << n_shift;
1179 "InnoDB: The universal page size of the "
1180 "database is set to %lu.\n", srv_page_size);
1182 fprintf(stderr,
"InnoDB: Error: invalid value of "
1183 "innobase_page_size: %lu", innobase_page_size);
1187 srv_page_size_shift = 14;
1188 srv_page_size = (1 << srv_page_size_shift);
1191 srv_log_block_size = 0;
1192 if (innobase_log_block_size != 512) {
1193 uint n_shift = get_bit_shift(innobase_log_block_size);;
1196 "InnoDB: Warning: innodb_log_block_size has "
1197 "been changed from its default value. "
1198 "(###EXPERIMENTAL### operation)\n");
1200 srv_log_block_size = (1 << n_shift);
1202 "InnoDB: The log block size is set to %lu.\n",
1203 srv_log_block_size);
1206 srv_log_block_size = 512;
1209 if (!srv_log_block_size) {
1211 "InnoDB: Error: %lu is not valid value for "
1212 "innodb_log_block_size.\n", innobase_log_block_size);
1216 srv_fast_checksum = (ibool) innobase_fast_checksum;
1220 if (
sizeof(ulint) == 4) {
1221 if (xtrabackup_use_memory > UINT32_MAX) {
1223 "xtrabackup: use-memory can't be over 4GB"
1224 " on 32-bit systems\n");
1227 if (innobase_buffer_pool_size > UINT32_MAX) {
1229 "xtrabackup: innobase_buffer_pool_size can't be over 4GB"
1230 " on 32-bit systems\n");
1235 if (innobase_log_file_size > UINT32_MAX) {
1237 "xtrabackup: innobase_log_file_size can't be over 4GB"
1238 " on 32-bit systemsi\n");
1253 current_dir[0] = FN_CURLIB;
1254 current_dir[1] = FN_LIBCHAR;
1256 default_path = current_dir;
1263 if (xtrabackup_backup || xtrabackup_stats) {
1264 fprintf(stderr,
"xtrabackup: Target instance is assumed as followings.\n");
1266 fprintf(stderr,
"xtrabackup: Temporary instance for recovery is set as followings.\n");
1273 srv_data_home = ((xtrabackup_backup || xtrabackup_stats) && innobase_data_home_dir
1274 ? innobase_data_home_dir : default_path);
1275 fprintf(stderr,
"xtrabackup: innodb_data_home_dir = %s\n", srv_data_home);
1281 if (!innobase_data_file_path) {
1282 innobase_data_file_path = (
char*)
"ibdata1:10M:autoextend";
1284 fprintf(stderr,
"xtrabackup: innodb_data_file_path = %s\n",
1285 innobase_data_file_path);
1290 internal_innobase_data_file_path = strdup(innobase_data_file_path);
1293 internal_innobase_data_file_path);
1296 "xtrabackup: syntax error in innodb_data_file_path\n");
1298 free(internal_innobase_data_file_path);
1302 if (xtrabackup_prepare) {
1306 for (i=0; i < srv_n_data_files; i++) {
1309 p = srv_data_file_names[i];
1310 while ((p = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1313 srv_data_file_names[i] = p;
1319 srv_doublewrite_file = innobase_doublewrite_file;
1321 srv_extra_undoslots = (ibool) innobase_extra_undoslots;
1329 if (!((xtrabackup_backup || xtrabackup_stats) && innobase_log_group_home_dir)) {
1330 innobase_log_group_home_dir = default_path;
1332 if (xtrabackup_prepare && xtrabackup_incremental_dir) {
1333 innobase_log_group_home_dir = xtrabackup_incremental_dir;
1335 fprintf(stderr,
"xtrabackup: innodb_log_group_home_dir = %s\n",
1336 innobase_log_group_home_dir);
1338#ifdef UNIV_LOG_ARCHIVE
1343 innobase_log_arch_dir = innobase_log_group_home_dir;
1345 srv_arch_dir = innobase_log_arch_dir;
1351 if (ret == FALSE || innobase_mirrored_log_groups != 1) {
1352 fprintf(stderr,
"xtrabackup: syntax error in innodb_log_group_home_dir, or a "
1353 "wrong number of mirrored log groups\n");
1355 goto mem_free_and_error;
1358 srv_adaptive_flushing = FALSE;
1359 srv_use_sys_malloc = TRUE;
1365 srv_file_flush_method_str = innobase_unix_file_flush_method;
1367 srv_n_log_groups = (ulint) innobase_mirrored_log_groups;
1368 srv_n_log_files = (ulint) innobase_log_files_in_group;
1369 srv_log_file_size = (ulint) innobase_log_file_size;
1370 fprintf(stderr,
"xtrabackup: innodb_log_files_in_group = %ld\n",
1372 fprintf(stderr,
"xtrabackup: innodb_log_file_size = %ld\n",
1375#ifdef UNIV_LOG_ARCHIVE
1376 srv_log_archive_on = (ulint) innobase_log_archive;
1378 srv_log_buffer_size = (ulint) innobase_log_buffer_size;
1386 srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size;
1388 srv_n_file_io_threads = (ulint) innobase_file_io_threads;
1390 srv_n_read_io_threads = (ulint) innobase_read_io_threads;
1391 srv_n_write_io_threads = (ulint) innobase_write_io_threads;
1393 srv_force_recovery = (ulint) innobase_force_recovery;
1395 srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
1396 srv_use_checksums = (ibool) innobase_use_checksums;
1398 btr_search_enabled = innobase_adaptive_hash_index ? true :
false;
1400 os_use_large_pages = (ibool) innobase_use_large_pages;
1401 os_large_page_size = (ulint) innobase_large_page_size;
1409 srv_max_n_open_files = (ulint) innobase_open_files;
1410 srv_innodb_status = (ibool) innobase_create_status_file;
1412 srv_print_verbose_log = 1;
1418 data_mysql_default_charset_coll = (ulint)default_charset_info->number;
1420 ut_a(DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number);
1437 switch (os_get_os_version()) {
1446 srv_use_native_aio = FALSE;
1452 srv_use_native_aio = TRUE;
1457 srv_use_native_aio = TRUE;
1458 srv_use_native_conditions = TRUE;
1462#elif defined(LINUX_NATIVE_AIO)
1464 if (srv_use_native_aio) {
1467 " InnoDB: Using Linux native AIO\n");
1473 srv_use_native_aio = FALSE;
1480 fprintf(stderr,
"xtrabackup: innodb_init_param(): Error occured.\n");
1491 if (err != DB_SUCCESS) {
1492 free(internal_innobase_data_file_path);
1510 fprintf(stderr,
"xtrabackup: innodb_init(): Error occured.\n");
1517 srv_fast_shutdown = (ulint) innobase_fast_shutdown;
1520 fprintf(stderr,
"xtrabackup: starting shutdown with innodb_fast_shutdown = %lu\n",
1526 free(internal_innobase_data_file_path);
1539 fprintf(stderr,
"xtrabackup: innodb_end(): Error occured.\n");
1545xtrabackup_read_metadata(
char *filename)
1549 fp = fopen(filename,
"r");
1551 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filename);
1555 if (fscanf(fp,
"backup_type = %29s\n", metadata_type)
1558 if (fscanf(fp,
"from_lsn = %" PRIu64
"\n", &metadata_from_lsn)
1561 if (fscanf(fp,
"to_lsn = %" PRIu64
"\n", &metadata_to_lsn)
1564 if (fscanf(fp,
"last_lsn = %" PRIu64
"\n", &metadata_last_lsn)
1566 metadata_last_lsn = 0;
1575xtrabackup_write_metadata(
char *filename)
1579 fp = fopen(filename,
"w");
1581 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filename);
1585 if (fprintf(fp,
"backup_type = %s\n", metadata_type)
1588 if (fprintf(fp,
"from_lsn = %" PRIu64
"\n", metadata_from_lsn)
1591 if (fprintf(fp,
"to_lsn = %" PRIu64
"\n", metadata_to_lsn)
1594 if (fprintf(fp,
"last_lsn = %" PRIu64
"\n", metadata_last_lsn)
1613 fp = fopen(filepath,
"r");
1619 if (fscanf(fp,
"page_size = %lu\n", &info->page_size) != 1)
1631xb_write_delta_metadata(
const char *filepath,
const xb_delta_info_t *info)
1635 fp = fopen(filepath,
"w");
1637 fprintf(stderr,
"xtrabackup: Error: cannot open %s\n", filepath);
1641 if (fprintf(fp,
"page_size = %lu\n", info->page_size) < 0)
1651xtrabackup_io_throttling(
void)
1653 if (xtrabackup_throttle && (io_ticket--) < 0) {
1655 os_event_wait(wait_throttle);
1661#define COPY_CHUNK 64
1664xtrabackup_copy_datafile(
fil_node_t* node, uint thread_n)
1668 char dst_path[OS_FILE_MAX_PATH +
sizeof(
".delta") +
1669 sizeof(XB_DELTA_INFO_SUFFIX)];
1670 char meta_path[OS_FILE_MAX_PATH +
sizeof(
".delta") +
1671 sizeof(XB_DELTA_INFO_SUFFIX)];
1677 ulint page_in_buffer= 0;
1678 ulint incremental_buffers = 0;
1680 ulint page_size_shift;
1687 if (xtrabackup_tables && (!trx_sys_sys_space(node->
space->
id)))
1689 if (xtrabackup_tables && (node->
space->
id != 0))
1693 int p_len, regres= 0;
1700 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1705 p_len = strlen(p) - strlen(
".ibd");
1717 for (i = 0; i < tables_regex_num; i++) {
1718 regres = regexec(&tables_regex[i], prev, 1, tables_regmatch, 0);
1719 if (regres != REG_NOMATCH)
1724 *(p - 1) = SRV_PATH_SEPARATOR;
1726 if ( regres == REG_NOMATCH ) {
1727 printf(
"[%02u] Copying %s is skipped.\n",
1728 thread_n, node->
name);
1734 if (xtrabackup_tables_file && (!trx_sys_sys_space(node->
space->
id)))
1736 if (xtrabackup_tables_file && (node->
space->
id != 0))
1739 xtrabackup_tables_t* table;
1747 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1752 p_len = strlen(p) - strlen(
".ibd");
1764 xtrabackup_tables_t*,
1767 !strcmp(table->name, prev));
1772 printf(
"[%02u] Copying %s is skipped.\n",
1773 thread_n, node->
name);
1779 zip_size = fil_space_get_zip_size(node->
space->
id);
1780 if (zip_size == ULINT_UNDEFINED) {
1781 fprintf(stderr,
"[%02u] xtrabackup: Warning: "
1782 "Failed to determine page size for %s.\n"
1783 "[%02u] xtrabackup: Warning: We assume the table was "
1784 "dropped during xtrabackup execution and ignore the "
1785 "file.\n", thread_n, node->
name, thread_n);
1787 }
else if (zip_size) {
1788 page_size = zip_size;
1789 page_size_shift = get_bit_shift(page_size);
1790 fprintf(stderr,
"[%02u] %s is compressed with page size = "
1791 "%lu bytes\n", thread_n, node->
name, page_size);
1792 if (page_size_shift < 10 || page_size_shift > 14) {
1793 fprintf(stderr,
"[%02u] xtrabackup: Error: Invalid "
1794 "page size.\n", thread_n);
1798 page_size = UNIV_PAGE_SIZE;
1799 page_size_shift = UNIV_PAGE_SIZE_SHIFT;
1803 if (trx_sys_sys_space(node->
space->
id))
1811 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
1815 sprintf(dst_path,
"%s/%s", xtrabackup_target_dir, p);
1818 sprintf(dst_path,
"%s%s", xtrabackup_target_dir, strstr(node->
name, SRV_PATH_SEPARATOR_STR));
1821 if (xtrabackup_incremental) {
1822 size_t dst_path_len = strlen(dst_path);
1823 if (dst_path_len +
sizeof(XB_DELTA_INFO_SUFFIX)
1825 || dst_path_len +
sizeof(
".delta") >
sizeof(dst_path)) {
1828 memcpy(meta_path, dst_path, dst_path_len);
1829 memcpy(meta_path + dst_path_len, XB_DELTA_INFO_SUFFIX,
1830 sizeof(XB_DELTA_INFO_SUFFIX));
1831 memcpy(dst_path + dst_path_len,
".delta",
sizeof(
".delta"));
1834 bzero(incremental_buffer, (page_size/4) * page_size);
1839 info.page_size = page_size;
1844 src_file = os_file_create_simple_no_error_handling(
1847 OS_FILE_READ_ONLY, &success);
1853 "[%02u] xtrabackup: Warning: cannot open %s\n"
1854 "[%02u] xtrabackup: Warning: We assume the "
1855 "table was dropped during xtrabackup execution "
1856 "and ignore the file.\n",
1857 thread_n, node->
name, thread_n);
1868#ifdef USE_POSIX_FADVISE
1869 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
1870 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1875 dst_file = os_file_create(
1877 dst_path, OS_FILE_CREATE,
1883 fprintf(stderr,
"[%02u] xtrabackup: error: "
1884 "cannot open %s\n", thread_n, dst_path);
1888#ifdef USE_POSIX_FADVISE
1889 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
1893 printf(
"[%02u] Copying %s \n to %s\n", thread_n,
1894 node->
name, dst_path);
1896 buf2 = (
unsigned char*)
ut_malloc(COPY_CHUNK * page_size + UNIV_PAGE_SIZE);
1897 page = (
unsigned char*)
ut_align(buf2, UNIV_PAGE_SIZE);
1899 success = os_file_read(src_file, page, 0, 0, UNIV_PAGE_SIZE);
1906 for (offset = 0; offset < file_size; offset += COPY_CHUNK * page_size) {
1909 ulint retry_count = 10;
1911 if ((ulint)(file_size - offset) > COPY_CHUNK * page_size) {
1912 chunk = COPY_CHUNK * page_size;
1914 chunk = (ulint)(file_size - offset);
1918 xtrabackup_io_throttling();
1920 success = os_file_read(src_file, page,
1921 (ulint)(offset & 0xFFFFFFFFUL),
1922 (ulint)(offset >> 32), chunk);
1928 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1929 if (buf_page_is_corrupted(page + chunk_offset, zip_size))
1933 trx_sys_sys_space(node->
space->
id)
1937 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1939 && ((offset + (IB_INT64)chunk_offset) >> page_size_shift)
1940 < FSP_EXTENT_SIZE * 3) {
1944 ut_a(page_size == UNIV_PAGE_SIZE);
1945 fprintf(stderr,
"[%02u] xtrabackup: "
1946 "Page %lu seems double write "
1947 "buffer. passing the check.\n",
1950 (IB_INT64)chunk_offset) >>
1954 if (retry_count == 0) {
1956 "[%02u] xtrabackup: "
1957 "Error: 10 retries "
1958 "resulted in fail. This"
1964 fprintf(stderr,
"[%02u] xtrabackup: "
1965 "Database page corruption "
1966 "detected at page %lu. "
1970 (IB_INT64)chunk_offset)
1971 >> page_size_shift));
1977 if (xtrabackup_incremental) {
1978 for (chunk_offset = 0; chunk_offset < chunk; chunk_offset += page_size) {
1981 if (ut_dulint_cmp(incremental_lsn,
1982 MACH_READ_64(page + chunk_offset +
FIL_PAGE_LSN)) < 0) {
1984 IB_INT64 offset_on_page;
1986 if (page_in_buffer == page_size/4) {
1988 success = os_file_write(dst_path, dst_file, incremental_buffer,
1989 ((incremental_buffers * (page_size/4))
1990 << page_size_shift) & 0xFFFFFFFFUL,
1991 (incremental_buffers * (page_size/4))
1992 >> (32 - page_size_shift),
1993 page_in_buffer * page_size);
1998 incremental_buffers++;
2001 bzero(incremental_buffer, (page_size/4) * page_size);
2007 offset_on_page = ((offset + (IB_INT64)chunk_offset) >> page_size_shift);
2008 ut_a(offset_on_page >> 32 == 0);
2010 mach_write_to_4(incremental_buffer + page_in_buffer * 4, (ulint)offset_on_page);
2011 memcpy(incremental_buffer + page_in_buffer * page_size,
2012 page + chunk_offset, page_size);
2019 success = os_file_write(dst_path, dst_file, page,
2020 (ulint)(offset & 0xFFFFFFFFUL),
2021 (ulint)(offset >> 32), chunk);
2029 if (xtrabackup_incremental) {
2031 if (page_in_buffer != page_size/4) {
2032 mach_write_to_4(incremental_buffer + page_in_buffer * 4, 0xFFFFFFFFUL);
2038 success = os_file_write(dst_path, dst_file, incremental_buffer,
2039 ((incremental_buffers * (page_size/4))
2040 << page_size_shift) & 0xFFFFFFFFUL,
2041 (incremental_buffers * (page_size/4))
2042 >> (32 - page_size_shift),
2043 page_in_buffer * page_size);
2047 if (!xb_write_delta_metadata(meta_path, &info)) {
2048 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2049 "failed to write meta info for %s\n",
2050 thread_n, dst_path);
2055 success = os_file_flush(dst_file);
2074 printf(
"[%02u] ...done\n", thread_n);
2076 os_file_close(src_file);
2078 os_file_close(dst_file);
2082 if (src_file != -1 && !node->
open)
2083 os_file_close(src_file);
2085 os_file_close(dst_file);
2088 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2089 "xtrabackup_copy_datafile() failed.\n", thread_n);
2093 if (src_file != -1 && !node->
open)
2094 os_file_close(src_file);
2096 os_file_close(dst_file);
2099 fprintf(stderr,
"[%02u] xtrabackup: Warning: skipping file %s.\n",
2100 thread_n, node->
name);
2105xtrabackup_copy_logfile(LSN64 from_lsn,
bool is_last)
2109 LSN64 group_scanned_lsn;
2110 LSN64 contiguous_lsn;
2114 if (!xtrabackup_stream)
2115 ut_a(dst_log != -1);
2118 contiguous_lsn = ut_dulint_align_down(from_lsn,
2134 start_lsn = contiguous_lsn;
2139 xtrabackup_io_throttling();
2142 group, start_lsn, end_lsn);
2154 ulint scanned_checkpoint_no = 0;
2158 log_block = log_sys->buf;
2159 scanned_lsn = start_lsn;
2166 || !log_block_checksum_is_ok_or_old_format(log_block)) {
2169 && log_block_checksum_is_ok_or_old_format(log_block)) {
2171">> ###Warning###: The copying transaction log migh be overtaken already by the target.\n"
2172">> : Waiting log block no %lu, but the bumber is already %lu.\n"
2173">> : If the number equals %lu + n * %lu, it should be overtaken already.\n",
2182 && !log_block_checksum_is_ok_or_old_format(
2185"xtrabackup: Log block no %lu at lsn %" PRIu64
" has\n"
2186"xtrabackup: ok header, but checksum field contains %lu, should be %lu\n",
2208 if (ut_dulint_cmp(scanned_lsn, contiguous_lsn) > 0) {
2209 contiguous_lsn = scanned_lsn;
2216 (scanned_checkpoint_no > 0)
2218 < scanned_checkpoint_no)
2219 && (scanned_checkpoint_no
2230 scanned_lsn = ut_dulint_add(scanned_lsn, data_len);
2242 group_scanned_lsn = scanned_lsn;
2255 write_size = ut_dulint_minus(
2262 if (!xtrabackup_stream) {
2263 success = os_file_write(dst_log_path, dst_log, log_sys->buf,
2264 (ulint)(log_copy_offset & 0xFFFFFFFFUL),
2265 (ulint)(log_copy_offset >> 32), write_size);
2268 ulint stdout_write_size = write_size;
2269 if (finished && !is_last
2273 if (stdout_write_size) {
2274 ret = write(fileno(stdout), log_sys->buf, stdout_write_size);
2275 if (ret == stdout_write_size) {
2278 fprintf(stderr,
"write: %lu > %lu\n", stdout_write_size, ret);
2286 log_copy_offset += write_size;
2295 if (!xtrabackup_stream) {
2296 fprintf(stderr,
"xtrabackup: Error: os_file_write to %s\n", dst_log_path);
2298 fprintf(stderr,
"xtrabackup: Error: write to stdout\n");
2310 start_lsn = end_lsn;
2318 fprintf(stderr,
">> log scanned up to (%" PRIu64
")\n",group->
scanned_lsn);
2323 log_copy_scanned_lsn = group_scanned_lsn;
2326 ut_a(group == NULL);
2330 if (!xtrabackup_stream) {
2331 success = os_file_flush(dst_log);
2344 if (!xtrabackup_stream)
2345 os_file_close(dst_log);
2346 fprintf(stderr,
"xtrabackup: Error: xtrabackup_copy_logfile() failed.\n");
2351#define SLEEPING_PERIOD 5
2364 if (!xtrabackup_stream)
2365 ut_a(dst_log != -1);
2367 log_copying_running = TRUE;
2369 while(log_copying) {
2373 if(counter >= SLEEPING_PERIOD * 5) {
2374 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, FALSE))
2381 if(xtrabackup_copy_logfile(log_copy_scanned_lsn, TRUE))
2384 log_copying_succeed = TRUE;
2386 log_copying_running = FALSE;
2403 ut_a(xtrabackup_backup);
2405 while (log_copying) {
2413 io_ticket = xtrabackup_throttle;
2418 xtrabackup_throttle = 0;
2441 segment = *((ulint*)arg);
2444 fil_aio_wait(segment);
2465xtrabackup_create_output_dir(
2470 char path[FN_REFLEN];
2474 ptr1 = strstr(space->
name, SRV_PATH_SEPARATOR_STR);
2476 ptr2 = strstr(ptr1 + 1, SRV_PATH_SEPARATOR_STR);
2481 if(!trx_sys_sys_space(space->
id) && ptr2)
2483 if(space->
id && ptr2)
2488 snprintf(path,
sizeof(path),
"%s%s", xtrabackup_target_dir,
2490 *ptr2 = SRV_PATH_SEPARATOR;
2492 if (mkdir(path, 0777) != 0 && errno != EEXIST) {
2494 "xtrabackup: Error: cannot mkdir %d: %s\n",
2506data_copy_thread_func(
2511 uint num = ctxt->num;
2513 ibool space_changed;
2516 while ((node = datafiles_iter_next(ctxt->it, &space_changed)) != NULL) {
2517 space = node->
space;
2519 if (space_changed && xtrabackup_create_output_dir(space))
2523 if(xtrabackup_copy_datafile(node, num)) {
2524 fprintf(stderr,
"[%02u] xtrabackup: Error: "
2525 "failed to copy datafile.\n",
2536 OS_THREAD_DUMMY_RETURN;
2541xtrabackup_backup_func(
void)
2543 struct stat stat_info;
2546#ifdef USE_POSIX_FADVISE
2547 fprintf(stderr,
"xtrabackup: uses posix_fadvise().\n");
2552 if (chdir(mysql_real_data_home) != 0)
2554 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
2557 fprintf(stderr,
"xtrabackup: cd to %s\n", mysql_real_data_home);
2559 mysql_data_home= mysql_data_home_buff;
2560 mysql_data_home[0]=FN_CURLIB;
2561 mysql_data_home[1]=0;
2564 srv_read_only = TRUE;
2567 if(innodb_init_param())
2570 if (srv_file_flush_method_str == NULL) {
2576 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"fsync")) {
2579 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DSYNC")) {
2582 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"O_DIRECT")) {
2584 fprintf(stderr,
"xtrabackup: use O_DIRECT\n");
2585 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"littlesync")) {
2588 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"nosync")) {
2591 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"normal")) {
2593 os_aio_use_native_aio = FALSE;
2595 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
"unbuffered")) {
2597 os_aio_use_native_aio = FALSE;
2599 }
else if (0 ==
ut_strcmp(srv_file_flush_method_str,
2600 "async_unbuffered")) {
2605 "xtrabackup: Unrecognized value %s for innodb_flush_method\n",
2606 srv_file_flush_method_str);
2616 srv_max_n_threads = 50000;
2621 srv_max_n_threads = 10000;
2623 srv_max_n_threads = 1000;
2632 nr = srv_n_data_files;
2634 for (i = 0; i < nr; i++) {
2635 srv_data_file_sizes[i] = srv_data_file_sizes[i]
2636 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2639 srv_last_file_size_max = srv_last_file_size_max
2640 * ((1024 * 1024) / UNIV_PAGE_SIZE);
2642 srv_log_file_size = srv_log_file_size / UNIV_PAGE_SIZE;
2644 srv_log_buffer_size = srv_log_buffer_size / UNIV_PAGE_SIZE;
2653 ibool create_new_db;
2655 ibool create_new_doublewrite_file;
2657 ibool log_file_created;
2658 ibool log_created = FALSE;
2659 ibool log_opened = FALSE;
2660 LSN64 min_flushed_lsn;
2661 LSN64 max_flushed_lsn;
2662 ulint sum_of_new_sizes;
2669#define SRV_N_PENDING_IOS_PER_THREAD OS_AIO_N_PENDING_IOS_PER_THREAD
2670#define SRV_MAX_N_PENDING_SYNC_IOS 100
2672 srv_n_file_io_threads = 2 + srv_n_read_io_threads + srv_n_write_io_threads;
2674 os_aio_init(8 * SRV_N_PENDING_IOS_PER_THREAD,
2675 srv_n_read_io_threads,
2676 srv_n_write_io_threads,
2677 SRV_MAX_N_PENDING_SYNC_IOS);
2680 srv_max_n_open_files);
2687 for (i = 0; i < srv_n_file_io_threads; i++) {
2695 err = open_or_create_data_files(&create_new_db,
2697 &create_new_doublewrite_file,
2699 &min_flushed_lsn, &max_flushed_lsn,
2701 if (err != DB_SUCCESS) {
2703"xtrabackup: Could not open or create data files.\n"
2704"xtrabackup: If you tried to add new data files, and it failed here,\n"
2705"xtrabackup: you should now edit innodb_data_file_path in my.cnf back\n"
2706"xtrabackup: to what it was, and remove the new ibdata files InnoDB created\n"
2707"xtrabackup: in this failed attempt. InnoDB only wrote those files full of\n"
2708"xtrabackup: zeros, but did not yet use them in any way. But be careful: do not\n"
2709"xtrabackup: remove old data files which contain your precious data!\n");
2716 if (create_new_db) {
2717 fprintf(stderr,
"xtrabackup: Something wrong with source files...\n");
2721 for (i = 0; i < srv_n_log_files; i++) {
2722 err = open_or_create_log_file(create_new_db, &log_file_created,
2724 if (err != DB_SUCCESS) {
2730 if (log_file_created) {
2735 if ((log_opened && create_new_db)
2736 || (log_opened && log_created)) {
2738 "xtrabackup: Error: all log files must be created at the same time.\n"
2739 "xtrabackup: All log files must be created also in database creation.\n"
2740 "xtrabackup: If you want bigger or smaller log files, shut down the\n"
2741 "xtrabackup: database and make sure there were no errors in shutdown.\n"
2742 "xtrabackup: Then delete the existing log files. Edit the .cnf file\n"
2743 "xtrabackup: and start the database again.\n");
2751 if (log_file_created) {
2752 fprintf(stderr,
"xtrabackup: Something wrong with source files...\n");
2761 if (xtrabackup_extra_lsndir
2762 && (stat(xtrabackup_extra_lsndir,&stat_info) != 0)
2763 && (mkdir(xtrabackup_extra_lsndir,0777) != 0)){
2764 fprintf(stderr,
"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_extra_lsndir);
2769 if (!xtrabackup_stream) {
2772 if (stat(xtrabackup_target_dir,&stat_info) != 0
2773 && (mkdir(xtrabackup_target_dir,0777) != 0)){
2774 fprintf(stderr,
"xtrabackup: Error: cannot mkdir %d: %s\n",errno,xtrabackup_target_dir);
2779 fprintf(stderr,
"xtrabackup: Stream mode.\n");
2785 fil_system_t* f_system = fil_system;
2791 boost::scoped_array<byte> log_hdr_buf_(
2802 log_hdr_buf = (
byte*)
ut_align(log_hdr_buf_.get(),
2813 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2815 if (err != DB_SUCCESS) {
2821 buf = log_sys->checkpoint_buf;
2823 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2824 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2829 0, 0, LOG_FILE_HDR_SIZE,
2830 log_hdr_buf, max_cp_group);
2833 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
2835 if (err != DB_SUCCESS) {
2841 buf = log_sys->checkpoint_buf;
2843 if(ut_dulint_cmp(checkpoint_no_start,
2844 MACH_READ_64(buf + LOG_CHECKPOINT_NO)) != 0) {
2845 checkpoint_lsn_start = MACH_READ_64(buf + LOG_CHECKPOINT_LSN);
2846 checkpoint_no_start = MACH_READ_64(buf + LOG_CHECKPOINT_NO);
2847 goto reread_log_header;
2850 if (!xtrabackup_stream) {
2853 sprintf(dst_log_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
2856 dst_log = os_file_create(
2858 dst_log_path, OS_FILE_CREATE,
2866"xtrabackup: error: cannot open %s\n",
2871#ifdef USE_POSIX_FADVISE
2872 posix_fadvise(dst_log, 0, 0, POSIX_FADV_DONTNEED);
2878 strcpy((
char*) log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
2881 (
char*) log_hdr_buf + (LOG_FILE_WAS_CREATED_BY_HOT_BACKUP
2882 + (
sizeof "xtrabkup ") - 1));
2884 if (!xtrabackup_stream) {
2885 success = os_file_write(dst_log_path, dst_log, log_hdr_buf,
2886 0, 0, LOG_FILE_HDR_SIZE);
2889 if ((write(fileno(stdout), log_hdr_buf, LOG_FILE_HDR_SIZE)
2890 - LOG_FILE_HDR_SIZE) == 0)
2898 log_copy_offset += LOG_FILE_HDR_SIZE;
2901 os_file_close(dst_log);
2909 if(xtrabackup_throttle) {
2912 io_ticket = xtrabackup_throttle;
2920 if(xtrabackup_copy_logfile(checkpoint_lsn_start, FALSE))
2928 if (!xtrabackup_stream) {
2937 printf(
"xtrabackup: Starting %u threads for parallel "
2938 "data files transfer\n", parallel);
2940 it = datafiles_iter_new(f_system);
2943 "xtrabackup: Error: "
2944 "datafiles_iter_new() failed.\n");
2954 count_mutex = OS_MUTEX_CREATE();
2956 for (i = 0; i < parallel; i++) {
2957 data_threads[i].it = it;
2958 data_threads[i].num = i+1;
2959 data_threads[i].count = &count;
2960 data_threads[i].count_mutex = count_mutex;
2963 &data_threads[i].
id);
2980 datafiles_iter_free(it);
2989 if (xtrabackup_suspend_at_end) {
2991 char suspend_path[FN_REFLEN];
2992 ibool success, exists;
2993 os_file_type_t
type;
2995 sprintf(suspend_path,
"%s%s", xtrabackup_target_dir,
2996 "/xtrabackup_suspended");
3000 suspend_file = os_file_create(
3002 suspend_path, OS_FILE_OVERWRITE,
3006 fprintf(stderr,
"xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
3009 if (suspend_file != -1)
3010 os_file_close(suspend_file);
3019 xtrabackup_suspend_at_end = FALSE;
3023 latest_cp = ut_dulint_zero;
3029 err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
3031 if (err != DB_SUCCESS) {
3032 fprintf(stderr,
"xtrabackup: Error: recv_find_max_checkpoint() failed.\n");
3038 latest_cp = MACH_READ_64(log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN);
3040 if (!xtrabackup_stream) {
3041 printf(
"xtrabackup: The latest check point (for incremental): '%" PRIu64
"'\n",
3044 fprintf(stderr,
"xtrabackup: The latest check point (for incremental): '%" PRIu64
"'\n",
3050 log_copying = FALSE;
3051 if (!xtrabackup_stream) {
3052 printf(
"xtrabackup: Stopping log copying thread");
3053 while (log_copying_running) {
3059 while (log_copying_running)
3065 char filename[FN_REFLEN];
3067 if(!xtrabackup_incremental) {
3068 strcpy(metadata_type,
"full-backuped");
3069 metadata_from_lsn = ut_dulint_zero;
3071 strcpy(metadata_type,
"incremental");
3072 metadata_from_lsn = incremental_lsn;
3074 metadata_to_lsn = latest_cp;
3075 metadata_last_lsn = log_copy_scanned_lsn;
3077 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
3078 if (xtrabackup_write_metadata(filename))
3079 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
3081 if(xtrabackup_extra_lsndir) {
3082 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3083 if (xtrabackup_write_metadata(filename))
3084 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3088 if (!log_copying_succeed) {
3089 fprintf(stderr,
"xtrabackup: Error: log_copying_thread failed.\n");
3093 if (!xtrabackup_stream)
3094 os_file_close(dst_log);
3099 if (!xtrabackup_stream) {
3100 printf(
"xtrabackup: Transaction log of lsn (%" PRIu64
") to (%" PRIu64
") was copied.\n",
3101 checkpoint_lsn_start, log_copy_scanned_lsn);
3103 fprintf(stderr,
"xtrabackup: Transaction log of lsn (%" PRIu64
") to (%" PRIu64
") was copied.\n",
3104 checkpoint_lsn_start, log_copy_scanned_lsn);
3105 if(xtrabackup_extra_lsndir) {
3106 char filename[FN_REFLEN];
3107 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
3108 if (xtrabackup_write_metadata(filename))
3109 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
3116xtrabackup_stats_level(
3117 dict_index_t* index,
3125 ulint right_page_no;
3132 ulint* offsets = NULL;
3134 uint64_t n_pages, n_pages_extern;
3135 uint64_t sum_data, sum_data_extern;
3139 n_pages = sum_data = n_recs = 0;
3140 n_pages_extern = sum_data_extern = 0;
3146 fprintf(stdout,
" leaf pages: ");
3148 fprintf(stdout,
" level %lu pages: ", level);
3153 block = btr_root_block_get(index, &mtr);
3154 page = buf_block_get_frame(block);
3157 zip_size = fil_space_get_zip_size(space);
3168 node_ptr = page_cur_get_rec(&cursor);
3169 offsets = rec_get_offsets(node_ptr, index, offsets,
3170 ULINT_UNDEFINED, &heap);
3172 block = btr_node_ptr_get_child(node_ptr, index, offsets, &mtr);
3173 page = buf_block_get_frame(block);
3196 mem_heap_t* local_heap = NULL;
3197 ulint offsets_[REC_OFFS_NORMAL_SIZE];
3198 ulint* local_offsets = offsets_;
3200 *offsets_ = (
sizeof offsets_) /
sizeof *offsets_;
3211 local_offsets = rec_get_offsets(cur.
rec, index, local_offsets,
3212 ULINT_UNDEFINED, &local_heap);
3215 for (i = 0; i < n_fields; i++) {
3228 data = rec_get_nth_field(cur.
rec, local_offsets, i, &local_len);
3238 fprintf(stderr,
"\nWarning: several record may share same external page.\n");
3243 local_block =
btr_block_get(space_id, zip_size, page_no, RW_S_LATCH, &local_mtr);
3244 local_page = buf_block_get_frame(local_block);
3246 blob_header = local_page + offset;
3247#define BTR_BLOB_HDR_PART_LEN 0
3248#define BTR_BLOB_HDR_NEXT_PAGE_NO 4
3264 sum_data_extern += part_len;
3285 block =
btr_block_get(space, zip_size, right_page_no, RW_X_LATCH, &mtr);
3286 page = buf_block_get_frame(block);
3292 page_size = zip_size;
3294 page_size = UNIV_PAGE_SIZE;
3298 fprintf(stdout,
"recs=%" PRIu64
", ", n_recs);
3300 fprintf(stdout,
"pages=%" PRIu64
", data=%" PRIu64
" bytes, data/pages=%" PRIu64
"%%",
3302 ((sum_data * 100)/ page_size)/n_pages);
3305 if (level == 0 && n_pages_extern) {
3308 fprintf(stdout,
" external pages: ");
3310 fprintf(stdout,
"pages=%" PRIu64
", data=%" PRIu64
" bytes, data/pages=%" PRIu64
"%%",
3311 n_pages_extern, sum_data_extern,
3312 ((sum_data_extern * 100)/ page_size)/n_pages_extern);
3318 xtrabackup_stats_level(index, level - 1);
3325xtrabackup_stats_func(
void)
3331 if (chdir(mysql_real_data_home) != 0)
3333 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3336 fprintf(stderr,
"xtrabackup: cd to %s\n", mysql_real_data_home);
3338 mysql_data_home= mysql_data_home_buff;
3339 mysql_data_home[0]=FN_CURLIB;
3340 mysql_data_home[1]=0;
3343 srv_read_only = TRUE;
3344 srv_fake_write = TRUE;
3347 if(innodb_init_param())
3352 for (n = 0; n < srv_n_log_files; n++) {
3353 char logname[FN_REFLEN];
3355 os_file_type_t
type;
3357 sprintf(logname,
"ib_logfile%lu", (ulong) n);
3359 type != OS_FILE_TYPE_FILE) {
3360 fprintf(stderr,
"xtrabackup: Error: "
3361 "Cannot find log file %s.\n", logname);
3362 fprintf(stderr,
"xtrabackup: Error: "
3363 "to use the statistics feature, you need a "
3364 "clean copy of the database including "
3365 "correctly sized log files, so you need to "
3366 "execute with --prepare twice to use this "
3367 "functionality on a backup.\n");
3372 fprintf(stderr,
"xtrabackup: Starting 'read-only' InnoDB instance to gather index statistics.\n"
3373 "xtrabackup: Using %" PRIu64
" bytes for buffer pool (set by --use-memory parameter)\n",
3374 xtrabackup_use_memory);
3379 fprintf(stdout,
"\n\n<INDEX STATISTICS>\n");
3384 dict_table_t* sys_tables;
3385 dict_index_t* sys_index;
3386 dict_table_t* table;
3396 mutex_enter(&kernel_mutex);
3397 srv_fatal_semaphore_wait_threshold += 72000;
3398 mutex_exit(&kernel_mutex);
3400 mutex_enter(&(dict_sys->mutex));
3412 rec = btr_pcur_get_rec(&pcur);
3421 mutex_exit(&(dict_sys->mutex));
3425 mutex_enter(&kernel_mutex);
3426 srv_fatal_semaphore_wait_threshold -= 72000;
3427 mutex_exit(&kernel_mutex);
3432 field = rec_get_nth_field_old(rec, 0, &len);
3439 char* table_name =
mem_strdupl((
char*) field, len);
3441 btr_pcur_store_position(&pcur, &mtr);
3449 if (xtrabackup_tables) {
3454 p = strstr(table->name, SRV_PATH_SEPARATOR_STR);
3459 for (i = 0; i < tables_regex_num; i++) {
3460 regres = regexec(&tables_regex[i], table->name, 1, tables_regmatch, 0);
3461 if (regres != REG_NOMATCH)
3466 *p = SRV_PATH_SEPARATOR;
3468 if ( regres == REG_NOMATCH )
3472 if (xtrabackup_tables_file) {
3473 xtrabackup_tables_t* xtable;
3476 xtrabackup_tables_t*,
3478 ut_ad(xtable->name),
3479 !strcmp(xtable->name, table->name));
3486 if (table == NULL) {
3487 fputs(
"InnoDB: Failed to load table ", stderr);
3491 dict_index_t* index;
3496 if (dict_table_get_first_index(table)) {
3498 dict_update_statistics(table, TRUE, FALSE);
3499#elif defined(INNODB_VERSION_SHORT)
3500 dict_update_statistics(table, TRUE);
3502 dict_update_statistics_low(table, TRUE);
3509 while (index != NULL) {
3513 if (index->n_user_defined_cols > 0) {
3514 n_vals = index->stat_n_diff_key_vals[
3515 index->n_user_defined_cols];
3517 n_vals = index->stat_n_diff_key_vals[1];
3521 " table: %s, index: %s, space id: %lu, root page: %lu"
3523 "\n estimated statistics in dictionary:\n"
3524 " key vals: %lu, leaf pages: %lu, size pages: %lu\n"
3525 " real statistics:\n",
3526 table->name, index->name,
3527 (ulong) index->space,
3528 (ulong) index->page,
3529 (ulong) fil_space_get_zip_size(index->space),
3531 (ulong) index->stat_n_leaf_pages,
3532 (ulong) index->stat_index_size);
3542 root = btr_root_get(index, &local_mtr);
3546 xtrabackup_stats_level(index, page_level);
3577xtrabackup_init_temp_log(
void)
3580 char src_path[FN_REFLEN];
3581 char dst_path[FN_REFLEN];
3586 byte* log_buf_ = NULL;
3592 LSN64 checkpoint_no;
3596 max_no = ut_dulint_zero;
3598 if(!xtrabackup_incremental_dir) {
3599 sprintf(dst_path,
"%s%s", xtrabackup_target_dir,
"/ib_logfile0");
3600 sprintf(src_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
3602 sprintf(dst_path,
"%s%s", xtrabackup_incremental_dir,
"/ib_logfile0");
3603 sprintf(src_path,
"%s%s", xtrabackup_incremental_dir,
"/xtrabackup_logfile");
3609 src_file = os_file_create_simple_no_error_handling(
3612 OS_FILE_READ_WRITE , &success);
3618"xtrabackup: Warning: cannot open %s. will try to find.\n",
3622 src_file = os_file_create_simple_no_error_handling(
3625 OS_FILE_READ_WRITE , &success);
3629" xtrabackup: Fatal error: cannot find %s.\n",
3635 log_buf_ = (
unsigned char*)
ut_malloc(LOG_FILE_HDR_SIZE * 2);
3636 log_buf = (
unsigned char*)
ut_align(log_buf_, LOG_FILE_HDR_SIZE);
3638 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3643 if (
ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3644 (
byte*)
"xtrabkup", (
sizeof "xtrabkup") - 1) == 0) {
3646" xtrabackup: 'ib_logfile0' seems to be 'xtrabackup_logfile'. will retry.\n");
3651 os_file_close(src_file);
3655 success = os_file_rename(
3657 dst_path, src_path);
3666" xtrabackup: Fatal error: cannot find %s.\n",
3672 os_file_close(src_file);
3678#ifdef USE_POSIX_FADVISE
3679 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3680 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3691 log_buf_ = (
unsigned char*)
ut_malloc(UNIV_PAGE_SIZE * 129);
3692 log_buf = (
unsigned char*)
ut_align(log_buf_, UNIV_PAGE_SIZE);
3695 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3700 if (
ut_memcmp(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
3701 (
byte*)
"xtrabkup", (
sizeof "xtrabkup") - 1) != 0 ) {
3702 printf(
"xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.\n");
3711 for (field = LOG_CHECKPOINT_1; field <= LOG_CHECKPOINT_2;
3712 field += LOG_CHECKPOINT_2 - LOG_CHECKPOINT_1) {
3713 if (!recv_check_cp_is_consistent(log_buf + field))
3714 goto not_consistent;
3716 checkpoint_no = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_NO);
3718 if (ut_dulint_cmp(checkpoint_no, max_no) >= 0) {
3719 max_no = checkpoint_no;
3720 max_lsn = MACH_READ_64(log_buf + field + LOG_CHECKPOINT_LSN);
3739 if (ut_dulint_cmp(max_no, ut_dulint_zero) == 0) {
3740 fprintf(stderr,
"xtrabackup: No valid checkpoint found.\n");
3746 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN, max_lsn);
3748 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3751 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_ARCHIVED_LSN,
3752 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3755 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_1, LOG_CHECKPOINT_CHECKSUM_1);
3756 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3758 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN,
3759 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3760 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3762 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN, max_lsn);
3764 LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3767 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_ARCHIVED_LSN,
3768 (ib_uint64_t)(LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
3771 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_2, LOG_CHECKPOINT_CHECKSUM_1);
3772 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_1, fold);
3774 fold =
ut_fold_binary(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN,
3775 LOG_CHECKPOINT_CHECKSUM_2 - LOG_CHECKPOINT_LSN);
3776 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_CHECKSUM_2, fold);
3779 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
3786 if (file_size % UNIV_PAGE_SIZE) {
3787 memset(log_buf, 0, UNIV_PAGE_SIZE);
3788 success = os_file_write(src_path, src_file, log_buf,
3789 (ulint)(file_size & 0xFFFFFFFFUL),
3790 (ulint)(file_size >> 32),
3791 UNIV_PAGE_SIZE - (file_size % UNIV_PAGE_SIZE));
3803 memset(log_buf, 0, UNIV_PAGE_SIZE * 128);
3804 expand = file_size / UNIV_PAGE_SIZE / 8;
3806 for (; expand > 128; expand -= 128) {
3807 success = os_file_write(src_path, src_file, log_buf,
3808 (ulint)(file_size & 0xFFFFFFFFUL),
3809 (ulint)(file_size >> 32),
3810 UNIV_PAGE_SIZE * 128);
3814 file_size += UNIV_PAGE_SIZE * 128;
3818 success = os_file_write(src_path, src_file, log_buf,
3819 (ulint)(file_size & 0xFFFFFFFFUL),
3820 (ulint)(file_size >> 32),
3821 expand * UNIV_PAGE_SIZE);
3825 file_size += UNIV_PAGE_SIZE * expand;
3830 if (file_size < 2*1024*1024L) {
3831 memset(log_buf, 0, UNIV_PAGE_SIZE);
3832 while (file_size < 2*1024*1024L) {
3833 success = os_file_write(src_path, src_file, log_buf,
3834 (ulint)(file_size & 0xFFFFFFFFUL),
3835 (ulint)(file_size >> 32),
3840 file_size += UNIV_PAGE_SIZE;
3845 printf(
"xtrabackup: xtrabackup_logfile detected: size=%" PRIu64
", start_lsn=(%" PRIu64
")\n",
3846 file_size, max_lsn);
3848 os_file_close(src_file);
3852 innobase_log_group_home_dir_backup = innobase_log_group_home_dir;
3853 innobase_log_file_size_backup = innobase_log_file_size;
3854 innobase_log_files_in_group_backup = innobase_log_files_in_group;
3857 innobase_log_group_home_dir = NULL;
3858 innobase_log_file_size = file_size;
3859 innobase_log_files_in_group = 1;
3861 srv_thread_concurrency = 0;
3864 success = os_file_rename(
3866 src_path, dst_path);
3870 xtrabackup_logfile_is_renamed = TRUE;
3877 os_file_close(src_file);
3884 os_file_close(src_file);
3887 fprintf(stderr,
"xtrabackup: Error: xtrabackup_init_temp_log() failed.\n");
3899 const char *delta_path,
3903 size_t len = strlen(delta_path);
3905 if (len <= 6 || strcmp(delta_path + len - 6,
".delta")) {
3908 memcpy(meta_path, delta_path, len - 6);
3909 strcpy(meta_path + len - 6, XB_DELTA_INFO_SUFFIX);
3915xtrabackup_apply_delta(
3916 const char* dirname,
3918 const char* filename,
3924 const size_t path_buffer_size = OS_FILE_MAX_PATH * 3 + 3;
3925 boost::scoped_array<char> src_path_buf(
new char[path_buffer_size]);
3926 boost::scoped_array<char> dst_path_buf(
new char[path_buffer_size]);
3927 boost::scoped_array<char> meta_path_buf(
new char[path_buffer_size]);
3928 char* src_path = src_path_buf.get();
3929 char* dst_path = dst_path_buf.get();
3930 char* meta_path = meta_path_buf.get();
3933 ibool last_buffer = FALSE;
3934 ulint page_in_buffer;
3935 ulint incremental_buffers = 0;
3939 ulint page_size_shift;
3941 ut_a(xtrabackup_incremental);
3944 snprintf(src_path, path_buffer_size,
"%s/%s/%s",
3945 dirname, dbname, filename);
3946 snprintf(dst_path, path_buffer_size,
"%s/%s/%s",
3947 xtrabackup_real_target_dir, dbname, filename);
3949 snprintf(src_path, path_buffer_size,
"%s/%s",
3951 snprintf(dst_path, path_buffer_size,
"%s/%s",
3952 xtrabackup_real_target_dir, filename);
3954 dst_path[strlen(dst_path) - 6] =
'\0';
3956 if (!get_meta_path(src_path, meta_path)) {
3964 if (!xb_read_delta_metadata(meta_path, &info)) {
3968 page_size = info.page_size;
3969 page_size_shift = get_bit_shift(page_size);
3970 fprintf(stderr,
"xtrabackup: page size for %s is %lu bytes\n",
3971 src_path, page_size);
3972 if (page_size_shift < 10 ||
3973 page_size_shift > UNIV_PAGE_SIZE_SHIFT_MAX) {
3975 "xtrabackup: error: invalid value of page_size "
3976 "(%lu bytes) read from %s\n", page_size, meta_path);
3980 src_file = os_file_create_simple_no_error_handling(
3986 "xtrabackup: error: cannot open %s\n",
3991#ifdef USE_POSIX_FADVISE
3992 posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3993 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
4000 dst_file = os_file_create_simple_no_error_handling(
4006 "xtrabackup: error: cannot open %s\n",
4011#ifdef USE_POSIX_FADVISE
4012 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
4019 printf(
"Applying %s ...\n", src_path);
4021 while (!last_buffer) {
4022 ulint cluster_header;
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),
4037 switch(cluster_header) {
4045 "xtrabackup: error: %s seems not .delta file.\n",
4050 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4057 ut_a(last_buffer || page_in_buffer == page_size / 4);
4060 success = os_file_read(src_file, incremental_buffer,
4061 ((incremental_buffers * (page_size / 4))
4062 << page_size_shift) & 0xFFFFFFFFUL,
4063 (incremental_buffers * (page_size / 4))
4064 >> (32 - page_size_shift),
4065 page_in_buffer * page_size);
4070 for (page_in_buffer = 1; page_in_buffer < page_size / 4;
4072 ulint offset_on_page;
4074 offset_on_page =
mach_read_from_4(incremental_buffer + page_in_buffer * 4);
4076 if (offset_on_page == 0xFFFFFFFFUL)
4086 success = os_file_write(dst_path, dst_file,
4087 incremental_buffer +
4088 page_in_buffer * page_size,
4089 (offset_on_page << page_size_shift) &
4091 offset_on_page >> (32 - page_size_shift),
4098 incremental_buffers++;
4102 os_file_close(src_file);
4104 os_file_close(dst_file);
4109 os_file_close(src_file);
4111 os_file_close(dst_file);
4112 fprintf(stderr,
"xtrabackup: Error: xtrabackup_apply_delta() failed.\n");
4117xtrabackup_apply_deltas(
bool check_newer)
4120 char dbpath[OS_FILE_MAX_PATH * 2 + 2];
4123 os_file_stat_t dbinfo;
4124 os_file_stat_t fileinfo;
4125 ulint err = DB_SUCCESS;
4126 static char current_dir[2];
4128 current_dir[0] = FN_CURLIB;
4130 srv_data_home = current_dir;
4135 if (dbdir != NULL) {
4136 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dbdir,
4139 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4140 goto next_file_item_1;
4143 if (strlen(fileinfo.
name) > 6
4144 && 0 == strcmp(fileinfo.
name +
4145 strlen(fileinfo.
name) - 6,
4147 xtrabackup_apply_delta(
4148 xtrabackup_incremental_dir, NULL,
4149 fileinfo.
name, check_newer);
4152 ret = fil_file_readdir_next_file(&err,
4153 xtrabackup_incremental_dir, dbdir,
4159 fprintf(stderr,
"xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4166 fprintf(stderr,
"xtrabackup: Cannot open dir %s\n", xtrabackup_incremental_dir);
4169 ret = fil_file_readdir_next_file(&err, xtrabackup_incremental_dir, dir,
4172 if (dbinfo.
type == OS_FILE_TYPE_FILE
4173 || dbinfo.
type == OS_FILE_TYPE_UNKNOWN) {
4175 goto next_datadir_item;
4178 snprintf(dbpath,
sizeof(dbpath),
"%s/%s",
4179 xtrabackup_incremental_dir, dbinfo.
name);
4184 if (dbdir != NULL) {
4186 ret = fil_file_readdir_next_file(&err, dbpath, dbdir,
4190 if (fileinfo.
type == OS_FILE_TYPE_DIR) {
4192 goto next_file_item_2;
4195 if (strlen(fileinfo.
name) > 6
4196 && 0 == strcmp(fileinfo.
name +
4197 strlen(fileinfo.
name) - 6,
4201 xtrabackup_apply_delta(
4202 xtrabackup_incremental_dir, dbinfo.
name,
4203 fileinfo.
name, check_newer);
4206 ret = fil_file_readdir_next_file(&err,
4214 ret = fil_file_readdir_next_file(&err,
4215 xtrabackup_incremental_dir,
4224xtrabackup_close_temp_log(
bool clear_flag)
4227 char src_path[FN_REFLEN];
4228 char dst_path[FN_REFLEN];
4232 byte* log_buf_ = NULL;
4235 if (!xtrabackup_logfile_is_renamed)
4239 innobase_log_group_home_dir = innobase_log_group_home_dir_backup;
4240 innobase_log_file_size = innobase_log_file_size_backup;
4241 innobase_log_files_in_group = innobase_log_files_in_group_backup;
4244 if(!xtrabackup_incremental_dir) {
4245 sprintf(dst_path,
"%s%s", xtrabackup_target_dir,
"/ib_logfile0");
4246 sprintf(src_path,
"%s%s", xtrabackup_target_dir,
"/xtrabackup_logfile");
4248 sprintf(dst_path,
"%s%s", xtrabackup_incremental_dir,
"/ib_logfile0");
4249 sprintf(src_path,
"%s%s", xtrabackup_incremental_dir,
"/xtrabackup_logfile");
4255 success = os_file_rename(
4257 dst_path, src_path);
4261 xtrabackup_logfile_is_renamed = FALSE;
4267 src_file = os_file_create_simple_no_error_handling(
4270 OS_FILE_READ_WRITE, &success);
4275#ifdef USE_POSIX_FADVISE
4276 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
4283 log_buf_ = (
unsigned char*)
ut_malloc(LOG_FILE_HDR_SIZE * 2);
4284 log_buf = (
unsigned char*)
ut_align(log_buf_, LOG_FILE_HDR_SIZE);
4286 success = os_file_read(src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4291 memset(log_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
' ', 4);
4293 success = os_file_write(src_path, src_file, log_buf, 0, 0, LOG_FILE_HDR_SIZE);
4298 os_file_close(src_file);
4304 os_file_close(src_file);
4307 fprintf(stderr,
"xtrabackup: Error: xtrabackup_close_temp_log() failed.\n");
4312xtrabackup_prepare_func(
void)
4316 if (chdir(xtrabackup_real_target_dir) != 0)
4318 fprintf(stderr,
"xtrabackup: cannot my_setwd %s\n", xtrabackup_real_target_dir);
4321 fprintf(stderr,
"xtrabackup: cd to %s\n", xtrabackup_real_target_dir);
4323 xtrabackup_target_dir= mysql_data_home_buff;
4324 mysql_data_home_buff[0]=FN_CURLIB;
4325 mysql_data_home_buff[1]=0;
4329 char filename[FN_REFLEN];
4331 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4333 if (xtrabackup_read_metadata(filename))
4334 fprintf(stderr,
"xtrabackup: error: xtrabackup_read_metadata()\n");
4336 if (!strcmp(metadata_type,
"full-backuped")) {
4337 fprintf(stderr,
"xtrabackup: This target seems to be not prepared yet.\n");
4338 }
else if (!strcmp(metadata_type,
"full-prepared")) {
4339 fprintf(stderr,
"xtrabackup: This target seems to be already prepared.\n");
4342 fprintf(stderr,
"xtrabackup: This target seems not to have correct metadata...\n");
4345 if (xtrabackup_incremental) {
4347 "xtrabackup: error: applying incremental backup needs target prepared.\n");
4351 if (xtrabackup_incremental
4352 && ut_dulint_cmp(metadata_to_lsn, incremental_lsn) != 0) {
4354 "xtrabackup: error: This incremental backup seems not to be proper for the target.\n"
4355 "xtrabackup: Check 'to_lsn' of the target and 'from_lsn' of the incremental.\n");
4361 srv_max_n_threads = 1000;
4366 srv_page_size_shift = 14;
4367 srv_page_size = (1 << srv_page_size_shift);
4372 if(xtrabackup_init_temp_log())
4375 if(xtrabackup_incremental)
4376 xtrabackup_apply_deltas(TRUE);
4387 if(innodb_init_param())
4390 srv_apply_log_only = (ibool) xtrabackup_apply_log_only;
4393 if(srv_n_file_io_threads < 10) {
4394 srv_n_file_io_threads = 10;
4397 fprintf(stderr,
"xtrabackup: Starting InnoDB instance for recovery.\n"
4398 "xtrabackup: Using %" PRIu64
" bytes for buffer pool (set by --use-memory parameter)\n",
4399 xtrabackup_use_memory);
4443 fil_system_t* f_system = fil_system;
4446 mutex_enter(&(f_system->
mutex));
4449 while (space != NULL) {
4458 mutex_exit(&(f_system->
mutex));
4462 mtr_s_lock(fil_space_get_latch(space->
id, &flags), &mtr);
4466 0, RW_S_LATCH, &mtr);
4468 + buf_block_get_frame(block);
4476 fil_extend_space_to_desired_size(&actual_size, space->
id, size);
4478 mutex_enter(&(f_system->
mutex));
4484 mutex_exit(&(f_system->
mutex));
4489 if (xtrabackup_export) {
4490 printf(
"xtrabackup: export option is specified.\n");
4491 if (innobase_file_per_table) {
4492 fil_system_t* f_system = fil_system;
4496 char info_file_path[FN_REFLEN];
4498 char table_name[FN_REFLEN];
4503 buf = (
byte*)
ut_malloc(UNIV_PAGE_SIZE * 2);
4504 page = (
byte*)
ut_align(buf, UNIV_PAGE_SIZE);
4507 innobase_fast_shutdown = 0;
4509 mutex_enter(&(f_system->
mutex));
4512 while (space != NULL) {
4516 || trx_sys_sys_space(space->
id)
4527 while (node != NULL) {
4529 char *next, *prev, *p;
4530 dict_table_t* table;
4531 dict_index_t* index;
4535 snprintf(info_file_path,
4536 sizeof(info_file_path),
"%s",
4538 len = strlen(info_file_path);
4539 info_file_path[len - 3] =
'e';
4540 info_file_path[len - 2] =
'x';
4541 info_file_path[len - 1] =
'p';
4545 while ((next = strstr(p, SRV_PATH_SEPARATOR_STR)) != NULL)
4550 info_file_path[len - 4] = 0;
4551 snprintf(table_name,
sizeof(table_name),
4554 info_file_path[len - 4] =
'.';
4556 mutex_exit(&(f_system->
mutex));
4557 mutex_enter(&(dict_sys->mutex));
4562"xtrabackup: error: cannot find dictionary record of table %s\n", table_name);
4565 index = dict_table_get_first_index(table);
4569"xtrabackup: error: sorry, cannot export over 31 indexes for now.\n");
4574 bzero(page, UNIV_PAGE_SIZE);
4578 xb_copy_padded((
char*)page + 12, 500,
4582"xtrabackup: export metadata of table '%s' to file `%s` (%lu indexes)\n",
4583 table_name, info_file_path, n_index);
4591 xb_copy_padded((
char*)page + n_index * 512 + 12,
4595"xtrabackup: name=%s, id.low=%lu, page=%lu\n",
4597 (ulint)(index->id & 0xFFFFFFFFUL),
4599 (ulint) index->page);
4601 index = dict_table_get_next_index(index);
4606 info_file = os_file_create(
4608 info_file_path, OS_FILE_OVERWRITE,
4614 success = os_file_write(info_file_path, info_file, page,
4615 0, 0, UNIV_PAGE_SIZE);
4620 success = os_file_flush(info_file);
4626 if (info_file != -1) {
4627 os_file_close(info_file);
4630 mutex_exit(&(dict_sys->mutex));
4631 mutex_enter(&(f_system->
mutex));
4638 mutex_exit(&(f_system->
mutex));
4642 printf(
"xtrabackup: export option is for file_per_table only, disabled.\n");
4647 printf(
"\n[notice (again)]\n"
4648 " If you use binary log and don't use any hack of group commit,\n"
4649 " the binary log position seems to be:\n");
4658 fp = fopen(
"xtrabackup_binlog_pos_innodb",
"w");
4660 fprintf(fp,
"%s\t%llu\n",
4667 printf(
"xtrabackup: failed to open 'xtrabackup_binlog_pos_innodb'\n");
4672 if ((xtrabackup_incremental
4674 ||(!xtrabackup_incremental
4676 printf(
"xtrabackup: ########################################################\n"
4677 "xtrabackup: # !!WARNING!! #\n"
4678 "xtrabackup: # The transaction log file should be wrong or corrupt. #\n"
4679 "xtrabackup: # The log was not applied to the intended LSN! #\n"
4680 "xtrabackup: ########################################################\n");
4681 if (xtrabackup_incremental) {
4682 printf(
"xtrabackup: The intended lsn is %" PRIu64
"\n",
4683 incremental_last_lsn);
4685 printf(
"xtrabackup: The intended lsn is %" PRIu64
"\n",
4703 if(xtrabackup_close_temp_log(TRUE))
4708 char filename[FN_REFLEN];
4710 strcpy(metadata_type,
"full-prepared");
4712 if(xtrabackup_incremental
4713 && ut_dulint_cmp(metadata_to_lsn, incremental_to_lsn) < 0)
4715 metadata_to_lsn = incremental_to_lsn;
4716 metadata_last_lsn = incremental_last_lsn;
4719 sprintf(filename,
"%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4720 if (xtrabackup_write_metadata(filename))
4721 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
4723 if(xtrabackup_extra_lsndir) {
4724 sprintf(filename,
"%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4725 if (xtrabackup_write_metadata(filename))
4726 fprintf(stderr,
"xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4730 if(!xtrabackup_create_ib_logfile)
4735 printf(
"\n[notice]\nWe cannot call InnoDB second time during the process lifetime.\n");
4736 printf(
"Please re-execte to create ib_logfile*. Sorry.\n");
4753 xtrabackup_close_temp_log(FALSE);
4760int main(
int argc,
char **argv)
4762 po::options_description commandline_options(_(
"Options used only in command line"));
4763 commandline_options.add_options()
4764 (
"target-dir", po::value<std::string>(), _(
"destination directory"))
4765 (
"backup", po::value<bool>(&xtrabackup_backup)->default_value(
false)->zero_tokens(), _(
"take backup to target-dir"))
4766 (
"stats", po::value<bool>(&xtrabackup_stats)->default_value(
false)->zero_tokens(), _(
"calc statistic of datadir (offline mysqld is recommended)"))
4767 (
"prepare", po::value<bool>(&xtrabackup_prepare)->default_value(
false)->zero_tokens(), _(
"prepare a backup for starting mysql server on the backup."))
4768 (
"export", po::value<bool>(&xtrabackup_export)->default_value(
false)->zero_tokens(), _(
"create files to import to another database when prepare."))
4769 (
"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."))
4770 (
"print-param", po::value<bool>(&xtrabackup_print_param)->default_value(
false)->zero_tokens(), _(
"print parameter of mysqld needed for copyback."))
4771 (
"use-memory", po::value<uint64_t>(&xtrabackup_use_memory)->default_value(100*1024*1024), _(
"The value is used instead of buffer_pool_size"))
4772 (
"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'"))
4773 (
"throttle", po::value<long>(&xtrabackup_throttle), _(
"limit count of IO operations (pairs of read&write) per second to IOS values (for '--backup')"))
4774 (
"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')."))
4775 (
"extra-lsndir", po::value<std::string>(), _(
"(for --backup): save an extra copy of the xtrabackup_checkpoints file in this directory."))
4776 (
"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!"))
4777 (
"incremental-basedir", po::value<std::string>(), _(
"(for --backup): copy only .ibd pages newer than backup at specified directory."))
4778 (
"incremental-dir", po::value<std::string>(), _(
"(for --prepare): apply .delta files and logfile in the specified directory."))
4779 (
"tables", po::value<std::string>(), _(
"filtering by regexp for table names."))
4780 (
"tables-file", po::value<std::string>(), _(
"filtering by list of the exact database.table name in the file."))
4781 (
"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. ###"))
4782 (
"datadir,h", po::value<std::string>(), _(
"Path to the database root."))
4783 (
"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."))
4784 (
"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."))
4785 (
"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."))
4786 (
"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."))
4787 (
"innodb-autoextend-increment", po::value<uint32_t>(&srv_auto_extend_increment)->default_value(8), _(
"Data file autoextend increment in megabytes"))
4788 (
"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."))
4789 (
"innodb-checksums", po::value<bool>(&innobase_use_checksums)->default_value(
true), _(
"Enable InnoDB checksums validation (enabled by default). Disable with --skip-innodb-checksums."))
4790 (
"innodb-data-file-path", po::value<std::string>(), _(
"Path to individual files and their sizes."))
4791 (
"innodb-data-home-dir", po::value<std::string>(), _(
"The common part for InnoDB table spaces."))
4792 (
"innodb-doublewrite", po::value<bool>(&innobase_use_doublewrite)->default_value(
true), _(
"Enable InnoDB doublewrite buffer (enabled by default). Disable with --skip-innodb-doublewrite."))
4793 (
"innodb-file-io-threads", po::value<long>(&innobase_file_io_threads)->default_value(4), _(
"Number of file I/O threads in InnoDB."))
4794 (
"innodb-file-per-table", po::value<bool>(&innobase_file_per_table), _(
"Stores each InnoDB table to an .ibd file in the database dir."))
4795 (
"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)."))
4796 (
"innodb-flush-method", po::value<std::string>(), _(
"With which method to flush data."))
4798 (
"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."))
4799 (
"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."))
4800 (
"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."))
4801 (
"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."))
4802 (
"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."))
4803 (
"innodb-log-group-home-dir", po::value<std::string>(), _(
"Path to InnoDB log files."))
4804 (
"innodb-max_dirty-pages-pct", po::value<ulong>(&srv_max_buf_pool_modified_pct)->default_value(90), _(
"Percentage of dirty pages allowed in bufferpool."))
4805 (
"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."))
4807 (
"innodb-page-size", po::value<uint32_t>(&innobase_page_size)->default_value(1 << 14), _(
"The universal page size of the database."))
4808 (
"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!"))
4809 (
"innodb-fast-checksum", po::value<bool>(&innobase_fast_checksum), _(
"Change the algorithm of checksum for the whole of datapage to 4-bytes word based."))
4810 (
"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."))
4811 (
"innodb-doublewrite-file", po::value<char *>(&innobase_doublewrite_file), _(
"Path to special datafile for doublewrite buffer. (default is "": not used)"))
4815 po::variables_map vm;
4817 int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
4818 po::store(po::command_line_parser(argc, argv).options(commandline_options).style(style).run(), vm);
4821 if (vm.count(
"target-dir"))
4822 xtrabackup_target_dir= vm[
"target-dir"].as<std::string>().c_str();
4824 if (vm.count(
"extra-lsndir"))
4825 xtrabackup_extra_lsndir= vm[
"extra-lsndir"].as<std::string>().c_str();
4827 if (vm.count(
"incremental-lsn"))
4828 xtrabackup_incremental= vm[
"incremental-lsn"].as<std::string>().c_str();
4830 if (vm.count(
"incremental-basedir"))
4831 xtrabackup_incremental_basedir= vm[
"incremental-basedir"].as<std::string>().c_str();
4833 boost::scoped_ptr<char> xtrabackup_tables_autoptr(
new char[(vm.count(
"tables")) ? vm[
"tables"].as<std::string>().length() + 1: 0]);
4834 if (vm.count(
"tables"))
4836 xtrabackup_tables= xtrabackup_tables_autoptr.get();
4837 strcpy(xtrabackup_tables, vm[
"tables"].as<std::string>().c_str());
4840 if (vm.count(
"tables-file"))
4841 xtrabackup_tables_file= vm[
"tables-file"].as<std::string>().c_str();
4843 if (vm.count(
"tmpdir"))
4844 opt_mysql_tmpdir= vm[
"tmpdir"].as<std::string>().c_str();
4846 if (vm.count(
"innodb-data-file-path"))
4847 innobase_data_file_path= vm[
"innodb-data-file-path"].as<std::string>().c_str();
4849 boost::scoped_ptr<char> xtrabackup_incremental_dir_autoptr(
new char[(vm.count(
"incremental-dir")) ? vm[
"incremental-dir"].as<std::string>().length() + 1: 0]);
4850 if (vm.count(
"incremental-dir"))
4852 xtrabackup_incremental_dir= xtrabackup_incremental_dir_autoptr.get();
4853 strcpy(xtrabackup_incremental_dir, vm[
"incremental-dir"].as<std::string>().c_str());
4856 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]);
4857 if (vm.count(
"innodb-data-home-dir"))
4859 innobase_data_home_dir= innobase_data_home_dir_autoptr.get();
4860 strcpy(innobase_data_home_dir, vm[
"innodb-data-home-dir"].as<std::string>().c_str());
4863 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]);
4864 if (vm.count(
"innodb-flush-method"))
4866 innobase_unix_file_flush_method= innobase_flush_method_autoptr.get();
4867 strcpy(innobase_unix_file_flush_method, vm[
"innodb-flush-method"].as<std::string>().c_str());
4870 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]);
4872 if (vm.count(
"innodb-log-group-home-dir"))
4874 innobase_log_group_home_dir= innobase_log_group_home_dir_autoptr.get();
4875 strcpy(innobase_log_group_home_dir, vm[
"innodb-log-group-home-dir"].as<std::string>().c_str());
4878 xtrabackup_use_memory-= xtrabackup_use_memory % (1024*1024);
4879 if (xtrabackup_use_memory < (1024*1024)) {
4880 fprintf(stderr,
"xtrabackup: use-memory out of range\n");
4885 fprintf(stderr,
"xtrabackup: parallel needs to be greater than 0\n");
4889 innobase_additional_mem_pool_size-= innobase_additional_mem_pool_size % 1024;
4890 if (innobase_additional_mem_pool_size < (512*1024)) {
4891 fprintf(stderr,
"xtrabackup: innodb-additional-mem-pool-size out of range\n");
4895 if ((srv_auto_extend_increment < 1) || (srv_auto_extend_increment > 8)) {
4896 fprintf(stderr,
"xtrabackup: innodb-auto-extend-increment out of range\n");
4900 innobase_buffer_pool_size-= innobase_buffer_pool_size % (1024*1024);
4901 if (innobase_buffer_pool_size < (1024*1024)) {
4902 fprintf(stderr,
"xtrabackup: innodb-buffer-pool-size out of range\n");
4906 if ((innobase_file_io_threads < 4) || (innobase_file_io_threads > 64)) {
4907 fprintf(stderr,
"xtrabackup: innodb-file-io-threads out of range\n");
4911 if (srv_flush_log_at_trx_commit > 2) {
4912 fprintf(stderr,
"xtrabackup: innodb-flush-log-at-trx-commit out of range\n");
4916 if (innobase_force_recovery > 6) {
4917 fprintf(stderr,
"xtrabackup: innodb-force-recovery out of range\n");
4921 if ((innobase_lock_wait_timeout < 1) || (innobase_lock_wait_timeout > (1024*1024*1024))) {
4922 fprintf(stderr,
"xtrabackup: innodb-lock-wait-timeout out of range\n");
4926 innobase_log_buffer_size-= innobase_log_buffer_size % 1024;
4927 if (innobase_additional_mem_pool_size < (256*1024)) {
4928 fprintf(stderr,
"xtrabackup: innodb-log-buffer-size out of range\n");
4932 if (innobase_additional_mem_pool_size < (1024*1024)) {
4933 fprintf(stderr,
"xtrabackup: innodb-log-file-size out of range\n");
4937 if ((innobase_log_files_in_group < 2) || (innobase_log_files_in_group > (100))) {
4938 fprintf(stderr,
"xtrabackup: innodb-log-files-in-group out of range\n");
4942 if (srv_max_buf_pool_modified_pct > 100) {
4943 fprintf(stderr,
"xtrabackup: innodb-max-buf-pool-modified-pct out of range\n");
4947 if (innobase_open_files < 10) {
4948 fprintf(stderr,
"xtrabackup: innodb-open-files out of range\n");
4952 if ((innobase_page_size < (1 << 12)) || (innobase_page_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4953 fprintf(stderr,
"xtrabackup: innodb-page-size out of range\n");
4957 if ((innobase_log_block_size < (512)) || (innobase_log_block_size > (1 << UNIV_PAGE_SIZE_SHIFT_MAX))) {
4958 fprintf(stderr,
"xtrabackup: innodb-log-block-size out of range\n");
4962 if (vm.count(
"datadir"))
4964 mysql_data_home_arg.assign(vm[
"datadir"].as<std::string>());
4968 mysql_data_home_arg.assign(LOCALSTATEDIR);
4971 mysql_data_home= (
char*)malloc(mysql_data_home_arg.length());
4972 strcpy(mysql_data_home, mysql_data_home_arg.c_str());
4974 if ((!xtrabackup_prepare) && (strcmp(mysql_data_home,
"./") == 0)) {
4975 if (!xtrabackup_print_param)
4977 printf(
"\nxtrabackup: Error: Please set parameter 'datadir'\n");
4981 if (xtrabackup_tables) {
4987 tables_regex_num = 1;
4989 p = xtrabackup_tables;
4990 while ((p = strchr(p,
',')) != NULL) {
4995 tables_regex = (regex_t*)
ut_malloc(
sizeof(regex_t) * tables_regex_num);
4997 p = xtrabackup_tables;
4998 for (i=0; i < tables_regex_num; i++) {
4999 next = strchr(p,
',');
5000 ut_a(next || i == tables_regex_num - 1);
5003 if (i != tables_regex_num - 1)
5006 regerror(regcomp(&tables_regex[i],p,REG_EXTENDED),
5007 &tables_regex[i],errbuf,
sizeof(errbuf));
5008 fprintf(stderr,
"xtrabackup: tables regcomp(%s): %s\n",p,errbuf);
5010 if (i != tables_regex_num - 1)
5016 if (xtrabackup_tables_file) {
5017 char name_buf[NAME_LEN*2+2];
5020 if (xtrabackup_stream) {
5021 fprintf(stderr,
"xtrabackup: Warning: --tables_file option doesn't affect with --stream.\n");
5022 xtrabackup_tables_file = NULL;
5023 goto skip_tables_file_register;
5026 name_buf[NAME_LEN*2+1] =
'\0';
5029 tables_hash = hash_create(1000);
5032 fp = fopen(xtrabackup_tables_file,
"r");
5034 fprintf(stderr,
"xtrabackup: cannot open %s\n", xtrabackup_tables_file);
5038 xtrabackup_tables_t* table;
5041 if ( fgets(name_buf, NAME_LEN*2+1, fp) == 0 ) {
5045 while (*p !=
'\0') {
5051 p = strchr(name_buf,
'\n');
5057 table = (xtrabackup_tables_t*) malloc(
sizeof(xtrabackup_tables_t) + strlen(name_buf) + 1);
5058 memset(table,
'\0',
sizeof(xtrabackup_tables_t) + strlen(name_buf) + 1);
5059 table->name = ((
char*)table) +
sizeof(xtrabackup_tables_t);
5060 strcpy(table->name, name_buf);
5062 HASH_INSERT(xtrabackup_tables_t, name_hash, tables_hash,
5065 printf(
"xtrabackup: table '%s' is registerd to the list.\n", table->name);
5068skip_tables_file_register:
5072 srv_page_size_shift = UNIV_PAGE_SIZE_SHIFT_MAX;
5073 srv_page_size = UNIV_PAGE_SIZE_MAX;
5074 srv_log_block_size = 512;
5076 if (xtrabackup_backup && xtrabackup_incremental) {
5083 incremental_lsn = strtoll(xtrabackup_incremental, &endchar, 10);
5084 if (*endchar !=
'\0')
5088 fprintf(stderr,
"xtrabackup: value '%s' may be wrong format for incremental option.\n",
5089 xtrabackup_incremental);
5094 incremental_buffer_base = (
byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5095 UNIV_PAGE_SIZE_MAX);
5096 incremental_buffer = (
byte*)
ut_align(incremental_buffer_base,
5097 UNIV_PAGE_SIZE_MAX);
5098 }
else if (xtrabackup_backup && xtrabackup_incremental_basedir) {
5099 char filename[FN_REFLEN];
5101 sprintf(filename,
"%s/%s", xtrabackup_incremental_basedir, XTRABACKUP_METADATA_FILENAME);
5103 if (xtrabackup_read_metadata(filename)) {
5105 "xtrabackup: error: failed to read metadata from %s\n",
5110 incremental_lsn = metadata_to_lsn;
5111 xtrabackup_incremental = xtrabackup_incremental_basedir;
5114 incremental_buffer_base = (
byte*) malloc((UNIV_PAGE_SIZE_MAX / 4 + 1) *
5115 UNIV_PAGE_SIZE_MAX);
5116 incremental_buffer = (
byte*)
ut_align(incremental_buffer_base,
5117 UNIV_PAGE_SIZE_MAX);
5118 }
else if (xtrabackup_prepare && xtrabackup_incremental_dir) {
5119 char filename[FN_REFLEN];
5121 sprintf(filename,
"%s/%s", xtrabackup_incremental_dir, XTRABACKUP_METADATA_FILENAME);
5123 if (xtrabackup_read_metadata(filename)) {
5125 "xtrabackup: error: failed to read metadata from %s\n",
5130 incremental_lsn = metadata_from_lsn;
5131 incremental_to_lsn = metadata_to_lsn;
5132 incremental_last_lsn = metadata_last_lsn;
5133 xtrabackup_incremental = xtrabackup_incremental_dir;
5136 incremental_buffer_base = (
byte*) malloc((UNIV_PAGE_SIZE / 4 + 1) *
5138 incremental_buffer = (
byte*)
ut_align(incremental_buffer_base,
5142 incremental_buffer_base = (
byte*) malloc((1 + 1) * UNIV_PAGE_SIZE_MAX);
5143 incremental_buffer = (
byte*)
ut_align(incremental_buffer_base,
5144 UNIV_PAGE_SIZE_MAX);
5146 xtrabackup_incremental = NULL;
5150 if (xtrabackup_print_param) {
5151 printf(
"# This MySQL options file was generated by XtraBackup.\n");
5152 printf(
"[mysqld]\n");
5153 printf(
"datadir = \"%s\"\n", mysql_data_home);
5154 printf(
"tmpdir = \"%s\"\n", opt_mysql_tmpdir);
5155 printf(
"innodb_data_home_dir = \"%s\"\n",
5156 innobase_data_home_dir ? innobase_data_home_dir : mysql_data_home);
5157 printf(
"innodb_data_file_path = \"%s\"\n",
5158 innobase_data_file_path ? innobase_data_file_path :
"ibdata1:10M:autoextend");
5159 printf(
"innodb_log_group_home_dir = \"%s\"\n",
5160 innobase_log_group_home_dir ? innobase_log_group_home_dir : mysql_data_home);
5161 printf(
"innodb_log_files_in_group = %ld\n", innobase_log_files_in_group);
5162 printf(
"innodb_log_file_size = %" PRIu64
"\n", (uint64_t)innobase_log_file_size);
5163 printf(
"innodb_flush_method = \"%s\"\n",
5164 (innobase_unix_file_flush_method != NULL) ?
5165 innobase_unix_file_flush_method :
"");
5169 if (!xtrabackup_stream) {
5171 if (xtrabackup_incremental) {
5172 printf(
"incremental backup from %" PRIu64
" is enabled.\n",
5176 if (xtrabackup_backup) {
5177 xtrabackup_suspend_at_end = TRUE;
5178 fprintf(stderr,
"xtrabackup: suspend-at-end is enabled.\n");
5186 if (xtrabackup_backup) num++;
5187 if (xtrabackup_stats) num++;
5188 if (xtrabackup_prepare) num++;
5196 if (xtrabackup_backup)
5197 xtrabackup_backup_func();
5200 if (xtrabackup_stats)
5201 xtrabackup_stats_func();
5204 if (xtrabackup_prepare)
5205 xtrabackup_prepare_func();
5207 free(incremental_buffer_base);
5209 if (xtrabackup_tables) {
5213 for (i = 0; i < tables_regex_num; i++) {
5214 regfree(&tables_regex[i]);
5219 if (xtrabackup_tables_file) {
5224 xtrabackup_tables_t* table;
5226 table = (xtrabackup_tables_t*)
5230 xtrabackup_tables_t* prev_table = table;
5232 table = (xtrabackup_tables_t*)
5235 HASH_DELETE(xtrabackup_tables_t, name_hash, tables_hash,
5242 hash_table_free(tables_hash);
#define btr_block_get(space, zip_size, page_no, mode, mtr)
UNIV_INLINE ulint btr_page_get_level(const page_t *page, mtr_t *mtr)
UNIV_INLINE ulint btr_page_get_next(const page_t *page, mtr_t *mtr)
#define BTR_EXTERN_SPACE_ID
#define BTR_EXTERN_PAGE_NO
#define BTR_EXTERN_OFFSET
UNIV_INLINE ibool btr_pcur_move_to_next_user_rec(btr_pcur_t *cursor, mtr_t *mtr)
UNIV_INLINE ibool btr_pcur_is_on_user_rec(const btr_pcur_t *cursor)
UNIV_INLINE void btr_pcur_open_at_index_side(ibool from_left, dict_index_t *index, ulint latch_mode, btr_pcur_t *pcur, ibool do_init, mtr_t *mtr)
UNIV_INLINE void btr_pcur_close(btr_pcur_t *cursor)
#define BTR_EXTERN_FIELD_REF_SIZE
struct btr_pcur_struct btr_pcur_t
UNIV_INLINE ulint buf_block_get_space(const buf_block_t *block) __attribute__((pure))
#define buf_page_get(SP, ZS, OF, LA, MTR)
struct buf_block_struct buf_block_t
UNIV_INLINE ulint dict_table_flags_to_zip_size(ulint flags) __attribute__((const))
UNIV_INLINE dict_table_t * dict_table_get_low(const char *table_name)
#define DICT_TF_FORMAT_51
UNIV_INTERN ulint fil_load_single_table_tablespaces(void)
UNIV_INTERN void fsp_init(void)
UNIV_INTERN void thd_set_lock_wait_time(drizzled::Session *in_session, ulint value)
UNIV_INTERN void innobase_casedn_str(char *a)
UNIV_INTERN ulong thd_lock_wait_timeout(drizzled::Session *)
ulint innobase_get_at_most_n_mbchars(ulint charset_id, ulint prefix_len, ulint data_len, const char *str)
UNIV_INTERN ibool thd_has_edited_nontrans_tables(drizzled::Session *session)
UNIV_INTERN int innobase_mysql_cmp(int mysql_type, uint charset_number, const unsigned char *a, unsigned int a_length, const unsigned char *b, unsigned int b_length)
UNIV_INTERN ibool trx_is_interrupted(trx_t *trx)
UNIV_INTERN void innobase_convert_from_table_id(const void *, char *to, const char *from, ulint len)
UNIV_INTERN char * innobase_convert_name(char *buf, ulint buflen, const char *id, ulint idlen, drizzled::Session *session, ibool table_id)
UNIV_INTERN ibool thd_is_select(const drizzled::Session *session)
UNIV_INTERN void innobase_get_cset_width(ulint cset, ulint *mbminlen, ulint *mbmaxlen)
UNIV_INTERN ibool trx_is_strict(trx_t *trx)
UNIV_INTERN void innobase_mysql_print_thd(FILE *f, drizzled::Session *in_session, uint)
UNIV_INTERN int innobase_mysql_tmpfile(void)
UNIV_INTERN ibool thd_is_replication_slave_thread(drizzled::Session *)
static char * innobase_convert_identifier(char *buf, ulint buflen, const char *id, ulint idlen, drizzled::Session *session, ibool file_id)
UNIV_INTERN void innobase_convert_from_id(const void *, char *to, const char *from, ulint len)
UNIV_INTERN int innobase_strcasecmp(const char *a, const char *b)
UNIV_INTERN ulint innobase_raw_format(const char *data, ulint data_len, ulint, char *buf, ulint buf_size)
UNIV_INTERN ibool thd_supports_xa(drizzled::Session *)
const char * innobase_basename(const char *path_name)
UNIV_INTERN void innobase_invalidate_query_cache(trx_t *trx, const char *full_name, ulint full_name_len)
UNIV_INTERN const char * innobase_get_stmt(drizzled::Session *mysql_thd, size_t *length) __attribute__((nonnull))
UNIV_INTERN void innobase_rec_to_mysql(Table *table, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
UNIV_INTERN void innobase_rec_reset(Table *table)
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)
UNIV_INLINE ulint hash_get_n_cells(hash_table_t *table)
#define HASH_SEARCH(NAME, TABLE, FOLD, TYPE, DATA, ASSERTION, TEST)
#define HASH_GET_NEXT(NAME, DATA)
#define HASH_DELETE(TYPE, NAME, TABLE, FOLD, DATA)
#define HASH_GET_FIRST(TABLE, HASH_VAL)
UNIV_INTERN void lock_sys_create(ulint n_cells)
UNIV_INTERN void log_group_read_checkpoint_info(log_group_t *group, ulint field)
UNIV_INLINE ulint log_block_get_checkpoint_no(const byte *log_block)
UNIV_INLINE ulint log_block_get_data_len(const byte *log_block)
UNIV_INTERN ulint log_group_get_capacity(const log_group_t *group)
UNIV_INLINE ulint log_block_get_hdr_no(const byte *log_block)
UNIV_INLINE ulint log_block_convert_lsn_to_no(ib_uint64_t lsn)
UNIV_INLINE ulint log_block_calc_checksum(const byte *block)
UNIV_INLINE ibool log_block_get_flush_bit(const byte *log_block)
UNIV_INLINE ulint log_block_get_checksum(const byte *log_block)
UNIV_INTERN void log_group_read_log_seg(ulint type, byte *buf, log_group_t *group, ib_uint64_t start_lsn, ib_uint64_t end_lsn)
struct log_group_struct log_group_t
UNIV_INTERN void log_init(void)
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
#define mem_heap_create(N)
UNIV_INLINE void mem_heap_empty(mem_heap_t *heap)
UNIV_INLINE char * mem_strdupl(const char *str, ulint len)
#define mem_heap_free(heap)
UNIV_INTERN ulint mtr_read_ulint(const byte *ptr, ulint type, mtr_t *mtr)
UNIV_INTERN void mtr_commit(mtr_t *mtr) __attribute__((nonnull))
#define mtr_s_lock(B, MTR)
#define mtr_x_lock(B, MTR)
UNIV_INLINE void mtr_start(mtr_t *mtr) __attribute__((nonnull))
Convert from decimal to binary representation.
TODO: Rename this file - func.h is stupid.
UNIV_INTERN ibool os_file_status(const char *path, ibool *exists, os_file_type_t *type)
UNIV_INTERN ulint os_file_get_last_error(ibool report_all_errors)
UNIV_INTERN int os_file_closedir(os_file_dir_t dir)
struct fil_node_struct fil_node_t
UNIV_INTERN void os_file_set_nocache(int fd, const char *file_name, const char *operation_name)
#define OS_FILE_LOG_BLOCK_SIZE
UNIV_INTERN void os_io_init_simple(void)
UNIV_INTERN ib_int64_t os_file_get_size_as_iblonglong(os_file_t file)
UNIV_INTERN os_file_dir_t os_file_opendir(const char *dirname, ibool error_is_fatal)
UNIV_INTERN ib_int64_t os_event_reset(os_event_t event)
UNIV_INTERN void os_mutex_enter(os_mutex_t mutex)
UNIV_INTERN os_event_t os_event_create(const char *name)
UNIV_INTERN void os_sync_free(void)
UNIV_INTERN void os_event_set(os_event_t event)
UNIV_INTERN void os_event_free(os_event_t event)
os_event_struct_t * os_event_t
os_mutex_str_t * os_mutex_t
UNIV_INTERN void os_mutex_exit(os_mutex_t mutex)
UNIV_INTERN void os_sync_init(void)
UNIV_INTERN void os_mutex_free(os_mutex_t mutex)
os_thread_t os_thread_id_t
UNIV_INTERN os_thread_t os_thread_create(os_posix_f_t start_f, void *arg, os_thread_id_t *thread_id)
UNIV_INTERN void os_thread_exit(void *exit_value)
UNIV_INTERN void os_thread_sleep(ulint tm)
UNIV_INLINE void page_cur_move_to_next(page_cur_t *cur)
UNIV_INLINE void page_cur_set_before_first(const buf_block_t *block, page_cur_t *cur)
UNIV_INLINE ibool page_cur_is_after_last(const page_cur_t *cur)
UNIV_INLINE ulint page_get_n_recs(const page_t *page)
UNIV_INLINE ulint page_get_space_id(const page_t *page)
UNIV_INLINE ibool page_is_leaf(const page_t *page) __attribute__((nonnull
UNIV_INLINE ulint page_get_data_size(const page_t *page)
struct page_cur_struct page_cur_t
UNIV_INLINE ulint rec_offs_n_fields(const ulint *offsets)
UNIV_INLINE ulint rec_offs_nth_extern(const ulint *offsets, ulint n)
UNIV_INLINE ulint rec_get_deleted_flag(const rec_t *rec, ulint comp)
ibool row_rollback_on_timeout
UNIV_INTERN void srv_general_init(void)
ibool srv_locks_unsafe_for_binlog
my_bool srv_file_per_table
ulint srv_max_file_format_at_startup
UNIV_INTERN void srv_normalize_path_for_win(char *str)
UNIV_INTERN int innobase_shutdown_for_mysql(void)
UNIV_INTERN ibool srv_parse_data_file_paths_and_sizes(char *str)
ib_uint64_t srv_start_lsn
UNIV_INTERN int innobase_start_or_create_for_mysql(void)
UNIV_INTERN ibool srv_parse_log_group_home_dirs(char *str)
UT_LIST_NODE_T(fil_node_t) LRU
UT_LIST_NODE_T(fil_node_t) chain
ib_int64_t modification_counter
ib_int64_t tablespace_version
UT_LIST_BASE_NODE_T(fil_node_t) chain
UT_LIST_NODE_T(fil_space_t) space_list
ulint n_pending_ibuf_merges
ibool is_in_unflushed_spaces
UT_LIST_NODE_T(fil_space_t) unflushed_spaces
UT_LIST_BASE_NODE_T(fil_space_t) space_list
ib_int64_t modification_counter
UT_LIST_BASE_NODE_T(fil_space_t) unflushed_spaces
ib_int64_t tablespace_version
UT_LIST_BASE_NODE_T(fil_node_t) LRU
char name[OS_FILE_MAX_PATH]
UNIV_INTERN void sync_close(void)
UNIV_INTERN void sync_init(void)
UNIV_INLINE void * ut_align(const void *ptr, ulint align_no)
#define UT_LIST_GET_LEN(BASE)
#define UT_LIST_GET_FIRST(BASE)
#define UT_LIST_GET_NEXT(NAME, N)
UNIV_INLINE int ut_strcmp(const char *str1, const char *str2)
UNIV_INLINE int ut_memcmp(const void *str1, const void *str2, ulint n)
UNIV_INTERN void ut_mem_init(void)
UNIV_INTERN void ut_free(void *ptr)
UNIV_INTERN void ut_free_all_mem(void)
UNIV_INTERN void * ut_malloc(ulint n)
UNIV_INLINE ulint ut_fold_string(const char *str) __attribute__((pure))
UNIV_INLINE ulint ut_fold_binary(const byte *str, ulint len) __attribute__((pure))
#define TEMP_INDEX_PREFIX
UNIV_INTERN void ut_print_timestamp(FILE *file)
UNIV_INTERN void ut_sprintf_timestamp(char *buf)
UNIV_INTERN void ut_print_namel(FILE *f, struct trx_struct *trx, ibool table_id, const char *name, ulint namelen)