@@ -3326,14 +3326,81 @@ static void stop_backup_threads()
3326
3326
}
3327
3327
}
3328
3328
3329
+ /* * Implement the core of --backup
3330
+ @return whether the operation succeeded */
3331
+ static
3332
+ bool
3333
+ xtrabackup_backup_low ()
3334
+ {
3335
+ /* read the latest checkpoint lsn */
3336
+ {
3337
+ ulint max_cp_field;
3338
+
3339
+ log_mutex_enter ();
3340
+
3341
+ if (recv_find_max_checkpoint (&max_cp_field) == DB_SUCCESS
3342
+ && log_sys->log .format != 0 ) {
3343
+ metadata_to_lsn = mach_read_from_8 (
3344
+ log_sys->checkpoint_buf + LOG_CHECKPOINT_LSN);
3345
+ msg (" xtrabackup: The latest check point"
3346
+ " (for incremental): '" LSN_PF " '\n " ,
3347
+ metadata_to_lsn);
3348
+ } else {
3349
+ metadata_to_lsn = 0 ;
3350
+ msg (" xtrabackup: Error: recv_find_max_checkpoint() failed.\n " );
3351
+ }
3352
+ log_mutex_exit ();
3353
+ }
3354
+
3355
+ stop_backup_threads ();
3356
+
3357
+ if (!dst_log_file || xtrabackup_copy_logfile (COPY_LAST)) {
3358
+ return false ;
3359
+ }
3360
+
3361
+ if (ds_close (dst_log_file)) {
3362
+ dst_log_file = NULL ;
3363
+ return false ;
3364
+ }
3365
+
3366
+ dst_log_file = NULL ;
3367
+
3368
+ if (!xtrabackup_incremental) {
3369
+ strcpy (metadata_type, " full-backuped" );
3370
+ metadata_from_lsn = 0 ;
3371
+ } else {
3372
+ strcpy (metadata_type, " incremental" );
3373
+ metadata_from_lsn = incremental_lsn;
3374
+ }
3375
+ metadata_last_lsn = log_copy_scanned_lsn;
3376
+
3377
+ if (!xtrabackup_stream_metadata (ds_meta)) {
3378
+ msg (" xtrabackup: Error: failed to stream metadata.\n " );
3379
+ return false ;
3380
+ }
3381
+ if (xtrabackup_extra_lsndir) {
3382
+ char filename[FN_REFLEN];
3383
+
3384
+ sprintf (filename, " %s/%s" , xtrabackup_extra_lsndir,
3385
+ XTRABACKUP_METADATA_FILENAME);
3386
+ if (!xtrabackup_write_metadata (filename)) {
3387
+ msg (" xtrabackup: Error: failed to write metadata "
3388
+ " to '%s'.\n " , filename);
3389
+ return false ;
3390
+ }
3391
+
3392
+ }
3393
+
3394
+ return true ;
3395
+ }
3396
+
3329
3397
/* * Implement --backup
3330
3398
@return whether the operation succeeded */
3331
3399
static
3332
3400
bool
3333
3401
xtrabackup_backup_func ()
3334
3402
{
3335
3403
MY_STAT stat_info;
3336
- lsn_t latest_cp;
3337
3404
uint i;
3338
3405
uint count;
3339
3406
pthread_mutex_t count_mutex;
@@ -3733,70 +3800,19 @@ xtrabackup_backup_func()
3733
3800
}
3734
3801
}
3735
3802
3736
- if (!backup_start ()) {
3737
- goto fail;
3738
- }
3739
-
3740
- /* read the latest checkpoint lsn */
3741
- {
3742
- ulint max_cp_field;
3743
-
3744
- log_mutex_enter ();
3745
-
3746
- if (recv_find_max_checkpoint (&max_cp_field) == DB_SUCCESS
3747
- && log_sys->log .format != 0 ) {
3748
- latest_cp = mach_read_from_8 (log_sys->checkpoint_buf +
3749
- LOG_CHECKPOINT_LSN);
3750
- msg (" xtrabackup: The latest check point"
3751
- " (for incremental): '" LSN_PF " '\n " , latest_cp);
3752
- } else {
3753
- latest_cp = 0 ;
3754
- msg (" xtrabackup: Error: recv_find_max_checkpoint() failed.\n " );
3755
- }
3756
- log_mutex_exit ();
3757
- }
3758
-
3759
- stop_backup_threads ();
3760
-
3761
- if (!dst_log_file || xtrabackup_copy_logfile (COPY_LAST)) {
3762
- goto fail;
3763
- }
3803
+ bool ok = backup_start ();
3764
3804
3765
- if (ds_close (dst_log_file)) {
3766
- dst_log_file = NULL ;
3767
- goto fail;
3768
- }
3769
-
3770
- dst_log_file = NULL ;
3805
+ if (ok) {
3806
+ ok = xtrabackup_backup_low ();
3771
3807
3772
- if (!xtrabackup_incremental) {
3773
- strcpy (metadata_type, " full-backuped" );
3774
- metadata_from_lsn = 0 ;
3775
- } else {
3776
- strcpy (metadata_type, " incremental" );
3777
- metadata_from_lsn = incremental_lsn;
3778
- }
3779
- metadata_to_lsn = latest_cp;
3780
- metadata_last_lsn = log_copy_scanned_lsn;
3808
+ backup_release ();
3781
3809
3782
- if (!xtrabackup_stream_metadata (ds_meta)) {
3783
- msg (" xtrabackup: Error: failed to stream metadata.\n " );
3784
- goto fail;
3785
- }
3786
- if (xtrabackup_extra_lsndir) {
3787
- char filename[FN_REFLEN];
3788
-
3789
- sprintf (filename, " %s/%s" , xtrabackup_extra_lsndir,
3790
- XTRABACKUP_METADATA_FILENAME);
3791
- if (!xtrabackup_write_metadata (filename)) {
3792
- msg (" xtrabackup: Error: failed to write metadata "
3793
- " to '%s'.\n " , filename);
3794
- goto fail;
3810
+ if (ok) {
3811
+ backup_finish ();
3795
3812
}
3796
-
3797
3813
}
3798
3814
3799
- if (!backup_finish () ) {
3815
+ if (!ok ) {
3800
3816
goto fail;
3801
3817
}
3802
3818
@@ -3809,10 +3825,10 @@ xtrabackup_backup_func()
3809
3825
xb_data_files_close ();
3810
3826
3811
3827
/* Make sure that the latest checkpoint was included */
3812
- if (latest_cp > log_copy_scanned_lsn) {
3828
+ if (metadata_to_lsn > log_copy_scanned_lsn) {
3813
3829
msg (" xtrabackup: error: failed to copy enough redo log ("
3814
3830
" LSN=" LSN_PF " ; checkpoint LSN=" LSN_PF " ).\n " ,
3815
- log_copy_scanned_lsn, latest_cp );
3831
+ log_copy_scanned_lsn, metadata_to_lsn );
3816
3832
goto fail;
3817
3833
}
3818
3834
0 commit comments