~sergei.glushchenko/+junk/page-scan-hack

« back to all changes in this revision

Viewing changes to innobackupex

merge parallel compression branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
my $option_throttle = '';
76
76
my $option_sleep = '';
77
77
my $option_compress = 999;
 
78
my $option_compress_threads = 1;
78
79
my $option_uncompress = '';
79
80
my $option_export = '';
80
81
my $option_use_memory = '';
98
99
my $option_remote_host = '';
99
100
my $option_rsync = '';
100
101
my $option_stream = '';
 
102
my $stream_cmd = '';
101
103
my $option_tmpdir = '';
102
104
 
103
105
my $option_tar4ibd = '';
296
298
    close XTRABACKUP_BINARY;
297
299
 
298
300
    if ($option_stream) {
299
 
      system("cd $option_tmpdir; tar chf - $xtrabackup_binary_file")
 
301
      system("cd $option_tmpdir; $stream_cmd $xtrabackup_binary_file")
300
302
        && die "Failed to stream $xtrabackup_binary_file: $!";
301
303
      unlink "$option_tmpdir/$xtrabackup_binary_file";
302
304
    }
387
389
    start_ibbackup();
388
390
 
389
391
    # wait for ibbackup to suspend itself
390
 
    if (!$option_remote_host && !$option_stream) {
 
392
    if (!$option_remote_host) {
391
393
        wait_for_ibbackup_suspend();
392
394
    }
393
395
 
456
458
        system("scp $option_scp_opt '$option_tmpdir/xtrabackup_checkpoints' '$option_remote_host:$backup_dir/xtrabackup_checkpoints'")
457
459
            and Die "Failed to scp file '$option_remote_host:$backup_dir/xtrabackup_checkpoints': $!";
458
460
        unlink "$option_tmpdir/xtrabackup_checkpoints" || Die "Failed to delete '$option_tmpdir/xtrabackup_checkpoints': $!";
459
 
    } elsif ($option_stream eq 'tar') {
460
 
        system("cd $option_tmpdir; tar chf - xtrabackup_logfile")
461
 
            and Die "Failed to stream 'xtrabackup_logfile': $!";
462
 
        unlink $tmp_logfile || Die "Failed to delete '$tmp_logfile': $!";
463
 
 
464
 
        system("cd $option_tmpdir; tar chf - xtrabackup_checkpoints")
465
 
            and Die "Failed to stream 'xtrabackup_checkpoints': $!";
466
 
        unlink "$option_tmpdir/xtrabackup_checkpoints" || Die "Failed to delete '$option_tmpdir/xtrabackup_checkpoints': $!";
467
461
    }
468
462
 
469
463
    print STDERR "\n$prefix Backup created in directory '$backup_dir'\n";
874
868
        $options = $options . " --target-dir=$backup_dir";
875
869
    } else {
876
870
        #(datadir) for 'xtrabackup_suspended' and 'xtrabackup_checkpoints'
877
 
        $options = $options . " --log-stream --target-dir=" . $option_tmpdir;
 
871
        $options = $options . " --target-dir=" . $option_tmpdir;
 
872
        if ($option_remote_host) {
 
873
          $options = $options . " --log-stream";
 
874
        }
878
875
    }
879
876
 
880
877
    # prepare command line for running ibbackup
885
882
        $options = $options . " --sleep=$option_sleep";
886
883
    }
887
884
    if ($option_compress) {
888
 
        $options = $options . " --compress=$option_compress";
 
885
        $options = $options . " --compress";
 
886
        $options = $options . " --compress-threads=$option_compress_threads";
889
887
    }
890
888
    if ($option_use_memory) {
891
889
        $options = $options . " --use-memory=$option_use_memory";
909
907
        $options = $options . " --tables_file='$option_tables_file'";
910
908
    }
911
909
    if ($option_parallel) {
912
 
        $options = $options. " --parallel=$option_parallel";
 
910
        $options = $options . " --parallel=$option_parallel";
 
911
    }
 
912
    if ($option_stream) {
 
913
        $options = $options . " --stream=$option_stream";
913
914
    }
914
915
    $cmdline = "$option_ibbackup_binary $options";
915
916
 
921
922
            # parent process
922
923
            $ibbackup_pid = $pid;
923
924
 
924
 
            if($option_remote_host || $option_stream) {
 
925
            if($option_remote_host) {
925
926
                #direct copy to remote
926
927
                my $orig_datadir = get_option(\%config, 'mysqld', 'datadir');
927
928
                my $orig_ibdata_dir =
936
937
                my $subdir;
937
938
                my @list;
938
939
 
939
 
                if($option_remote_host) {
940
 
                    if (system("ssh $option_ssh_opt $option_remote_host test -e $backup_dir/ib_logfile0")
941
 
                            == 0) {
942
 
                        print STDERR "$prefix Remove $option_remote_host:$backup_dir/ib_logfile*\n";
943
 
                        system("ssh $option_ssh_opt $option_remote_host rm $backup_dir/ib_logfile\*")
944
 
                            and Die "Failed to rm file '$backup_dir/ib_logfile*': $!";
945
 
                    }
 
940
                if (system("ssh $option_ssh_opt $option_remote_host test -e $backup_dir/ib_logfile0")
 
941
                    == 0) {
 
942
                    print STDERR "$prefix Remove $option_remote_host:$backup_dir/ib_logfile*\n";
 
943
                    system("ssh $option_ssh_opt $option_remote_host rm $backup_dir/ib_logfile\*")
 
944
                        and Die "Failed to rm file '$backup_dir/ib_logfile*': $!";
946
945
                }
947
946
 
948
947
                wait_for_ibbackup_suspend();
949
948
 
950
949
                #InnoDB data files from original InnoDB data directory
951
950
                print STDERR "\n$prefix Starting to backup InnoDB tables and indexes\n";
952
 
                if($option_remote_host) {
953
 
                    print STDERR "$prefix to '$backup_dir'\n";
954
 
                }
 
951
                print STDERR "$prefix to '$backup_dir'\n";
955
952
                print STDERR "$prefix from original InnoDB data directory '$orig_ibdata_dir'\n";
956
953
                foreach my $a (split(/;/, $orig_innodb_data_file_path)) {
957
954
                    my $path = (split(/:/,$a))[0];
958
955
                    $path=~s/([\$\\\" ])/\\$1/g;
959
 
                    if($option_remote_host) {
960
 
                        print STDERR "$prefix Backing up file '$orig_ibdata_dir/$path'\n";
961
 
                        system("scp $option_scp_opt '$orig_ibdata_dir/$path' '$option_remote_host:$backup_dir/$path'")
962
 
                            and Die "Failed to scp file '$path': $!";
963
 
                    } elsif($option_stream eq 'tar') {
964
 
                        my $ret = 0;
965
 
                        my $tarcmd;
966
 
                        print STDERR "$prefix Backing up as tar stream '$path'\n";
967
 
                        if (!$option_tar4ibd) {
968
 
                            $tarcmd = "tar chf - -b 32";
969
 
                        } else {
970
 
                            $tarcmd = "tar4ibd";
971
 
                            if ($innodb_use_odirect) {
972
 
                                $tarcmd = "$tarcmd -d";
973
 
                            }
974
 
                            $tarcmd = "$tarcmd -c";
975
 
                        }
976
 
                        $ret = system("cd $orig_ibdata_dir; $tarcmd $path") >> 8;
977
 
                        if ($ret == 1) {
978
 
                            print STDERR "$prefix If you use GNU tar, this warning can be ignored.\n";
979
 
                        } elsif ($ret != 0) {
980
 
                            print STDERR "$prefix tar returned with exit code $ret.\n";
981
 
                            if ( -e "$orig_ibdata_dir/$path" ) {
982
 
                                Die "Failed to stream '$orig_ibdata_dir/$path': $!";
983
 
                            }
984
 
                            else {
985
 
                                print STDERR "$prefix Ignoring nonexistent file '$orig_ibdata_dir/$path'.\n";
986
 
                            }
987
 
                        }
988
 
                    }
 
956
                    print STDERR "$prefix Backing up file '$orig_ibdata_dir/$path'\n";
 
957
                    system("scp $option_scp_opt '$orig_ibdata_dir/$path' '$option_remote_host:$backup_dir/$path'")
 
958
                      and Die "Failed to scp file '$path': $!";
989
959
                }
990
960
 
991
961
                #copy *.ibd files
1026
996
                        if ($print_each_file) {
1027
997
                            print STDERR "$prefix Backing up file '$file'\n";
1028
998
                        }
1029
 
                        if($option_remote_host) {
1030
 
                            if (system("ssh $option_ssh_opt $option_remote_host test -e $backup_dir/$subdir")
1031
 
                                    != 0) {
1032
 
                                system("ssh $option_ssh_opt $option_remote_host mkdir $backup_dir/$subdir");
1033
 
                            }
1034
 
                            system("scp $option_scp_opt '$file' '$option_remote_host:$backup_dir/$subdir/'")
1035
 
                                and Die "Failed to scp file '$file': $!";
1036
 
                        } elsif($option_stream eq 'tar') {
1037
 
                            my $ret = 0;
1038
 
                            my $file_name = substr($file, rindex($file, '/') + 1);
1039
 
                            $file_name=~s/([\$\\\" ])/\\$1/g;
1040
 
                            if (!$option_tar4ibd) {
1041
 
                                $ret = system("cd $orig_datadir; tar chf - -b 32 $subdir/$file_name") >> 8;
1042
 
                            } else {
1043
 
                                $ret = system("cd $orig_datadir; tar4ibd -c $subdir/$file_name") >> 8;
1044
 
                            }
1045
 
                            if ($ret == 1) {
1046
 
                                print STDERR "$prefix If you use GNU tar, this warning can be ignored.\n";
1047
 
                            } elsif ($ret != 0) {
1048
 
                                print STDERR "$prefix tar returned with exit code $ret.\n";
1049
 
                                if ( -e "$orig_datadir/$subdir/$file_name" ) {
1050
 
                                    Die "Failed to stream '$orig_datadir/$subdir/$file_name': $!";
1051
 
                                }
1052
 
                                else {
1053
 
                                    print STDERR "$prefix Ignoring nonexistent file '$orig_datadir/$subdir/$file_name'.\n";
1054
 
                                }
1055
 
                            }
 
999
                        if (system("ssh $option_ssh_opt $option_remote_host test -e $backup_dir/$subdir")
 
1000
                            != 0) {
 
1001
                          system("ssh $option_ssh_opt $option_remote_host mkdir $backup_dir/$subdir");
1056
1002
                        }
1057
 
                    }
 
1003
                        system("scp $option_scp_opt '$file' '$option_remote_host:$backup_dir/$subdir/'")
 
1004
                          and Die "Failed to scp file '$file': $!";
 
1005
                      }
1058
1006
                }
1059
1007
                closedir(DIR);
1060
1008
            }
1061
1009
        } else {
1062
 
            if($option_remote_host || $option_stream) {
 
1010
            if($option_remote_host) {
1063
1011
                open(STDOUT, "> $tmp_logfile")
1064
1012
                || Die "Failed to open file '$tmp_logfile': $!"
1065
1013
            }
1277
1225
    print FILE  "$info_lines[1]\n";
1278
1226
    close(FILE);
1279
1227
 
1280
 
    if ($option_stream eq 'tar') {
1281
 
        system("cd $option_tmpdir; tar chf - xtrabackup_binlog_info")
 
1228
    if ($option_stream) {
 
1229
        system("cd $option_tmpdir; $stream_cmd xtrabackup_binlog_info")
1282
1230
            and Die "Failed to stream 'xtrabackup_binlog_info': $!";
1283
1231
        unlink $binlog_info || Die "Failed to delete '$binlog_info': $!";
1284
1232
    }
1374
1322
    print FILE  "CHANGE MASTER TO MASTER_LOG_FILE='$filename', MASTER_LOG_POS=$position\n";
1375
1323
    close(FILE);
1376
1324
 
1377
 
    if ($option_stream eq 'tar') {
1378
 
        system("cd $option_tmpdir; tar chf - xtrabackup_slave_info")
 
1325
    if ($option_stream) {
 
1326
        system("cd $option_tmpdir; $stream_cmd xtrabackup_slave_info")
1379
1327
            and Die "Failed to stream 'xtrabackup_slave_info': $!";
1380
1328
        unlink $slave_info || Die "Failed to delete '$slave_info': $!";
1381
1329
    }
1734
1682
    if ($option_stream) {
1735
1683
        my $filename_dir = dirname($filename);
1736
1684
        my $filename_name = basename($filename);
1737
 
        if ($option_stream eq 'tar') {
1738
 
            system("cd $filename_dir; tar chf - $filename_name")
1739
 
                and Die "Failed to stream '$filename_name': $!";
1740
 
        }
 
1685
        system("cd $filename_dir; $stream_cmd $filename_name")
 
1686
          and Die "Failed to stream '$filename_name': $!";
 
1687
 
1741
1688
        unlink $filename || Die "Failed to delete '$filename': $!";
1742
1689
    }
1743
1690
}
1771
1718
    }
1772
1719
 
1773
1720
    # read command line options
1774
 
    $rcode = GetOptions('compress:i' => \$option_compress,
 
1721
    $rcode = GetOptions('compress' => \$option_compress,
 
1722
                        'compress-threads=i' => \$option_compress_threads,
1775
1723
                        'help' => \$option_help,
1776
1724
                        'version' => \$option_version,
1777
1725
                        'throttle=i' => \$option_throttle,
1839
1787
        $option_compress = 0;
1840
1788
    }
1841
1789
 
 
1790
    if ($option_stream eq 'tar') {
 
1791
      $stream_cmd = 'tar chf -';
 
1792
    } elsif ($option_stream eq 'xbstream') {
 
1793
      $stream_cmd = 'xbstream -c'
 
1794
    }
 
1795
 
1842
1796
    if (@ARGV < 1) {
1843
1797
        print STDERR "$prefix Missing command line argument\n";
1844
1798
        exit(1);
1847
1801
        exit(1);
1848
1802
    }
1849
1803
 
1850
 
    if ($option_stream) {
1851
 
        if ($option_stream eq 'tar') {
1852
 
           if ( !$option_force_tar ) {
1853
 
              $option_tar4ibd = 'tar4ibd';
1854
 
            }
1855
 
            else {
1856
 
               print STDERR "Forcing tar instead of tar4ibd\n";
1857
 
            }
1858
 
        } elsif ($option_stream eq 'tar4ibd') {
1859
 
            $option_stream = 'tar';
1860
 
            $option_tar4ibd = 'tar4ibd';
1861
 
        } elsif ($option_stream eq 'cpio') {
1862
 
            print STDERR "$prefix --stream=cpio is not supported yet\n";
1863
 
            exit(1);
1864
 
        } else {
1865
 
            print STDERR "$prefix Unknown option --stream=$option_stream\n";
1866
 
            exit(1);
1867
 
        }
1868
 
    }
1869
 
 
1870
1804
    # get options file name
1871
1805
    #$config_file = $ARGV[0];
1872
1806
 
2107
2041
            } elsif ($option_remote_host) {
2108
2042
                # Queue up files for one single scp per database.
2109
2043
                push(@scp_files, "'$file'");
2110
 
            } elsif($option_stream eq 'tar') {
 
2044
            } elsif($option_stream) {
2111
2045
                my $ret = 0;
2112
2046
                my $file_name = substr($file, rindex($file, '/') + 1);
2113
2047
                $file_name=~s/([\$\\\" ])/\\$1/g;
2114
 
                $ret = system("cd $source_dir; tar cf - $database/$file_name") >> 8;
2115
 
                if ($ret == 1) {
 
2048
                $ret = system("cd $source_dir; $stream_cmd $database/$file_name") >> 8;
 
2049
                if ($ret == 1 && $option_stream eq 'tar') {
2116
2050
                    print STDERR "$prefix If you use GNU tar, this warning can be ignored.\n";
2117
2051
                # Check for non-zero exit code
2118
2052
                } elsif ($ret != 0) {
2119
 
                    print STDERR "$prefix tar returned with exit code $ret.\n";
 
2053
                    print STDERR "$prefix $stream_cmd returned with exit code $ret.\n";
2120
2054
                    # Only treat as fatal cases where the file exists
2121
2055
                    if ( -e "$database/$file_name" ) {
2122
2056
                        Die "Failed to stream '$database/$file_name': $!";
2407
2341
    return ${$group_hash_ref}{$option_name};
2408
2342
}
2409
2343
 
 
2344
 
2410
2345
# check_if_required subroutine returns 1 if the specified database and
2411
2346
# table needs to be backed up.
2412
2347
#    Parameters:
2682
2617
 
2683
2618
=head1 SYNOPOSIS
2684
2619
 
2685
 
innobackupex [--compress[=LEVEL]] [--include=REGEXP] [--user=NAME] 
 
2620
innobackupex [--compress] [--compress-threads=NUMBER-OF-THREADS]
 
2621
             [--include=REGEXP] [--user=NAME]
2686
2622
             [--password=WORD] [--port=PORT] [--socket=SOCKET]
2687
2623
             [--no-timestamp] [--ibbackup=IBBACKUP-BINARY]
2688
 
             [--slave-info] [--stream=tar] [--force-tar]
2689
 
             [--scpopt=OPTIONS-FOR-SCP] [--sshopt=OPTIONS-FOR-SSH]
 
2624
             [--slave-info] [--stream=tar|xbstream] [--force-tar]
 
2625
             [--scpopt=OPTIONS-FOR-SCP]  [--sshopt=OPTIONS-FOR-SSH]
2690
2626
             [--defaults-file=MY.CNF]
2691
2627
             [--databases=LIST] [--remote-host=HOSTNAME] [--no-lock] 
2692
2628
             [--tmpdir=DIRECTORY] [--tables-file=FILE]
2741
2677
 
2742
2678
Prepare a backup in BACKUP-DIR by applying the transaction log file named "xtrabackup_logfile" located in the same directory. Also, create new transaction logs. The InnoDB configuration is read from the file "backup-my.cnf".
2743
2679
 
 
2680
=item --compress
 
2681
 
 
2682
This option instructs xtrabackup to compress backup copies of InnoDB
 
2683
data files. It is passed directly to the xtrabackup child process. Try
 
2684
'xtrabackup --help' for more details.
 
2685
 
 
2686
=item --compress-threads
 
2687
 
 
2688
This option specifies the number of worker threads that will be used
 
2689
for parallel compression. It is passed directly to the xtrabackup
 
2690
child process. Try 'xtrabackup --help' for more details.
 
2691
 
2744
2692
=item --copy-back
2745
2693
 
2746
2694
Copy all the files in a previously made backup from the backup directory to their original locations.
2852
2800
 
2853
2801
=item --stream=[tar|. . .]
2854
2802
 
2855
 
This option specifies the format in which to do the streamed backup.  The option accepts a string argument. The backup will be done to STDOUT in the specified format. Currently, the only supported format is tar. Uses tar4ibd, which is available in XtraBackup distributions.
 
2803
This option specifies the format in which to do the streamed backup.  The option accepts a string argument. The backup will be done to STDOUT in the specified format. Currently, the only supported formats are tar and xbstream. This option is passed directly to xtrabackup's --stream option.
2856
2804
 
2857
2805
=item --tables-file=FILE
2858
2806