420
420
# (or finalize the backup by syncing changes if using rsync)
423
# resume ibbackup and wait till it has finished
424
my $ibbackup_exit_code = resume_ibbackup();
423
# resume ibbackup and wait till log copying is finished
426
426
# release read locks on all tables
427
427
mysql_unlockall() if !$option_no_lock;
429
my $ibbackup_exit_code = wait_for_ibbackup_finish();
429
431
if ( $option_safe_slave_backup && $sql_thread_started) {
430
432
print STDERR "$prefix: Starting slave SQL thread\n";
431
433
mysql_send('START SLAVE SQL_THREAD;');
905
# resume_ibbackup subroutine signals ibbackup to complete its execution
906
# by deleting the 'ibbackup_suspended' file.
907
# resume_ibbackup subroutine signals ibbackup to finish log copying by deleting
908
# the 'xtrabackup_suspended' file and waits until log copying is stopped,
909
# i.e. until 'xtrabackup_suspended' is created again.
911
# If this functions detects that the xtrabackup process has terminated, it also
912
# sets ibbackup_exit_code and resets ibbackup_pid to avoid trying to reap a
913
# non-existing process later
908
915
sub resume_ibbackup {
909
print STDERR "$prefix Resuming ibbackup\n\n";
910
unlink $suspend_file || Die "Failed to delete '$suspend_file': $!";
918
$now = current_time();
919
print STDERR "$now $prefix Waiting for log copying to finish\n\n";
920
unlink $suspend_file || Die "Failed to delete '$suspend_file': $!";
923
# check if the xtrabackup process is still alive _before_ checking if
924
# the file exists to avoid a race condition when the file is created and
925
# the process terminates right after we do the file check
926
$pid = waitpid($ibbackup_pid, &WNOHANG);
928
last if -e $suspend_file;
930
if ($ibbackup_pid == $pid) {
931
# The file doesn't exist, but the process has terminated
932
Die "ibbackup child process has died";
938
if ($pid == $ibbackup_pid) {
939
$ibbackup_exit_code = $CHILD_ERROR >> 8;
943
unlink $suspend_file || Die "Failed to delete '$suspend_file': $!";
947
# wait for ibbackup to finish and return its exit code
949
sub wait_for_ibbackup_finish {
950
if (!$ibbackup_pid) {
951
# The process has already been reaped.
952
return $ibbackup_exit_code;
955
$now = current_time();
956
print STDERR "$now $prefix Waiting for ibbackup (pid=$ibbackup_pid) to finish\n";
912
958
# wait for ibbackup to finish
913
959
waitpid($ibbackup_pid, 0);