~akopytov/percona-xtrabackup/bug1135441-followup-2.1

« back to all changes in this revision

Viewing changes to innobackupex

  • Committer: Alexey Kopytov
  • Date: 2013-08-16 06:41:05 UTC
  • mfrom: (657.2.1 2.1)
  • Revision ID: akopytov@gmail.com-20130816064105-b12pwdr9i82atw5q
MergedĀ lp:~akopytov/percona-xtrabackup/bug1135441-2.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
200
200
# run on a slave server
201
201
my $mysql_slave_position = '';
202
202
 
 
203
# process id if the script itself
 
204
my $innobackupex_pid = $$;
 
205
 
203
206
# process id of ibbackup program (runs as a child process of this script)
204
207
my $ibbackup_pid = '';
205
208
 
400
403
    return strftime("%y%m%d %H:%M:%S", localtime());
401
404
}
402
405
 
403
 
 
404
 
#
405
 
# Die subroutine kills all child processes and exits this process.
406
 
# This subroutine takes the same argument as the built-in die function.
407
 
#    Parameters:
408
 
#       message   string which is printed to stdout
409
 
#
410
 
sub Die {
411
 
    my $message = shift;
412
 
 
413
 
    # kill all child processes of this process
414
 
    kill_child_processes();
415
 
 
416
 
    die "$prefix Error: $message";
417
 
}
418
 
    
 
406
#
 
407
# Global initialization:
 
408
# 1. Override the 'die' builtin to customize the format of error messages
 
409
#
 
410
# 2. Setup signal handlers to terminate gracefully on fatal signals
 
411
#
 
412
BEGIN {
 
413
    *CORE::GLOBAL::die = sub {
 
414
 
 
415
        print STDERR "$prefix Error: @_";
 
416
 
 
417
        # Mimic the default 'die' behavior: append information about the caller
 
418
        # and the new line, if the argument does not already end with a newline
 
419
        if ($_[-1] !~ m(\n$)) {
 
420
            my ($pkg, $file, $line) = caller 0;
 
421
 
 
422
            print STDERR " at $file line $line.\n";
 
423
        }
 
424
 
 
425
        exit(1);
 
426
    };
 
427
 
 
428
    foreach ('HUP', 'INT', 'QUIT', 'ABRT', 'PIPE', 'TERM', 'XFSZ') {
 
429
        $SIG{$_} = \&catch_fatal_signal;
 
430
    }
 
431
}
 
432
 
 
433
#
 
434
# Make sure all child processes are killed on exit. This doesn't cover cases
 
435
# when innobackupex is terminated with a signal.
 
436
#
 
437
END {
 
438
    # We only want to execute this in the parent script process, and ignore
 
439
    # for all child processes it may spawn
 
440
    if ($$ == $innobackupex_pid) {
 
441
        kill_child_processes();
 
442
    }
 
443
}
 
444
 
 
445
#
 
446
# kill child processes spawned by the script
 
447
#
 
448
sub kill_child_processes {
 
449
    if ($ibbackup_pid) {
 
450
        kill($kill_signal, $ibbackup_pid);
 
451
        wait_for_ibbackup_finish();
 
452
    }
 
453
    stop_query_killer();
 
454
}
 
455
 
 
456
sub catch_fatal_signal {
 
457
    # Don't print anything if a child process is terminated with a signal
 
458
    if ($$ == $innobackupex_pid) {
 
459
        die "Terminated with SIG$_[0]"
 
460
    }
 
461
}
 
462
 
419
463
#
420
464
# Finds all files that match the given pattern recursively beneath
421
465
# the given directory. Returns a list of files with their paths relative 
429
473
  my @retlist;
430
474
 
431
475
  opendir(FINDDIR, $dir)
432
 
        || Die "Can't open directory '$dir': $!\n";
 
476
        || die "Can't open directory '$dir': $!";
433
477
 
434
478
  while (defined($child = readdir(FINDDIR))) {
435
479
    next if $child eq "." || $child eq "..";
464
508
  } elsif ($mode == 2) {
465
509
    $file_cmd = "qpress -do " . $file . " > " . $dest_file;
466
510
  } else {
467
 
    Die("Unknown decrypt_decompress mode : $mode\n"); 
 
511
    die "Unknown decrypt_decompress mode : $mode";
468
512
  }
469
513
  print STDERR "$prefix $file_cmd\n";
470
 
  system("$file_cmd") && Die "$file_cmd failed with $!\n";
 
514
  system("$file_cmd") && die "$file_cmd failed with $!";
471
515
  system("rm -f $file");
472
516
}
473
517
 
505
549
  } elsif ($mode == 2) {
506
550
    $file_ext = ".qp";
507
551
  } else {
508
 
    Die("Unknown decrypt_decompress mode : $mode\n"); 
 
552
    die "Unknown decrypt_decompress mode : $mode";
509
553
  }
510
554
 
511
555
  # recursively find all files of interest in the backup set
547
591
          if ($status == $pids[$freepidindex]) {
548
592
            my $childretcode = $? >> 8;
549
593
            if ($childretcode != 0) {
550
 
              Die("Child failed on $workingfiles[$freepidindex] : $childretcode");
 
594
              die "Child failed on $workingfiles[$freepidindex] : $childretcode";
551
595
            }
552
596
            last;
553
597
          } elsif ($status == -1) {
554
 
            Die("waitpid failed on $workingfiles[$freepidindex] : $status");
 
598
            die "waitpid failed on $workingfiles[$freepidindex] : $status";
555
599
          }
556
600
        }
557
601
        # couldn't find a free slot yet so sleep for 1/10 th of a second or so.
581
625
      my $childretcode = $? >> 8;
582
626
      if ($status == $pids[$freepidindex]) {
583
627
        if ($childretcode != 0) {
584
 
          Die("Child failed on $workingfiles[$freepidindex] : $childretcode");
 
628
          die "Child failed on $workingfiles[$freepidindex] : $childretcode";
585
629
        }
586
630
      } else {
587
 
        Die("waitpid failed on $workingfiles[$freepidindex] : $status");
 
631
        die "waitpid failed on $workingfiles[$freepidindex] : $status";
588
632
      }
589
633
    }
590
634
  }
795
839
    my $dst_path = shift;
796
840
 
797
841
    print STDERR "$prefix Copying '$src_path' to '$dst_path'\n";
798
 
    copy($src_path, $dst_path) or Die "copy failed: $!";
 
842
    copy($src_path, $dst_path) or die "copy failed: $!";
799
843
}
800
844
 
801
845
#
806
850
    my $dst_path = shift;
807
851
 
808
852
    print STDERR "$prefix Moving '$src_path' to '$dst_path'\n";
809
 
    move($src_path, $dst_path) or Die "move failed: $!";
 
853
    move($src_path, $dst_path) or die "move failed: $!";
810
854
}
811
855
 
812
856
 
851
895
        # Create the directory in the destination if necessary
852
896
        if (! -e "$dst_path") {
853
897
            print STDERR "$prefix Creating directory '$dst_path'\n";
854
 
            mkdir "$dst_path" or Die "mkdir failed: $!";
 
898
            mkdir "$dst_path" or die "mkdir failed: $!";
855
899
        } elsif (! -d "$dst_path") {
856
 
            Die "$dst_path exists, but is not a directory";
 
900
            die "$dst_path exists, but is not a directory";
857
901
        }
858
902
    } else {
859
903
        # Don't overwrite files unless $copy_dir_overwrite is 1
860
904
        if (!$copy_dir_overwrite && -e "$copy_dir_dst/$_") {
861
 
            Die "Failed to process file $File::Find::name: " .
 
905
            die "Failed to process file $File::Find::name: " .
862
906
                "not overwriting file $copy_dir_dst/$_";
863
907
        }
864
908
 
898
942
    }
899
943
    if (! exists $processed_files{$rel_path}) {
900
944
        unlink($File::Find::name) or
901
 
            Die("Cannot remove file $File::Find::name");
 
945
            die "Cannot remove file $File::Find::name";
902
946
    }
903
947
}
904
948
 
1043
1087
                                      "Original undo directory");
1044
1088
    }
1045
1089
 
1046
 
    # check that the original options file and the backup options file have
1047
 
    # the same value for "innodb_data_file_path" option
1048
 
    #$backup_innodb_data_file_path = 
1049
 
    #    get_option(\%backup_config, 'mysqld', 'innodb_data_file_path');
1050
 
    #if (!are_equal_innodb_data_file_paths($orig_innodb_data_file_path, 
1051
 
    #                                      $backup_innodb_data_file_path)
1052
 
    #) {
1053
 
    #    Die "The value of 'innodb_data_file_path' option in the original "
1054
 
    #      . "my.cnf file '$config_file' is different from the value "
1055
 
    #      . "in the backup my.cnf file '$backup_config_file'.\n(original: "
1056
 
    #      . "'$orig_innodb_data_file_path')\n"
1057
 
    #      . "(backup:   '$backup_innodb_data_file_path')";
1058
 
    #}
1059
 
 
1060
1090
    # make a list of all ibdata files in the backup directory and all
1061
1091
    # directories in the backup directory under which there are ibdata files
1062
1092
    foreach my $c (parse_innodb_data_file_path($orig_innodb_data_file_path)) {
1064
1094
        # check that the backup data file exists
1065
1095
        if (! -e "$backup_dir/$c->{filename}") {
1066
1096
            if (-e "$backup_dir/$c->{filename}.ibz") {
1067
 
                Die "Backup data file '$backup_dir/$c->{filename}' "
 
1097
                die "Backup data file '$backup_dir/$c->{filename}' "
1068
1098
                  . "does not exist, but "
1069
1099
                  . "its compressed copy '$c->{path}.ibz' exists. Check "
1070
1100
                  . "that you have decompressed "
1072
1102
                  . "'$innobackup_script --copy-back ...'  "
1073
1103
                  . "or '$innobackup_script --move-back ...' !";
1074
1104
            } elsif (-e "$backup_dir/$c->{filename}.qp") {
1075
 
                Die "Backup data file '$backup_dir/$c->{filename}' "
 
1105
                die "Backup data file '$backup_dir/$c->{filename}' "
1076
1106
                  . "does not exist, but "
1077
1107
                  . "its compressed copy '$c->{path}.qp' exists. Check "
1078
1108
                  . "that you have run "
1081
1111
                  . "'$innobackup_script --copy-back ...'  "
1082
1112
                  . "or '$innobackup_script --move-back ...' !";
1083
1113
            } elsif (-e "$backup_dir/$c->{filename}.xbcrypt") {
1084
 
                Die "Backup data file '$backup_dir/$c->{filename}' "
 
1114
                die "Backup data file '$backup_dir/$c->{filename}' "
1085
1115
                  . "does not exist, but "
1086
1116
                  . "its compressed copy '$c->{path}.xbcrypt' exists. Check "
1087
1117
                  . "that you have run "
1090
1120
                  . "'$innobackup_script --copy-back ...'  "
1091
1121
                  . "or '$innobackup_script --move-back ...' !";
1092
1122
            } else {
1093
 
                Die "Backup data file '$backup_dir/$c->{filename}' "
 
1123
                die "Backup data file '$backup_dir/$c->{filename}' "
1094
1124
                    . "does not exist.";
1095
1125
            }
1096
1126
        }
1123
1153
    print STDERR "$prefix in '$backup_dir'\n";
1124
1154
    print STDERR "$prefix back to '$orig_undo_dir'\n";
1125
1155
    opendir(DIR, $backup_dir)
1126
 
        || Die "Can't open directory '$backup_dir': $!\n";
 
1156
        || die "Can't open directory '$backup_dir': $!";
1127
1157
    while (defined($file = readdir(DIR))) {
1128
1158
        if ($file =~ /^$ibundo_files$/ && -f "$backup_dir/$file") {
1129
1159
            $src_name = escape_path("$backup_dir/$file");
1135
1165
 
1136
1166
    # copy InnoDB log files to original InnoDB log directory
1137
1167
    opendir(DIR, $backup_dir) 
1138
 
        || Die "Can't open directory '$backup_dir': $!\n";
 
1168
        || die "Can't open directory '$backup_dir': $!";
1139
1169
    print STDERR "\n$prefix Starting to $operation InnoDB log files\n";
1140
1170
    print STDERR "$prefix in '$backup_dir'\n";
1141
1171
    print STDERR "$prefix back to original InnoDB log directory '$orig_iblog_dir'\n";
1216
1246
    $rcode = system("$cmdline");
1217
1247
    if ($rcode) {
1218
1248
        # failure
1219
 
        Die "\n$prefix ibbackup failed";
 
1249
        die "\n$prefix ibbackup failed";
1220
1250
    }
1221
1251
 
1222
1252
    # We should not create ib_logfile files if we prepare for following incremental applies
1228
1258
        $rcode = system("$cmdline");
1229
1259
        if ($rcode) {
1230
1260
            # failure
1231
 
            Die "\n$prefix xtrabackup (2nd execution) failed";
 
1261
            die "\n$prefix xtrabackup (2nd execution) failed";
1232
1262
        }
1233
1263
    }
1234
1264
 
1275
1305
 
1276
1306
        if ($ibbackup_pid == $pid) {
1277
1307
            # The file doesn't exist, but the process has terminated
1278
 
            Die "ibbackup child process has died";
 
1308
            $ibbackup_pid = '';
 
1309
            die "The xtrabackup child process has died";
1279
1310
        }
1280
1311
 
1281
1312
        sleep 1;
1309
1340
#
1310
1341
sub resume_ibbackup {
1311
1342
    my $suspend_file = shift;
1312
 
    unlink $suspend_file || Die "Failed to delete '$suspend_file': $!";
 
1343
    unlink $suspend_file || die "Failed to delete '$suspend_file': $!";
1313
1344
}
1314
1345
 
1315
1346
#
1325
1356
 
1326
1357
    wait_for_ibbackup_file_create($suspend_file);
1327
1358
 
1328
 
    unlink $suspend_file || Die "Failed to delete '$suspend_file': $!";
 
1359
    unlink $suspend_file || die "Failed to delete '$suspend_file': $!";
1329
1360
}
1330
1361
 
1331
1362
#
1460
1491
            $ibbackup_pid = $pid;
1461
1492
        } else {
1462
1493
            # child process
1463
 
            exec($cmdline) || Die "Failed to exec ibbackup: $!";
 
1494
            exec($cmdline) || die "Failed to exec ibbackup: $!";
1464
1495
        }
1465
1496
    } else {
1466
 
        Die "failed to fork ibbackup child process: $!";
 
1497
        die "failed to fork ibbackup child process: $!";
1467
1498
    }
1468
1499
}
1469
1500
                  
1513
1544
    my $con = shift;
1514
1545
 
1515
1546
    if (defined($con->{keep_alive_pid})) {
1516
 
        Die "Keep-alive process has already been started for this connection."
 
1547
        die "Keep-alive process has already been started for this connection."
1517
1548
    }
1518
1549
 
1519
1550
    my $keep_alive_pid = fork();
1557
1588
    my $con = shift;
1558
1589
 
1559
1590
    if (!defined($con->{keep_alive_pid})) {
1560
 
        Die "Keep-alive process has never been started for this connection."
 
1591
        die "Keep-alive process has never been started for this connection."
1561
1592
    }
1562
1593
 
1563
1594
    kill 'INT', $con->{keep_alive_pid};
1565
1596
    my $rc = $? >> 8;
1566
1597
 
1567
1598
    if ($rc != 0) {
1568
 
        Die "Keep-alive process died with exit code " . $rc;
 
1599
        die "Keep-alive process died with exit code " . $rc;
1569
1600
    }
1570
1601
    undef $con->{keep_alive_pid};
1571
1602
}
1611
1642
 
1612
1643
    if ($args{abort_on_error}) {
1613
1644
        if (!$dbd_mysql_installed) {
1614
 
            die "ERROR: Failed to connect to MySQL server as " .
 
1645
            die "Failed to connect to MySQL server as " .
1615
1646
                "DBD::mysql module is not installed";
1616
1647
        } else {
1617
1648
            if (!$con{dbh}) {
1618
 
                die "ERROR: Failed to connect to MySQL server: " .
 
1649
                die "Failed to connect to MySQL server: " .
1619
1650
                    $con{connect_error};
1620
1651
            }
1621
1652
        }
1670
1701
      }
1671
1702
  };
1672
1703
  if ($EVAL_ERROR) {
1673
 
      Die "\nError executing '$query': $EVAL_ERROR\n";
 
1704
      die "\nError executing '$query': $EVAL_ERROR";
1674
1705
  }
1675
1706
}
1676
1707
 
1925
1956
        sleep(1);
1926
1957
    }
1927
1958
 
1928
 
    Die "Unable to obtain lock. Please try again.";
 
1959
    die "Unable to obtain lock. Please try again.";
1929
1960
}
1930
1961
 
1931
1962
 
1964
1995
    if (defined($query_killer_pid)) {
1965
1996
        kill 'HUP' => $query_killer_pid;
1966
1997
        waitpid($query_killer_pid, 0);
 
1998
        undef $query_killer_pid;
1967
1999
        print STDERR "Query killing process is finished\n";
1968
2000
    }
1969
2001
}
2029
2061
}
2030
2062
 
2031
2063
#
2032
 
# kill_child_processes subroutine kills all child processes of this process.
2033
 
#
2034
 
sub kill_child_processes {
2035
 
    if ($ibbackup_pid) {
2036
 
        kill($kill_signal, $ibbackup_pid);
2037
 
        $ibbackup_pid = '';
2038
 
    }
2039
 
    stop_query_killer();
2040
 
}
2041
 
 
2042
 
 
2043
 
#
2044
2064
# require_external subroutine checks that an external program is runnable
2045
2065
# via the shell. This is tested by calling the program with the
2046
2066
# given arguments. It is checked that the program returns 0 and does 
2075
2095
    if ($stderr ne '') {
2076
2096
        # failure
2077
2097
        unlink $tmp_stdout;
2078
 
        Die "Couldn't run $program: $stderr";
 
2098
        die "Couldn't run $program: $stderr";
2079
2099
    } elsif ($rcode) {
2080
2100
        # failure
2081
2101
        unlink $tmp_stdout;
2082
 
        Die "Couldn't run $program: $error";
 
2102
        die "Couldn't run $program: $error";
2083
2103
    }
2084
2104
 
2085
2105
    # success
2186
2206
            && $ibbackup_version le "2.0") {
2187
2207
            # --include option was given, but ibbackup is too
2188
2208
            # old to support it
2189
 
            Die "--include option was given, but ibbackup is too old"
 
2209
            die "--include option was given, but ibbackup is too old"
2190
2210
                . " to support it. You must upgrade to InnoDB Hot Backup"
2191
2211
                . " v2.0 in order to use --include option.\n";
2192
2212
        }
2229
2249
                    "WARNING : A left over instance of " .
2230
2250
                    "suspend file '$suspend_file' was found.\n";
2231
2251
                unlink "$suspend_file"
2232
 
                    || Die "Failed to delete '$suspend_file': $!";
 
2252
                    || die "Failed to delete '$suspend_file': $!";
2233
2253
            }
2234
2254
        }
2235
2255
 
2238
2258
                         "file '$option_tmpdir/$xtrabackup_pid_file' " .
2239
2259
                         "was found.\n";
2240
2260
            unlink $option_tmpdir . "/" . $xtrabackup_pid_file || 
2241
 
                Die "Failed to delete " .
 
2261
                die "Failed to delete " .
2242
2262
                    "'$option_tmpdir/$xtrabackup_pid_file': $!";
2243
2263
        }
2244
2264
 
2313
2333
        }
2314
2334
    }
2315
2335
 
2316
 
    if (@ARGV == 0) {
2317
 
        # no command line arguments
2318
 
        print STDERR "$prefix You must specify the backup directory.\n";
2319
 
        exit(1);
2320
 
    }
2321
 
 
2322
2336
    # read command line options
2323
2337
    $rcode = GetOptions('compress' => \$option_compress,
2324
2338
                        'decompress' => \$option_decompress,
2383
2397
                        'lock-wait-query-type=s' =>
2384
2398
                        \$option_lock_wait_query_type
2385
2399
    );
2386
 
                        
 
2400
 
 
2401
    if (@ARGV == 0) {
 
2402
        die "You must specify the backup directory.\n";
 
2403
    } elsif (@ARGV > 1) {
 
2404
        die "Too many command line arguments\n";
 
2405
    }
 
2406
 
2387
2407
    if (!$rcode) {
2388
2408
        # failed to read options
2389
 
        print STDERR "$prefix Bad command line arguments\n";
2390
 
        exit(1);
 
2409
        die "Bad command line arguments\n";
2391
2410
    }
2392
2411
    if ($option_help) {
2393
2412
        # print help text and exit
2401
2420
    }
2402
2421
 
2403
2422
    if ($option_defaults_file && $option_defaults_extra_file) {
2404
 
        print STDERR "$prefix --defaults-file and --defaults-extra-file " .
 
2423
        die "--defaults-file and --defaults-extra-file " .
2405
2424
            "options are mutually exclusive";
2406
 
        exit(1);
2407
2425
    }
2408
2426
 
2409
2427
    if ($option_copy_back && $option_move_back) {
2423
2441
 
2424
2442
    # validate lock-wait-query-type and kill-long-query-type values
2425
2443
    if (!(grep {$_ eq $option_lock_wait_query_type} qw/all update/)) {
2426
 
        Die "Wrong value of lock-wait-query-type. ".
 
2444
        die "Wrong value of lock-wait-query-type. ".
2427
2445
            "Possible values are all|update, but $option_lock_wait_query_type ".
2428
2446
            "is specified.";
2429
2447
    }
2430
2448
    if (!(grep {$_ eq $option_kill_long_query_type} qw/all select/)) {
2431
 
        Die "Wrong value of kill-long-query-type. ".
 
2449
        die "Wrong value of kill-long-query-type. ".
2432
2450
            "Possible values are all|select, but $option_kill_long_query_type ".
2433
2451
            "is specified.";
2434
2452
    }
2435
2453
 
2436
2454
    if ($option_parallel && $option_parallel < 1) {
2437
 
        Die "$prefix --parallel must be a positive numerical value" .
2438
 
            "greater than 0";
 
2455
        die "--parallel must be a positive value.\n";
2439
2456
    }
2440
2457
 
2441
2458
    if ($option_stream eq 'tar') {
2457
2474
      }
2458
2475
    }
2459
2476
 
2460
 
    if (@ARGV < 1) {
2461
 
        print STDERR "$prefix Missing command line argument\n";
2462
 
        exit(1);
2463
 
    } elsif (@ARGV > 1) {
2464
 
        print STDERR "$prefix Too many command line arguments\n";
2465
 
        exit(1);
2466
 
    }
2467
 
 
2468
2477
    if (!$option_apply_log && !$option_copy_back && !$option_move_back
2469
2478
        && !$option_decrypt && !$option_decompress) {
2470
2479
        # we are making a backup, get backup root directory
2487
2496
 
2488
2497
    if ($option_slave_info) {
2489
2498
        if ($option_no_lock and !$option_safe_slave_backup) {
2490
 
          print STDERR "--slave-info is used with --no-lock but without --safe-slave-backup. The binlog position cannot be consistent with the backup data.\n";
2491
 
            exit(1);
 
2499
          die "--slave-info is used with --no-lock but without --safe-slave-backup. The binlog position cannot be consistent with the backup data.\n";
2492
2500
        }
2493
2501
    }
2494
2502
 
2495
2503
    if ($option_rsync && $option_stream) {
2496
 
        print STDERR "--rsync doesn't work with --stream\n";
2497
 
        exit(1);
 
2504
        die "--rsync doesn't work with --stream\n";
2498
2505
    }
2499
2506
 
2500
2507
    if ($option_decompress) {
2501
2508
      if (system("which qpress &>/dev/null") >> 8 != 0) {
2502
 
        print STDERR "--decompress requires qpress\n";
2503
 
        exit(1);
 
2509
        die "--decompress requires qpress\n";
2504
2510
      }
2505
2511
    }
2506
2512
 
2528
2534
 
2529
2535
    $dir .= '/' . strftime("%Y-%m-%d_%H-%M-%S", localtime())
2530
2536
       unless $option_no_timestamp;
2531
 
    mkdir($dir, 0777) || Die "Failed to create backup directory $dir: $!";
 
2537
    mkdir($dir, 0777) || die "Failed to create backup directory $dir: $!";
2532
2538
 
2533
2539
    # create subdirectories for ibdata files if needed
2534
2540
#    foreach my $a (split(/;/, $innodb_data_file_path)) {
2566
2572
        $path = $path . "/" . $a;
2567
2573
        if (! -d $path) {
2568
2574
            # this directory does not exist, create it !
2569
 
            mkdir($path, 0777) || Die "Failed to create backup directory: $!";
 
2575
            mkdir($path, 0777) || die "Failed to create backup directory: $!";
2570
2576
        }
2571
2577
    }
2572
2578
}
2626
2632
            $rsync_file_list = $rsync_tmpfile_pass2;
2627
2633
        }
2628
2634
        open(RSYNC, ">$rsync_file_list")
2629
 
            || Die "Can't open $rsync_file_list for writing: $!\n";
 
2635
            || die "Can't open $rsync_file_list for writing: $!";
2630
2636
    }
2631
2637
 
2632
2638
    opendir(DIR, $source_dir) 
2633
 
        || Die "Can't open directory '$source_dir': $!\n";
 
2639
        || die "Can't open directory '$source_dir': $!";
2634
2640
    $now = current_time();
2635
2641
    if ($prep_mode) {
2636
2642
        $operation = "a prep copy of";
2653
2659
            if (! -e "$backup_dir/$database") {
2654
2660
                # create database directory for the backup
2655
2661
                mkdir("$backup_dir/$database", 0777)
2656
 
                    || Die "Couldn't create directory '$backup_dir/$database': $!";
 
2662
                    || die "Couldn't create directory '$backup_dir/$database': $!";
2657
2663
            }
2658
2664
        }
2659
2665
 
2720
2726
        # ignore errors in the prep mode, since we are running without lock,
2721
2727
        # so some files may have disappeared.
2722
2728
        if (system("$rsync_cmd") && !$prep_mode) {
2723
 
            Die "rsync failed: $!\n";
 
2729
            die "rsync failed: $!";
2724
2730
        }
2725
2731
 
2726
2732
        $now = current_time();
2731
2737
        # with --files-from.
2732
2738
        if (!$prep_mode && !$option_no_lock) {
2733
2739
            open(RSYNC, "<$rsync_tmpfile_pass1")
2734
 
                || Die "Can't open $rsync_tmpfile_pass1 for reading: $!\n";
 
2740
                || die "Can't open $rsync_tmpfile_pass1 for reading: $!";
2735
2741
 
2736
2742
            while (<RSYNC>) {
2737
2743
                chomp;
2743
2749
 
2744
2750
            close(RSYNC);
2745
2751
            unlink "$rsync_tmpfile_pass1" || \
2746
 
                Die "Failed to delete $rsync_tmpfile_pass1: $!";
 
2752
                die "Failed to delete $rsync_tmpfile_pass1: $!";
2747
2753
            unlink "$rsync_tmpfile_pass2" || \
2748
 
                Die "Failed to delete $rsync_tmpfile_pass2: $!";
 
2754
                die "Failed to delete $rsync_tmpfile_pass2: $!";
2749
2755
        }
2750
2756
    }
2751
2757
 
2771
2777
    my $filename = shift;
2772
2778
    my $lines_ref = shift;
2773
2779
    
2774
 
    open(FILE, $filename) || Die "can't open file '$filename': $!";
 
2780
    open(FILE, $filename) || die "can't open file '$filename': $!";
2775
2781
    @{$lines_ref} = <FILE>;
2776
 
    close(FILE) || Die "can't close file '$filename': $!";
 
2782
    close(FILE) || die "can't close file '$filename': $!";
2777
2783
 
2778
2784
    foreach my $a (@{$lines_ref}) {
2779
2785
        chomp($a);
2943
2949
 
2944
2950
    if (!exists ${$config_ref}{$group}) {
2945
2951
        # no group
2946
 
        print STDERR "$prefix fatal error: no '$group' group in MySQL options\n";
2947
 
        exit(1);
 
2952
        die "no '$group' group in MySQL options";
2948
2953
    }
2949
2954
 
2950
2955
    $group_hash_ref = ${$config_ref}{$group};
2970
2975
 
2971
2976
    if (!exists $config{$group}) {
2972
2977
        # no group
2973
 
        print STDERR "$prefix fatal error: no '$group' group in MySQL options\n";
2974
 
        exit(1);
 
2978
        die "no '$group' group in MySQL options";
2975
2979
    }
2976
2980
    
2977
2981
    $group_hash_ref = ${$config_ref}{$group};
2978
2982
    if (!exists ${$group_hash_ref}{$option_name}) {
2979
2983
        # no option
2980
 
        print STDERR "$prefix fatal error: no '$option_name' option in group '$group' in MySQL options\n";
2981
 
        exit(1);
 
2984
        die "no '$option_name' option in group '$group' in MySQL options";
2982
2985
    }
2983
2986
 
2984
2987
    return ${$group_hash_ref}{$option_name};
3089
3092
        # the option value is pathname of the file containing
3090
3093
        # list of databases
3091
3094
        if (! -f $option_databases) {
3092
 
            Die "can't find file '$option_databases'";
 
3095
            die "can't find file '$option_databases'";
3093
3096
        }
3094
3097
 
3095
3098
        # read from file the value of --databases option
3199
3202
 
3200
3203
 
3201
3204
    if($var_version =~ m/5\.0\.\d/) {
3202
 
        Die "MySQL 5.0 support was removed in Percona XtraBackup 2.1. The last version to support MySQL 5.0 was Percona XtraBackup 2.0.";
 
3205
        die "MySQL 5.0 support was removed in Percona XtraBackup 2.1. The last version to support MySQL 5.0 was Percona XtraBackup 2.0.\n";
3203
3206
    }
3204
3207
 
3205
3208
    if($var_version =~ m/5\.1\.\d/ && !defined($var_innodb_version)) {
3206
 
        Die "Support for MySQL 5.1 with builtin InnoDB (not the plugin) was removed in Percona XtraBackup 2.1. The last version to support MySQL 5.1 with builtin InnoDB was Percona XtraBackup 2.0.";
 
3209
        die "Support for MySQL 5.1 with builtin InnoDB (not the plugin) was removed in Percona XtraBackup 2.1. The last version to support MySQL 5.1 with builtin InnoDB was Percona XtraBackup 2.0.\n";
3207
3210
    }
3208
3211
 
3209
3212
    if($var_version =~ m/5\.1\.\d/) {
3227
3230
    }
3228
3231
 
3229
3232
    if (!$ibbackup_binary) {
3230
 
        Die "Unsupported server version: '$var_version' " .
 
3233
        die "Unsupported server version: '$var_version' " .
3231
3234
            "(InnoDB version: '$var_innodb_version'). " .
3232
3235
            "Please report a bug at ".
3233
3236
            "https://bugs.launchpad.net/percona-xtrabackup\n";
3295
3298
       mysql_query($con, 'START SLAVE SQL_THREAD');
3296
3299
   }
3297
3300
 
3298
 
   Die "Slave_open_temp_tables did not become zero after waiting $option_safe_slave_backup_timeout seconds";
 
3301
   die "Slave_open_temp_tables did not become zero after $option_safe_slave_backup_timeout seconds";
3299
3302
}
3300
3303
 
3301
3304
sub get_slave_open_temp_tables {
3304
3307
    get_mysql_status($con);
3305
3308
 
3306
3309
    if (!defined($con->{status}->{Slave_open_temp_tables})) {
3307
 
        Die "Failed to get Slave_open_temp_tables from SHOW STATUS"
 
3310
        die "Failed to get Slave_open_temp_tables from SHOW STATUS"
3308
3311
    }
3309
3312
    if (!defined($con->{status}->{Slave_open_temp_tables}->{Value})) {
3310
 
        Die "SHOW STATUS LIKE 'slave_open_temp_tables' did not return anything"
 
3313
        die "SHOW STATUS LIKE 'slave_open_temp_tables' did not return anything"
3311
3314
    }
3312
3315
 
3313
3316
   return $con->{status}->{Slave_open_temp_tables}->{Value};
3352
3355
    }
3353
3356
    # Only treat as fatal cases where the file exists
3354
3357
    if ( -e "$src_path/$src_file" ) {
3355
 
      Die "Failed to stream '$src_path/$src_file': $ret";
 
3358
      die "Failed to stream '$src_path/$src_file': $ret";
3356
3359
    } else {
3357
3360
      print STDERR "$prefix Ignoring nonexistent file '$src_path/$src_file'.\n";
3358
3361
    }
3377
3380
    $dst_file_esc = $dst_file_esc . ".xbcrypt";
3378
3381
    $ret = system("$encrypt_cmd -i \"$src_file_esc\" -o \"$dst_file_esc\"");
3379
3382
    if ($ret != 0) {
3380
 
      Die "Failed to copy and encrypt file '$src_file': $ret";
 
3383
      die "Failed to copy and encrypt file '$src_file': $ret";
3381
3384
    }
3382
3385
  } elsif ( -e "$src_file_esc" ) {
3383
3386
    $ret = system("$CP_CMD \"$src_file_esc\" \"$dst_file_esc\"");
3384
3387
    if ($ret != 0) {
3385
 
       Die "Failed to copy file '$src_file': $ret";
 
3388
       die "Failed to copy file '$src_file': $ret";
3386
3389
     }
3387
3390
  }
3388
3391
}