1017
1030
{"throttle", OPT_XTRA_THROTTLE, "limit count of IO operations (pairs of read&write) per second to IOS values (for '--backup')",
1018
1031
(G_PTR*) &xtrabackup_throttle, (G_PTR*) &xtrabackup_throttle,
1019
1032
0, GET_LONG, REQUIRED_ARG, 0, 0, LONG_MAX, 0, 1, 0},
1020
{"log-stream", OPT_XTRA_STREAM, "outputs the contents of 'xtrabackup_logfile' to stdout only until the file 'xtrabackup_suspended' deleted (for '--backup').",
1021
(G_PTR*) &xtrabackup_stream, (G_PTR*) &xtrabackup_stream,
1033
{"log-stream", OPT_XTRA_LOG_ONLY, "outputs the contents of 'xtrabackup_logfile' to stdout only until the file 'xtrabackup_suspended' deleted (for '--backup').",
1034
(G_PTR*) &xtrabackup_log_only, (G_PTR*) &xtrabackup_log_only,
1022
1035
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1023
1036
{"extra-lsndir", OPT_XTRA_EXTRA_LSNDIR, "(for --backup): save an extra copy of the xtrabackup_checkpoints file in this directory.",
1024
1037
(G_PTR*) &xtrabackup_extra_lsndir, (G_PTR*) &xtrabackup_extra_lsndir,
1057
1070
{"parallel", OPT_XTRA_PARALLEL,
1058
1071
"Number of threads to use for parallel datafiles transfer. Does not have "
1059
1072
"any effect in the stream mode. The default value is 1.",
1060
(G_PTR*) ¶llel, (G_PTR*) ¶llel, 0, GET_INT, REQUIRED_ARG,
1061
1, 1, INT_MAX, 0, 0, 0},
1073
(G_PTR*) &xtrabackup_parallel, (G_PTR*) &xtrabackup_parallel, 0, GET_INT,
1074
REQUIRED_ARG, 1, 1, INT_MAX, 0, 0, 0},
1076
{"stream", OPT_XTRA_STREAM, "Stream all backup files to the standard output "
1077
"in the specified format. Currently the only supported format is 'tar'.",
1078
(G_PTR*) &xtrabackup_stream_str, (G_PTR*) &xtrabackup_stream_str, 0, GET_STR,
1079
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1081
{"compress", OPT_XTRA_COMPRESS, "Compress individual backup files using the "
1082
"specified compression algorithm. Currently the only supported algorithm "
1083
"is 'quicklz'. It is also the default algorithm, i.e. the one used when "
1084
"--compress is used without an argument.",
1085
(G_PTR*) &xtrabackup_compress_alg, (G_PTR*) &xtrabackup_compress_alg, 0,
1086
GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1088
{"compress-threads", OPT_XTRA_COMPRESS_THREADS,
1089
"Number of threads for parallel data compression. The default value is 1.",
1090
(G_PTR*) &xtrabackup_compress_threads, (G_PTR*) &xtrabackup_compress_threads,
1091
0, GET_UINT, REQUIRED_ARG, 1, 1, UINT_MAX, 0, 0, 0},
1063
1093
{"innodb_adaptive_hash_index", OPT_INNODB_ADAPTIVE_HASH_INDEX,
1064
1094
"Enable InnoDB adaptive hash index (enabled by default). "
1572
fprintf(stderr, "xtrabackup: Got error %d on dup\n",fd2);
1623
msg("xtrabackup: Got error %d on dup\n",fd2);
1574
1625
my_close(fd, MYF(MY_WME));
1630
/***********************************************************************
1631
Creates a temporary file in tmpdir with a specified prefix in the file
1632
name. The file will be automatically removed on close.
1633
Unlike innobase_mysql_tmpfile(), dup() is not used, so the returned
1634
file must be closed with my_close().
1635
@return file descriptor or a negative number in case of error.*/
1637
xtrabackup_create_tmpfile(char *path, const char *prefix)
1639
File fd = create_temp_file(path, my_tmpdir(&mysql_tmpdir_list),
1642
O_BINARY | O_TRUNC | O_SEQUENTIAL |
1643
O_TEMPORARY | O_SHORT_LIVED |
1644
#endif /* __WIN__ */
1645
O_CREAT | O_EXCL | O_RDWR,
1649
/* On Windows, open files cannot be removed, but files can be
1650
created with the O_TEMPORARY flag to the same effect
1651
("delete on close"). */
1654
#endif /* !__WIN__ */
1580
1660
innobase_invalidate_query_cache(
2496
fprintf(stderr, "xtrabackup: innodb_end(): Error occured.\n");
2567
msg("xtrabackup: innodb_end(): Error occured.\n");
2500
2571
/* ================= common ================= */
2573
/***********************************************************************
2574
Read backup meta info.
2575
@return TRUE on success, FALSE on failure. */
2502
2578
xtrabackup_read_metadata(char *filename)
2507
2583
fp = fopen(filename,"r");
2509
fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filename);
2585
msg("xtrabackup: Error: cannot open %s\n", filename);
2513
2589
if (fscanf(fp, "backup_type = %29s\n", metadata_type)
2518
2594
#ifndef INNODB_VERSION_SHORT
2519
2595
if (fscanf(fp, "from_lsn = %lu:%lu\n", &metadata_from_lsn.high, &metadata_from_lsn.low)
2524
2600
if (fscanf(fp, "to_lsn = %lu:%lu\n", &metadata_to_lsn.high, &metadata_to_lsn.low)
2529
2605
if (fscanf(fp, "last_lsn = %lu:%lu\n", &metadata_last_lsn.high, &metadata_last_lsn.low)
2557
xtrabackup_write_metadata(char *filename)
2632
/***********************************************************************
2633
Print backup meta info to a specified buffer. */
2636
xtrabackup_print_metadata(char *buf, size_t buf_len)
2562
fp = fopen(filename,"w");
2564
fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filename);
2568
if (fprintf(fp, "backup_type = %s\n", metadata_type)
2573
2638
#ifndef INNODB_VERSION_SHORT
2574
if (fprintf(fp, "from_lsn = %lu:%lu\n", metadata_from_lsn.high, metadata_from_lsn.low)
2579
if (fprintf(fp, "to_lsn = %lu:%lu\n", metadata_to_lsn.high, metadata_to_lsn.low)
2584
if (fprintf(fp, "last_lsn = %lu:%lu\n", metadata_last_lsn.high, metadata_last_lsn.low)
2639
snprintf(buf, buf_len,
2640
"backup_type = %s\n"
2641
"from_lsn = %lu:%lu\n"
2642
"to_lsn = %lu:%lu\n"
2643
"last_lsn = %lu:%lu\n",
2645
metadata_from_lsn.high, metadata_from_lsn.low,
2646
metadata_to_lsn.high, metadata_to_lsn.low,
2647
metadata_last_lsn.high, metadata_last_lsn.low);
2590
if (fprintf(fp, "from_lsn = %llu\n", metadata_from_lsn)
2595
if (fprintf(fp, "to_lsn = %llu\n", metadata_to_lsn)
2600
if (fprintf(fp, "last_lsn = %llu\n", metadata_last_lsn)
2649
snprintf(buf, buf_len,
2650
"backup_type = %s\n"
2653
"last_lsn = %llu\n",
2661
/***********************************************************************
2662
Stream backup meta info to a specified datasink.
2663
@return TRUE on success, FALSE on failure. */
2666
xtrabackup_stream_metadata(ds_ctxt_t *ds_ctxt)
2670
datasink_t *ds = ds_ctxt->datasink;
2674
xtrabackup_print_metadata(buf, sizeof(buf));
2678
mystat.st_size = len;
2679
mystat.st_mtime = my_time(0);
2681
stream = ds->open(ds_ctxt, XTRABACKUP_METADATA_FILENAME,
2683
if (stream == NULL) {
2684
msg("xtrabackup: Error: cannot open output stream "
2685
"for %s\n", XTRABACKUP_METADATA_FILENAME);
2689
if (ds->write(stream, buf, len)) {
2699
/***********************************************************************
2700
Write backup meta info to a specified file.
2701
@return TRUE on success, FALSE on failure. */
2704
xtrabackup_write_metadata(const char *filepath)
2710
xtrabackup_print_metadata(buf, sizeof(buf));
2714
fp = fopen(filepath, "w");
2716
msg("xtrabackup: Error: cannot open %s\n", filepath);
2719
if (fwrite(buf, len, 1, fp) < 1) {
2612
2729
/***********************************************************************
2637
2754
/***********************************************************************
2638
2755
Write meta info for an incremental delta.
2639
2756
@return TRUE on success, FALSE on failure. */
2641
xb_write_delta_metadata(const char *filepath, const xb_delta_info_t *info)
2759
xb_write_delta_metadata(ds_ctxt_t *ds_ctxt, const char *filename,
2760
const xb_delta_info_t *info)
2646
fp = fopen(filepath, "w");
2648
fprintf(stderr, "xtrabackup: Error: cannot open %s\n", filepath);
2762
datasink_t *ds = ds_ctxt->datasink;
2769
snprintf(buf, sizeof(buf), "page_size = %lu\n", info->page_size);
2772
mystat.st_size = len;
2773
mystat.st_mtime = my_time(0);
2775
f = ds->open(ds_ctxt, filename, &mystat);
2777
msg("xtrabackup: Error: cannot open output stream for %s\n",
2652
if (fprintf(fp, "page_size = %lu\n", info->page_size) < 0)
2782
ret = ds->write(f, buf, len) == 0;
2660
2789
/* ================= backup ================= */
2993
3125
posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
2997
/* xb_file_create reads srv_unix_file_flush_method */
2998
dst_file = xb_file_create(dst_path, OS_FILE_CREATE,
2999
OS_FILE_NORMAL, OS_DATA_FILE, &success);
3001
/* The following call prints an error message */
3002
os_file_get_last_error(TRUE);
3004
fprintf(stderr,"[%02u] xtrabackup: error: "
3005
"cannot open %s\n", thread_n, dst_path);
3128
if (my_stat(node->name, &src_stat, MYF(MY_WME)) == NULL) {
3129
msg("[%02u] xtrabackup: Warning: cannot stat %s\n",
3130
thread_n, node->name);
3133
dstfile = ds->open(ds_ctxt, dst_name, &src_stat);
3134
if (dstfile == NULL) {
3135
msg("[%02u] xtrabackup: error: "
3136
"cannot open the destination stream for %s\n",
3137
thread_n, dst_name);
3009
#ifdef USE_POSIX_FADVISE
3010
posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
3141
if (xtrabackup_stream) {
3142
const char *action = xtrabackup_compress ?
3143
"Compressing and streaming" : "Streaming";
3144
msg("[%02u] %s %s\n", thread_n, action, node->name);
3013
/* copy : TODO: tune later */
3014
printf("[%02u] Copying %s \n to %s\n", thread_n,
3015
node->name, dst_path);
3148
if (xtrabackup_compress) {
3149
action = "Compressing";
3153
msg("[%02u] %s %s to %s\n", thread_n, action,
3154
node->name, dstfile->path);
3017
3157
buf2 = ut_malloc(COPY_CHUNK * page_size + UNIV_PAGE_SIZE);
3018
3158
page = ut_align(buf2, UNIV_PAGE_SIZE);
3160
3291
mach_write_to_4(incremental_buffer, 0x58545241UL);/*"XTRA"*/
3162
3293
/* flush buffer */
3163
success = os_file_write(dst_path, dst_file, incremental_buffer,
3164
((incremental_buffers * (page_size/4))
3165
<< page_size_shift) & 0xFFFFFFFFUL,
3166
(incremental_buffers * (page_size/4))
3167
>> (32 - page_size_shift),
3168
page_in_buffer * page_size);
3172
if (!xb_write_delta_metadata(meta_path, &info)) {
3173
fprintf(stderr, "[%02u] xtrabackup: Error: "
3174
"failed to write meta info for %s\n",
3175
thread_n, dst_path);
3180
success = xb_file_flush(dst_file);
3186
/* check size again */
3187
/* TODO: but is it needed ?? */
3188
// if (file_size < os_file_get_size_as_iblonglong(src_file)) {
3189
// offset -= COPY_CHUNK * page_size;
3190
// file_size = os_file_get_size_as_iblonglong(src_file);
3294
if (ds->write(dstfile, incremental_buffer,
3295
page_in_buffer * page_size)) {
3298
if (!xb_write_delta_metadata(ds_ctxt, meta_name, &info)) {
3299
msg("[%02u] xtrabackup: Error: "
3300
"failed to write meta info for %s\n",
3301
thread_n, dst_name);
3194
3306
/* TODO: How should we treat double_write_buffer here? */
3195
3307
/* (currently, don't care about. Because,
3196
3308
the blocks is newer than the last checkpoint anyway.) */
3199
printf("[%02u] ...done\n", thread_n);
3311
msg("[%02u] ...done\n", thread_n);
3200
3312
if (!node->open) {
3201
3313
os_file_close(src_file);
3203
os_file_close(dst_file);
3204
3316
if (incremental_buffer_base)
3205
3317
ut_free(incremental_buffer_base);
3209
3321
if (src_file != XB_FILE_UNDEFINED && !node->open)
3210
3322
os_file_close(src_file);
3211
if (dst_file != XB_FILE_UNDEFINED)
3212
os_file_close(dst_file);
3323
if (dstfile != NULL)
3213
3325
if (incremental_buffer_base)
3214
3326
ut_free(incremental_buffer_base);
3217
fprintf(stderr, "[%02u] xtrabackup: Error: "
3218
"xtrabackup_copy_datafile() failed.\n", thread_n);
3329
msg("[%02u] xtrabackup: Error: "
3330
"xtrabackup_copy_datafile() failed.\n", thread_n);
3219
3331
return(TRUE); /*ERROR*/
3222
3334
if (src_file != XB_FILE_UNDEFINED && !node->open)
3223
3335
os_file_close(src_file);
3224
if (dst_file != XB_FILE_UNDEFINED)
3225
os_file_close(dst_file);
3336
if (dstfile != NULL)
3226
3338
if (incremental_buffer_base)
3227
3339
ut_free(incremental_buffer_base);
3230
fprintf(stderr, "[%02u] xtrabackup: Warning: skipping file %s.\n",
3231
thread_n, node->name);
3342
msg("[%02u] xtrabackup: Warning: We assume the "
3343
"table was dropped during xtrabackup execution "
3344
"and ignore the file.\n", thread_n);
3345
msg("[%02u] xtrabackup: Warning: skipping file %s.\n",
3346
thread_n, node->name);
3317
"xtrabackup: error:"
3318
" log block numbers mismatch:\n"
3319
"xtrabackup: error: expected log block no. %lu,"
3320
" but got no. %lu from the log file.\n",
3321
(ulong) scanned_no, (ulong) no);
3426
msg("xtrabackup: error:"
3427
" log block numbers mismatch:\n"
3428
"xtrabackup: error: expected log block no. %lu,"
3429
" but got no. %lu from the log file.\n",
3430
(ulong) scanned_no, (ulong) no);
3323
3432
if ((no - scanned_no) % blocks_in_group == 0) {
3325
"xtrabackup: error:"
3326
" it looks like InnoDB log has wrapped"
3327
" around before xtrabackup could"
3328
" process all records due to either"
3329
" log copying being too slow, or "
3330
" log files being too small.\n");
3433
msg("xtrabackup: error:"
3434
" it looks like InnoDB log has wrapped"
3435
" around before xtrabackup could"
3436
" process all records due to either"
3437
" log copying being too slow, or "
3438
" log files being too small.\n");
3334
3442
} else if (!checksum_is_ok) {
3335
3443
/* Garbage or an incompletely written log block */
3338
"xtrabackup: error:"
3339
" Log block checksum mismatch"
3445
msg("xtrabackup: error: Log block checksum mismatch"
3340
3446
#ifndef INNODB_VERSION_SHORT
3341
" (block no %lu at lsn %lu %lu): \n"
3447
" (block no %lu at lsn %lu %lu): \n"
3343
" (block no %lu at lsn %llu): \n"
3449
" (block no %lu at lsn %llu): \n"
3345
"expected %lu, calculated checksum %lu\n",
3451
"expected %lu, calculated checksum %lu\n",
3347
3453
#ifndef INNODB_VERSION_SHORT
3348
3454
(ulong) ut_dulint_get_high(scanned_lsn),
3414
3521
write_size = (ulint) ut_dulint_minus(
3415
3522
ut_dulint_align_up(group_scanned_lsn, OS_FILE_LOG_BLOCK_SIZE),
3419
//printf("Wrinting offset= %lld, size= %lu\n", log_copy_offset, write_size);
3421
if (!xtrabackup_stream) {
3422
success = os_file_write(dst_log_path, dst_log, log_sys->buf,
3423
(ulint)(log_copy_offset & 0xFFFFFFFFUL),
3424
(ulint)(log_copy_offset >> 32), write_size);
3427
ulint stdout_write_size = write_size;
3428
if (finished && !is_last
3429
#ifndef INNODB_VERSION_SHORT
3430
&& group_scanned_lsn.low % OS_FILE_LOG_BLOCK_SIZE
3432
&& group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE
3435
stdout_write_size -= OS_FILE_LOG_BLOCK_SIZE;
3436
if (stdout_write_size) {
3437
ret = fwrite(log_sys->buf, 1, stdout_write_size, stdout);
3438
if (ret == stdout_write_size) {
3441
fprintf(stderr, "write: %lu > %lu\n", stdout_write_size, ret);
3445
success = TRUE; /* do nothing */
3449
log_copy_offset += write_size;
3451
#ifndef INNODB_VERSION_SHORT
3452
if (finished && group_scanned_lsn.low % OS_FILE_LOG_BLOCK_SIZE)
3454
if (finished && group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE)
3457
/* if continue, it will start from align_down(group_scanned_lsn) */
3458
log_copy_offset -= OS_FILE_LOG_BLOCK_SIZE;
3462
if (!xtrabackup_stream) {
3463
fprintf(stderr, "xtrabackup: Error: os_file_write to %s\n", dst_log_path);
3465
fprintf(stderr, "xtrabackup: Error: write to stdout\n");
3525
#ifndef INNODB_VERSION_SHORT
3526
group_scanned_lsn.low % OS_FILE_LOG_BLOCK_SIZE
3528
group_scanned_lsn % OS_FILE_LOG_BLOCK_SIZE
3531
write_size -= OS_FILE_LOG_BLOCK_SIZE;
3535
rc = my_write(dst_log_fd, log_sys->buf, write_size,
3536
MYF(MY_WME | MY_NABP));
3539
msg("xtrabackup: Error: write to logfile failed\n");
3716
3771
OS_THREAD_DUMMY_RETURN;
3774
/***********************************************************************
3775
Stream the transaction log from a temporary file a specified datasink.
3776
@return FALSE on succees, TRUE on error. */
3779
xtrabackup_stream_temp_logfile(File src_file, ds_ctxt_t *ds_ctxt)
3781
datasink_t *ds = ds_ctxt->datasink;
3783
const size_t buf_size = 1024 * 1024;
3785
ds_file_t *dst_file = NULL;
3788
msg("xtrabackup: Streaming transaction log from a temporary file...\n");
3790
#ifdef USE_POSIX_FADVISE
3791
posix_fadvise(src_file, 0, 0, POSIX_FADV_SEQUENTIAL);
3792
posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
3795
if (my_seek(src_file, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR) {
3796
msg("xtrabackup: error: my_seek() failed, errno = %d.\n",
3801
if (my_fstat(src_file, &mystat, MYF(0))) {
3802
msg("xtrabackup: error: my_fstat() failed.\n");
3806
dst_file = ds->open(ds_ctxt, XB_LOG_FILENAME, &mystat);
3807
if (dst_file == NULL) {
3808
msg("xtrabackup: error: cannot open the destination stream "
3809
"for %s.\n", XB_LOG_FILENAME);
3813
buf = (uchar *) ut_malloc(buf_size);
3815
while ((bytes = my_read(src_file, buf, buf_size, MYF(MY_WME))) > 0) {
3816
if (ds->write(dst_file, buf, bytes)) {
3817
msg("xtrabackup: error: cannot write to stream "
3818
"for %s.\n", XB_LOG_FILENAME);
3822
if (bytes == (size_t) -1) {
3827
ds->close(dst_file);
3828
my_close(src_file, MYF(MY_WME));
3830
msg("xtrabackup: Done.\n");
3838
ds->close(dst_file);;
3840
my_close(src_file, MYF(MY_WME));
3841
msg("xtrabackup: Failed.\n");
3720
3846
xtrabackup_backup_func(void)
3722
3848
MY_STAT stat_info;
3723
3849
LSN64 latest_cp;
3850
char logfile_temp_path[FN_REFLEN];
3852
ds_ctxt_t *ds_ctxt = NULL;
3725
3854
#ifdef USE_POSIX_FADVISE
3726
fprintf(stderr, "xtrabackup: uses posix_fadvise().\n");
3855
msg("xtrabackup: uses posix_fadvise().\n");
3729
3858
/* cd to datadir */
3731
3860
if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
3733
fprintf(stderr, "xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3862
msg("xtrabackup: cannot my_setwd %s\n", mysql_real_data_home);
3734
3863
exit(EXIT_FAILURE);
3736
fprintf(stderr, "xtrabackup: cd to %s\n", mysql_real_data_home);
3865
msg("xtrabackup: cd to %s\n", mysql_real_data_home);
3738
3867
mysql_data_home= mysql_data_home_buff;
3739
3868
mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
3985
4113
if (xtrabackup_extra_lsndir
3986
4114
&&!my_stat(xtrabackup_extra_lsndir,&stat_info,MYF(0))
3987
4115
&& (my_mkdir(xtrabackup_extra_lsndir,0777,MYF(0)) < 0)){
3988
fprintf(stderr,"xtrabackup: Error: cannot mkdir %d: %s\n",my_errno,xtrabackup_extra_lsndir);
4116
msg("xtrabackup: Error: cannot mkdir %d: %s\n",
4117
my_errno, xtrabackup_extra_lsndir);
3989
4118
exit(EXIT_FAILURE);
3993
if (!xtrabackup_stream) {
4122
if (!xtrabackup_log_only) {
3995
4124
/* create target dir if not exist */
3996
4125
if (!my_stat(xtrabackup_target_dir,&stat_info,MYF(0))
3997
4126
&& (my_mkdir(xtrabackup_target_dir,0777,MYF(0)) < 0)){
3998
fprintf(stderr,"xtrabackup: Error: cannot mkdir %d: %s\n",my_errno,xtrabackup_target_dir);
4127
msg("xtrabackup: Error: cannot mkdir %d: %s\n",
4128
my_errno, xtrabackup_target_dir);
3999
4129
exit(EXIT_FAILURE);
4003
fprintf(stderr,"xtrabackup: Stream mode.\n");
4004
/* stdout can treat binary at Linux */
4005
//setmode(fileno(stdout), O_BINARY);
4133
msg("xtrabackup: Log only mode.\n");
4081
4202
mutex_exit(&log_sys->mutex);
4083
if (!xtrabackup_stream) {
4085
/* open 'xtrabackup_logfile' */
4086
sprintf(dst_log_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
4087
srv_normalize_path_for_win(dst_log_path);
4088
/* xb_file_create reads srv_unix_file_flush_method for
4090
dst_log = xb_file_create(dst_log_path, OS_FILE_CREATE,
4091
OS_FILE_NORMAL, OS_DATA_FILE,
4095
/* The following call prints an error message */
4096
os_file_get_last_error(TRUE);
4099
"xtrabackup: error: cannot open %s\n",
4204
/* open the log file */
4205
if (!xtrabackup_log_only) {
4206
/* The xbstream format allows concurrent files streaming */
4207
if (xtrabackup_stream) {
4208
dst_log_fd = xtrabackup_create_tmpfile(
4209
logfile_temp_path, XB_LOG_FILENAME);
4210
if (dst_log_fd < 0) {
4211
msg("xtrabackup: error: "
4212
"xtrabackup_create_tmpfile() failed. "
4213
"(errno: %d)\n", my_errno);
4217
fn_format(dst_log_path, XB_LOG_FILENAME,
4218
xtrabackup_target_dir, "", MYF(0));
4219
dst_log_fd = my_create(dst_log_path, 0,
4220
O_RDWR | O_BINARY | O_EXCL |
4221
O_NOFOLLOW, MYF(MY_WME));
4222
if (dst_log_fd < 0) {
4223
msg("xtrabackup: error: cannot open %s "
4224
"(errno: %d)\n", dst_log_path, my_errno);
4104
4228
#ifdef USE_POSIX_FADVISE
4105
posix_fadvise(dst_log, 0, 0, POSIX_FADV_DONTNEED);
4229
posix_fadvise(dst_log_fd, 0, 0, POSIX_FADV_DONTNEED);
4232
dst_log_fd = dup(fileno(stdout));
4233
if (dst_log_fd < 0) {
4234
msg("xtrabackup: error: dup() failed (errno: %d)",
4156
4271
os_thread_create(log_copying_thread, NULL, &log_copying_thread_id);
4160
if (!xtrabackup_stream) { /* stream mode is transaction log only */
4273
if (xtrabackup_parallel > 1 && xtrabackup_stream &&
4274
xtrabackup_stream_fmt == XB_STREAM_FMT_TAR) {
4275
msg("xtrabackup: warning: the --parallel option does not have "
4276
"any effect when streaming in the 'tar' format. "
4277
"You can use the 'xbstream' format instead.\n");
4278
xtrabackup_parallel = 1;
4281
/* Initialize the appropriate datasink */
4282
if (xtrabackup_log_only) {
4283
ds = &datasink_local;
4284
} else if (xtrabackup_compress) {
4285
ds = &datasink_compress;
4286
} else if (xtrabackup_stream) {
4287
ds = &datasink_stream;
4289
ds = &datasink_local;
4292
ds_ctxt = ds->init(xtrabackup_target_dir);
4293
if (ds_ctxt == NULL) {
4294
msg("xtrabackup: Error: failed to initialize the "
4299
if (!xtrabackup_log_only) {
4163
4302
os_mutex_t count_mutex;
4164
4303
data_thread_ctxt_t *data_threads;
4305
ut_a(xtrabackup_parallel > 0);
4169
printf("xtrabackup: Starting %u threads for parallel "
4170
"data files transfer\n", parallel);
4307
if (xtrabackup_parallel > 1) {
4308
msg("xtrabackup: Starting %u threads for parallel data "
4309
"files transfer\n", xtrabackup_parallel);
4172
4312
it = datafiles_iter_new(f_system);
4173
4313
if (it == NULL) {
4175
"xtrabackup: Error: "
4176
"datafiles_iter_new() failed.\n");
4314
msg("xtrabackup: Error: "
4315
"datafiles_iter_new() failed.\n");
4177
4316
exit(EXIT_FAILURE);
4180
4319
/* Create data copying threads */
4183
4320
data_threads = (data_thread_ctxt_t *)
4184
ut_malloc(sizeof(data_thread_ctxt_t) * parallel);
4321
ut_malloc(sizeof(data_thread_ctxt_t) *
4322
xtrabackup_parallel);
4323
count = xtrabackup_parallel;
4186
4324
count_mutex = OS_MUTEX_CREATE();
4188
for (i = 0; i < (uint) parallel; i++) {
4326
for (i = 0; i < (uint) xtrabackup_parallel; i++) {
4189
4327
data_threads[i].it = it;
4190
4328
data_threads[i].num = i+1;
4191
4329
data_threads[i].count = &count;
4192
4330
data_threads[i].count_mutex = count_mutex;
4331
data_threads[i].ds_ctxt = ds_ctxt;
4193
4332
os_thread_create(data_copy_thread_func,
4194
4333
data_threads + i,
4195
4334
&data_threads[i].id);
4274
4419
mutex_exit(&log_sys->mutex);
4276
if (!xtrabackup_stream) {
4277
#ifndef INNODB_VERSION_SHORT
4278
printf("xtrabackup: The latest check point (for incremental): '%lu:%lu'\n",
4279
latest_cp.high, latest_cp.low);
4281
printf("xtrabackup: The latest check point (for incremental): '%llu'\n",
4285
#ifndef INNODB_VERSION_SHORT
4286
fprintf(stderr, "xtrabackup: The latest check point (for incremental): '%lu:%lu'\n",
4287
latest_cp.high, latest_cp.low);
4289
fprintf(stderr, "xtrabackup: The latest check point (for incremental): '%llu'\n",
4421
#ifndef INNODB_VERSION_SHORT
4422
msg("xtrabackup: The latest check point (for incremental): "
4423
"'%lu:%lu'\n", latest_cp.high, latest_cp.low);
4425
msg("xtrabackup: The latest check point (for incremental): "
4426
"'%llu'\n", latest_cp);
4295
4430
/* stop log_copying_thread */
4296
4431
log_copying = FALSE;
4297
if (!xtrabackup_stream) {
4298
printf("xtrabackup: Stopping log copying thread");
4299
while (log_copying_running) {
4301
os_thread_sleep(200000); /*0.2 sec*/
4432
msg("xtrabackup: Stopping log copying thread.\n");
4433
while (log_copying_running) {
4435
os_thread_sleep(200000); /*0.2 sec*/
4439
if(!xtrabackup_incremental) {
4440
strcpy(metadata_type, "full-backuped");
4441
metadata_from_lsn = ut_dulint_zero;
4305
while (log_copying_running)
4306
os_thread_sleep(200000); /*0.2 sec*/
4443
strcpy(metadata_type, "incremental");
4444
metadata_from_lsn = incremental_lsn;
4446
metadata_to_lsn = latest_cp;
4447
metadata_last_lsn = log_copy_scanned_lsn;
4309
/* output to metadata file */
4449
if (!xtrabackup_stream_metadata(ds_ctxt))
4450
msg("xtrabackup: error: "
4451
"xtrabackup_stream_metadata() failed.\n"
4453
if (xtrabackup_extra_lsndir) {
4311
4454
char filename[FN_REFLEN];
4313
if(!xtrabackup_incremental) {
4314
strcpy(metadata_type, "full-backuped");
4315
metadata_from_lsn = ut_dulint_zero;
4317
strcpy(metadata_type, "incremental");
4318
metadata_from_lsn = incremental_lsn;
4320
metadata_to_lsn = latest_cp;
4321
metadata_last_lsn = log_copy_scanned_lsn;
4323
sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
4324
if (xtrabackup_write_metadata(filename))
4325
fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_target_dir)\n");
4327
if(xtrabackup_extra_lsndir) {
4328
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4329
if (xtrabackup_write_metadata(filename))
4330
fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4456
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
4457
XTRABACKUP_METADATA_FILENAME);
4458
if (!xtrabackup_write_metadata(filename))
4459
msg("xtrabackup: error: "
4460
"xtrabackup_write_metadata() failed.\n");
4334
4464
if (!log_copying_succeed) {
4335
fprintf(stderr, "xtrabackup: Error: log_copying_thread failed.\n");
4339
if (!xtrabackup_stream)
4340
os_file_close(dst_log);
4465
msg("xtrabackup: Error: log_copying_thread failed.\n");
4469
/* Stream the transaction log from the temporary file */
4470
if (!xtrabackup_log_only && xtrabackup_stream &&
4471
xtrabackup_stream_temp_logfile(dst_log_fd, ds_ctxt)) {
4472
msg("xtrabackup: Error: failed to stream the log "
4473
"from the temporary file %s", logfile_temp_path);
4477
ds->deinit(ds_ctxt);
4342
4479
if (wait_throttle)
4343
4480
os_event_free(wait_throttle);
4345
if (!xtrabackup_stream) {
4346
#ifndef INNODB_VERSION_SHORT
4347
printf("xtrabackup: Transaction log of lsn (%lu %lu) to (%lu %lu) was copied.\n",
4348
checkpoint_lsn_start.high, checkpoint_lsn_start.low,
4349
log_copy_scanned_lsn.high, log_copy_scanned_lsn.low);
4351
printf("xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
4352
checkpoint_lsn_start, log_copy_scanned_lsn);
4355
#ifndef INNODB_VERSION_SHORT
4356
fprintf(stderr, "xtrabackup: Transaction log of lsn (%lu %lu) to (%lu %lu) was copied.\n",
4357
checkpoint_lsn_start.high, checkpoint_lsn_start.low,
4358
log_copy_scanned_lsn.high, log_copy_scanned_lsn.low);
4360
fprintf(stderr, "xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
4361
checkpoint_lsn_start, log_copy_scanned_lsn);
4363
if(xtrabackup_extra_lsndir) {
4364
char filename[FN_REFLEN];
4365
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
4366
if (xtrabackup_write_metadata(filename))
4367
fprintf(stderr, "xtrabackup: error: xtrabackup_write_metadata(xtrabackup_extra_lsndir)\n");
4482
#ifndef INNODB_VERSION_SHORT
4483
msg("xtrabackup: Transaction log of lsn (%lu %lu) to (%lu %lu) was "
4484
"copied.\n", checkpoint_lsn_start.high, checkpoint_lsn_start.low,
4485
log_copy_scanned_lsn.high, log_copy_scanned_lsn.low);
4487
msg("xtrabackup: Transaction log of lsn (%llu) to (%llu) was copied.\n",
4488
checkpoint_lsn_start, log_copy_scanned_lsn);
4372
4492
/* ================= stats ================= */
4677
4797
sprintf(logname, "ib_logfile%lu", (ulong) n);
4678
4798
if (!os_file_status(logname, &exists, &type) || !exists ||
4679
4799
type != OS_FILE_TYPE_FILE) {
4680
fprintf(stderr, "xtrabackup: Error: "
4681
"Cannot find log file %s.\n", logname);
4682
fprintf(stderr, "xtrabackup: Error: "
4683
"to use the statistics feature, you need a "
4684
"clean copy of the database including "
4685
"correctly sized log files, so you need to "
4686
"execute with --prepare twice to use this "
4687
"functionality on a backup.\n");
4800
msg("xtrabackup: Error: "
4801
"Cannot find log file %s.\n", logname);
4802
msg("xtrabackup: Error: "
4803
"to use the statistics feature, you need a "
4804
"clean copy of the database including "
4805
"correctly sized log files, so you need to "
4806
"execute with --prepare twice to use this "
4807
"functionality on a backup.\n");
4688
4808
exit(EXIT_FAILURE);
4692
fprintf(stderr, "xtrabackup: Starting 'read-only' InnoDB instance to gather index statistics.\n"
4693
"xtrabackup: Using %lld bytes for buffer pool (set by --use-memory parameter)\n",
4694
xtrabackup_use_memory);
4812
msg("xtrabackup: Starting 'read-only' InnoDB instance to gather "
4813
"index statistics.\n"
4814
"xtrabackup: Using %lld bytes for buffer pool (set by "
4815
"--use-memory parameter)\n", xtrabackup_use_memory);
4696
4817
if(innodb_init())
4697
4818
exit(EXIT_FAILURE);
4942
5063
max_no = ut_dulint_zero;
4944
5065
if(!xtrabackup_incremental_dir) {
4945
sprintf(dst_path, "%s%s", xtrabackup_target_dir, "/ib_logfile0");
4946
sprintf(src_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
5066
sprintf(dst_path, "%s/ib_logfile0", xtrabackup_target_dir);
5067
sprintf(src_path, "%s/%s", xtrabackup_target_dir,
4948
sprintf(dst_path, "%s%s", xtrabackup_incremental_dir, "/ib_logfile0");
4949
sprintf(src_path, "%s%s", xtrabackup_incremental_dir, "/xtrabackup_logfile");
5070
sprintf(dst_path, "%s/ib_logfile0", xtrabackup_incremental_dir);
5071
sprintf(src_path, "%s/%s", xtrabackup_incremental_dir,
4952
5075
srv_normalize_path_for_win(dst_path);
5633
5750
/* rename 'ib_logfile0' to 'xtrabackup_logfile' */
5634
5751
if(!xtrabackup_incremental_dir) {
5635
sprintf(dst_path, "%s%s", xtrabackup_target_dir, "/ib_logfile0");
5636
sprintf(src_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
5752
sprintf(dst_path, "%s/ib_logfile0", xtrabackup_target_dir);
5753
sprintf(src_path, "%s/%s", xtrabackup_target_dir,
5638
sprintf(dst_path, "%s%s", xtrabackup_incremental_dir, "/ib_logfile0");
5639
sprintf(src_path, "%s%s", xtrabackup_incremental_dir, "/xtrabackup_logfile");
5756
sprintf(dst_path, "%s/ib_logfile0", xtrabackup_incremental_dir);
5757
sprintf(src_path, "%s/%s", xtrabackup_incremental_dir,
5642
5761
srv_normalize_path_for_win(dst_path);
5716
5836
sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
5718
if (xtrabackup_read_metadata(filename))
5719
fprintf(stderr, "xtrabackup: error: xtrabackup_read_metadata()\n");
5838
if (!xtrabackup_read_metadata(filename))
5839
msg("xtrabackup: error: xtrabackup_read_metadata()\n");
5721
5841
if (!strcmp(metadata_type, "full-backuped")) {
5722
fprintf(stderr, "xtrabackup: This target seems to be not prepared yet.\n");
5842
msg("xtrabackup: This target seems to be not prepared "
5723
5844
} else if (!strcmp(metadata_type, "full-prepared")) {
5724
fprintf(stderr, "xtrabackup: This target seems to be already prepared.\n");
5845
msg("xtrabackup: This target seems to be already "
5725
5847
goto skip_check;
5727
fprintf(stderr, "xtrabackup: This target seems not to have correct metadata...\n");
5849
msg("xtrabackup: This target seems not to have correct "
5730
5853
if (xtrabackup_incremental) {
5732
"xtrabackup: error: applying incremental backup needs target prepared.\n");
5854
msg("xtrabackup: error: applying incremental backup "
5855
"needs target prepared.\n");
5733
5856
exit(EXIT_FAILURE);
5736
5859
if (xtrabackup_incremental
5737
5860
&& ut_dulint_cmp(metadata_to_lsn, incremental_lsn) != 0) {
5739
"xtrabackup: error: This incremental backup seems not to be proper for the target.\n"
5740
"xtrabackup: Check 'to_lsn' of the target and 'from_lsn' of the incremental.\n");
5861
msg("xtrabackup: error: This incremental backup seems "
5862
"not to be proper for the target.\n"
5863
"xtrabackup: Check 'to_lsn' of the target and "
5864
"'from_lsn' of the incremental.\n");
5741
5865
exit(EXIT_FAILURE);
5783
5907
srv_n_file_io_threads = 10;
5786
fprintf(stderr, "xtrabackup: Starting InnoDB instance for recovery.\n"
5787
"xtrabackup: Using %lld bytes for buffer pool (set by --use-memory parameter)\n",
5788
xtrabackup_use_memory);
5910
msg("xtrabackup: Starting InnoDB instance for recovery.\n"
5911
"xtrabackup: Using %lld bytes for buffer pool "
5912
"(set by --use-memory parameter)\n", xtrabackup_use_memory);
5790
5914
if(innodb_init())
5793
//printf("Hello InnoDB world!\n");
5795
/* TEST: innodb status*/
5797
ulint trx_list_start = ULINT_UNDEFINED;
5798
ulint trx_list_end = ULINT_UNDEFINED;
5799
srv_printf_innodb_monitor(stdout, &trx_list_start, &trx_list_end);
5801
/* TEST: list of datafiles and transaction log files and LSN*/
5804
fil_system_t* f_system = fil_system;
5808
mutex_enter(&(f_system->mutex));
5810
space = UT_LIST_GET_FIRST(f_system->space_list);
5812
while (space != NULL) {
5813
printf("space: name=%s, id=%d, purpose=%d, size=%d\n",
5814
space->name, space->id, space->purpose, space->size);
5816
node = UT_LIST_GET_FIRST(space->chain);
5818
while (node != NULL) {
5819
printf("node: name=%s, open=%d, size=%d\n",
5820
node->name, node->open, node->size);
5822
node = UT_LIST_GET_NEXT(chain, node);
5824
space = UT_LIST_GET_NEXT(space_list, space);
5827
mutex_exit(&(f_system->mutex));
5830
5917
/* align space sizes along with fsp header */
5832
5919
fil_system_t* f_system = fil_system;
6076
6170
&& ut_dulint_cmp(srv_start_lsn, incremental_last_lsn) < 0)
6077
6171
||(!xtrabackup_incremental
6078
6172
&& ut_dulint_cmp(srv_start_lsn, metadata_last_lsn) < 0)) {
6079
printf( "xtrabackup: ########################################################\n"
6080
"xtrabackup: # !!WARNING!! #\n"
6081
"xtrabackup: # The transaction log file should be wrong or corrupt. #\n"
6082
"xtrabackup: # The log was not applied to the intended LSN! #\n"
6083
"xtrabackup: ########################################################\n");
6174
"xtrabackup: ########################################################\n"
6175
"xtrabackup: # !!WARNING!! #\n"
6176
"xtrabackup: # The transaction log file is corrupted. #\n"
6177
"xtrabackup: # The log was not applied to the intended LSN! #\n"
6178
"xtrabackup: ########################################################\n"
6084
6180
if (xtrabackup_incremental) {
6085
6181
#ifndef INNODB_VERSION_SHORT
6086
printf("xtrabackup: The intended lsn is %lu:%lu\n",
6087
incremental_last_lsn.high, incremental_last_lsn.low);
6182
msg("xtrabackup: The intended lsn is %lu:%lu\n",
6183
incremental_last_lsn.high,
6184
incremental_last_lsn.low);
6089
printf("xtrabackup: The intended lsn is %llu\n",
6090
incremental_last_lsn);
6186
msg("xtrabackup: The intended lsn is %llu\n",
6187
incremental_last_lsn);
6093
6190
#ifndef INNODB_VERSION_SHORT
6094
printf("xtrabackup: The intended lsn is %lu:%lu\n",
6095
metadata_last_lsn.high, metadata_last_lsn.low);
6191
msg("xtrabackup: The intended lsn is %lu:%lu\n",
6192
metadata_last_lsn.high, metadata_last_lsn.low);
6097
printf("xtrabackup: The intended lsn is %llu\n",
6194
msg("xtrabackup: The intended lsn is %llu\n",
6452
6525
exit(EXIT_SUCCESS);
6455
if (!xtrabackup_stream) {
6529
if (!xtrabackup_log_only) {
6457
6530
if (xtrabackup_incremental) {
6458
6531
#ifndef INNODB_VERSION_SHORT
6460
"incremental backup from %lu:%lu is enabled.\n",
6461
incremental_lsn.high, incremental_lsn.low);
6532
msg("incremental backup from %lu:%lu is enabled.\n",
6533
incremental_lsn.high, incremental_lsn.low);
6464
"incremental backup from %llu is enabled.\n",
6535
msg("incremental backup from %llu is enabled.\n",
6469
6540
if (xtrabackup_backup) {
6470
6541
xtrabackup_suspend_at_end = TRUE;
6471
fprintf(stderr, "xtrabackup: suspend-at-end is enabled.\n");
6542
msg("xtrabackup: suspend-at-end is enabled.\n");
6475
6546
if (xtrabackup_export && innobase_file_per_table == FALSE) {
6476
fprintf(stderr, "xtrabackup: error: --export option can only "
6477
"be used with --innodb-file-per-table=ON.\n");
6547
msg("xtrabackup: error: --export option can only "
6548
"be used with --innodb-file-per-table=ON.\n");
6478
6549
exit(EXIT_FAILURE);