~laurynas-biveinis/percona-xtrabackup/BT-28340-bug1158154-2.1

« back to all changes in this revision

Viewing changes to innobackupex

MergedĀ lp:~gl-az/percona-xtrabackup/BT-23557-2.1-encrypted_stream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
my $option_sleep = '';
86
86
my $option_compress = 999;
87
87
my $option_compress_threads = 1;
 
88
my $option_compress_chunk_size = '';
 
89
my $option_encrypt = '';
 
90
my $option_encrypt_key = '';
 
91
my $option_encrypt_key_file = '';
 
92
my $encrypt_cmd = '';
 
93
my $option_encrypt_threads = 1;
 
94
my $option_encrypt_chunk_size = '';
88
95
my $option_uncompress = '';
89
96
my $option_export = '';
90
97
my $option_use_memory = '';
298
305
    close XTRABACKUP_BINARY;
299
306
 
300
307
    if ($option_stream) {
301
 
      system("cd $option_tmpdir; $stream_cmd $xtrabackup_binary_file")
302
 
        && die "Failed to stream $xtrabackup_binary_file: $!";
 
308
      stream_encrypt_file($option_tmpdir, $xtrabackup_binary_file)
 
309
                          && die "Failed to stream $xtrabackup_binary_file: $!";
303
310
      unlink "$option_tmpdir/$xtrabackup_binary_file";
304
311
    }
305
312
}
420
427
    if (-e "$orig_datadir/ib_lru_dump") {
421
428
        if ($option_stream) {
422
429
            print STDERR "$prefix Backing up as tar stream 'ib_lru_dump'\n";
423
 
            system("cd $orig_datadir; $stream_cmd ib_lru_dump")
424
 
                and Die "Failed to stream 'ib_lru_dump': $!";
 
430
            stream_encrypt_file($orig_datadir, "ib_lru_dump")
 
431
                                and Die "Failed to stream 'ib_lru_dump': $!";
425
432
        } elsif (!$option_rsync) {
426
433
            my $src_name = escape_path("$orig_datadir/ib_lru_dump");
427
434
            my $dst_name = escape_path("$backup_dir/ib_lru_dump");
996
1003
        #(datadir) for 'xtrabackup_suspended' and 'xtrabackup_checkpoints'
997
1004
        $options = $options . " --target-dir=" . $option_tmpdir;
998
1005
    } else {
999
 
        $options = $options . " --target-dir=$backup_dir";
 
1006
        $options = $options . " --target-dir=$backup_dir";
1000
1007
    }
1001
1008
 
1002
1009
    if ($option_tmpdir) {
1013
1020
    if ($option_compress) {
1014
1021
        $options = $options . " --compress";
1015
1022
        $options = $options . " --compress-threads=$option_compress_threads";
 
1023
        if ($option_compress_chunk_size) {
 
1024
                $options = $options . " --compress-chunk-size=$option_compress_chunk_size";
 
1025
        }
 
1026
    }
 
1027
    if ($option_encrypt) {
 
1028
        $options = $options . " --encrypt=$option_encrypt";
 
1029
        if ($option_encrypt_key) {
 
1030
            $options = $options . " --encrypt-key=$option_encrypt_key";
 
1031
        }
 
1032
        if ($option_encrypt_key_file) {
 
1033
            $options = $options . " --encrypt-key-file=$option_encrypt_key_file";
 
1034
        }
 
1035
        $options = $options . " --encrypt-threads=$option_encrypt_threads";
 
1036
        if ($option_encrypt_chunk_size) {
 
1037
                $options = $options . " --encrypt-chunk-size=$option_encrypt_chunk_size";
 
1038
        }
1016
1039
    }
1017
1040
    if ($option_use_memory) {
1018
1041
        $options = $options . " --use-memory=$option_use_memory";
1027
1050
    if ($option_incremental) {
1028
1051
        if($option_incremental_lsn) {
1029
1052
          $options = $options . " --incremental-lsn='$option_incremental_lsn'";
1030
 
            } else {
 
1053
        } else {
1031
1054
          $options = $options . " --incremental-basedir='$incremental_basedir'";
1032
 
            }
 
1055
        }
1033
1056
    }
1034
1057
 
1035
1058
    if ($option_tables_file) {
1039
1062
        $options = $options . " --parallel=$option_parallel";
1040
1063
    }
1041
1064
    if ($option_stream) {
1042
 
        $options = $options . " --stream=$option_stream";
 
1065
        $options = $options . " --stream=$option_stream";
1043
1066
    }
1044
1067
 
1045
1068
    if ($option_compact) {
1319
1342
    close(FILE);
1320
1343
 
1321
1344
    if ($option_stream) {
1322
 
        system("cd $option_tmpdir; $stream_cmd xtrabackup_binlog_info")
1323
 
            and Die "Failed to stream 'xtrabackup_binlog_info': $!";
 
1345
        stream_encrypt_file($option_tmpdir, "xtrabackup_binlog_info")
 
1346
                            and Die "Failed to stream 'xtrabackup_binlog_info': $!";
1324
1347
        unlink $binlog_info || Die "Failed to delete '$binlog_info': $!";
1325
1348
    }
1326
1349
 
1350
1373
    close(FILE);
1351
1374
 
1352
1375
    if ($option_stream) {
1353
 
        system("cd $option_tmpdir; $stream_cmd xtrabackup_galera_info")
1354
 
            and Die "Failed to stream 'xtrabackup_galera_info': $!";
 
1376
        stream_encrypt_file($option_tmpdir, "xtrabackup_galera_info")
 
1377
                            and Die "Failed to stream 'xtrabackup_galera_info': $!";
1355
1378
        unlink $galera_info || Die "Failed to delete '$galera_info': $!";
1356
1379
    }
1357
1380
 
1391
1414
    close(FILE);
1392
1415
 
1393
1416
    if ($option_stream) {
1394
 
        system("cd $option_tmpdir; $stream_cmd xtrabackup_slave_info")
1395
 
            and Die "Failed to stream 'xtrabackup_slave_info': $!";
 
1417
        stream_encrypt_file($option_tmpdir, "xtrabackup_slave_info")
 
1418
                            and Die "Failed to stream 'xtrabackup_slave_info': $!";
1396
1419
        unlink $slave_info || Die "Failed to delete '$slave_info': $!";
1397
1420
    }
1398
1421
 
1687
1710
    if ($option_stream) {
1688
1711
        my $filename_dir = dirname($filename);
1689
1712
        my $filename_name = basename($filename);
1690
 
        system("cd $filename_dir; $stream_cmd $filename_name")
1691
 
          and Die "Failed to stream '$filename_name': $!";
1692
 
 
 
1713
        stream_encrypt_file($filename_dir, $filename_name)
 
1714
                            and Die "Failed to stream '$filename_name': $!";
1693
1715
        unlink $filename || Die "Failed to delete '$filename': $!";
1694
1716
    }
1695
1717
}
1724
1746
 
1725
1747
    # read command line options
1726
1748
    $rcode = GetOptions('compress' => \$option_compress,
1727
 
                        'compress-threads=i' => \$option_compress_threads,
 
1749
                        'compress-threads=i' => \$option_compress_threads,
 
1750
                        'compress-chunk-size=s' => \$option_compress_chunk_size,
 
1751
                        'encrypt=s' => \$option_encrypt,
 
1752
                        'encrypt-key=s' => \$option_encrypt_key,
 
1753
                        'encrypt-key-file=s' => \$option_encrypt_key_file,
 
1754
                        'encrypt-threads=i' => \$option_encrypt_threads,
 
1755
                        'encrypt-chunk-size=s' => \$option_encrypt_chunk_size,
1728
1756
                        'help' => \$option_help,
1729
1757
                        'version' => \$option_version,
1730
1758
                        'throttle=i' => \$option_throttle,
1756
1784
                        'incremental-dir=s' => \$option_incremental_dir,
1757
1785
                        'extra-lsndir=s' => \$option_extra_lsndir,
1758
1786
                        'stream=s' => \$option_stream,
1759
 
                        'rsync' => \$option_rsync,
 
1787
                        'rsync' => \$option_rsync,
1760
1788
                        'tmpdir=s' => \$option_tmpdir,
1761
1789
                        'no-lock' => \$option_no_lock,
1762
1790
                        'ibbackup=s' => \$option_ibbackup_binary,
1801
1829
 
1802
1830
    if ($option_compress == 999) {
1803
1831
        # compress option not given in the command line
1804
 
        $option_compress = 0;
 
1832
        $option_compress = 0;
1805
1833
    }
1806
1834
 
1807
1835
    if ($option_stream eq 'tar') {
1808
1836
      $stream_cmd = 'tar chf -';
1809
1837
    } elsif ($option_stream eq 'xbstream') {
1810
 
      $stream_cmd = 'xbstream -c'
 
1838
      $stream_cmd = 'xbstream -c';
 
1839
      if ($option_encrypt) {
 
1840
        $encrypt_cmd = "xbcrypt --encrypt-algo=$option_encrypt";
 
1841
        if ($option_encrypt_key) {
 
1842
          $encrypt_cmd = $encrypt_cmd . " --encrypt-key=$option_encrypt_key";
 
1843
        }
 
1844
        if ($option_encrypt_key_file) {
 
1845
          $encrypt_cmd = $encrypt_cmd . " --encrypt-key-file=$option_encrypt_key_file";
 
1846
        }
 
1847
        if ($option_encrypt_chunk_size) {
 
1848
          $encrypt_cmd = $encrypt_cmd . " --encrypt-chunk-size=$option_encrypt_chunk_size";
 
1849
        }
 
1850
      }
1811
1851
    }
1812
1852
 
1813
1853
    if (@ARGV < 1) {
2047
2087
                my $ret = 0;
2048
2088
                my $file_name = substr($file, rindex($file, '/') + 1);
2049
2089
                $file_name=~s/([\$\\\" ])/\\$1/g;
2050
 
                $ret = system("cd $source_dir; $stream_cmd $database/$file_name") >> 8;
 
2090
                $ret = stream_encrypt_file($source_dir, "$database/$file_name") >> 8;
2051
2091
                if ($ret == 1 && $option_stream eq 'tar') {
2052
2092
                    print STDERR "$prefix If you use GNU tar, this warning can be ignored.\n";
2053
2093
                # Check for non-zero exit code
2673
2713
   return $con->{status}->{Slave_open_temp_tables}->{Value};
2674
2714
}
2675
2715
 
 
2716
sub stream_encrypt_file {
 
2717
  my $basedir = shift;
 
2718
  my $relpath = shift;
 
2719
  my $rcode;
 
2720
 
 
2721
  if ($encrypt_cmd) {
 
2722
    $rcode = system("cd $basedir; $stream_cmd $relpath | $encrypt_cmd");
 
2723
  } else {
 
2724
    $rcode = system("cd $basedir; $stream_cmd $relpath");
 
2725
  }
 
2726
  return $rcode;
 
2727
}
 
2728
 
 
2729
 
2676
2730
=pod
2677
2731
 
2678
2732
=head1 NAME
2681
2735
 
2682
2736
=head1 SYNOPOSIS
2683
2737
 
2684
 
innobackupex [--compress] [--compress-threads=NUMBER-OF-THREADS]
 
2738
innobackupex [--compress] [--compress-threads=NUMBER-OF-THREADS] [--compress-chunk-size=CHUNK-SIZE]
 
2739
             [--encrypt=encryption_algorithm] [--encrypt-threads=NUMBER-OF-THREADS] [--encrypt-chunk-size=CHUNK-SIZE]
 
2740
             [--encrypt-key=literal_encryption_key] | [--encryption-key-file=MY.KEY]
2685
2741
             [--include=REGEXP] [--user=NAME]
2686
2742
             [--password=WORD] [--port=PORT] [--socket=SOCKET]
2687
2743
             [--no-timestamp] [--ibbackup=IBBACKUP-BINARY]
2765
2821
for parallel compression. It is passed directly to the xtrabackup
2766
2822
child process. Try 'xtrabackup --help' for more details.
2767
2823
 
 
2824
=item --compress-chunk-size
 
2825
 
 
2826
This option specifies the size of the internal working buffer for each
 
2827
compression thread, measured in kilobytes. It is passed directly to the
 
2828
xtrabackup child process. Try 'xtrabackup --help' for more details.
 
2829
 
2768
2830
=item --copy-back
2769
2831
 
2770
2832
Copy all the files in a previously made backup from the backup directory to their original locations.
2781
2843
 
2782
2844
This option specifies what extra file to read the default MySQL options from before the standard defaults-file.  The option accepts a string argument. It is also passed directly to xtrabackup's --defaults-extra-file option. See the xtrabackup documentation for details.
2783
2845
 
 
2846
=item --encrypt=ENCRYPTION_ALGORITHM
 
2847
 
 
2848
This option instructs xtrabackup to encrypt backup copies of InnoDB data
 
2849
files using the algorithm specified in the ENCRYPTION_ALGORITHM.
 
2850
It is passed directly to the xtrabackup child process.
 
2851
Try 'xtrabackup --help' for more details.
 
2852
 
 
2853
=item --encrypt-key=ENCRYPTION_KEY
 
2854
 
 
2855
This option instructs xtrabackup to use the given ENCRYPTION_KEY when using the --encrypt option.
 
2856
It is passed directly to the xtrabackup child process.
 
2857
Try 'xtrabackup --help' for more details.
 
2858
 
 
2859
=item --encrypt-key-file=ENCRYPTION_KEY_FILE
 
2860
 
 
2861
This option instructs xtrabackup to use the encryption key stored in the given ENCRYPTION_KEY_FILE when using the --encrypt option.
 
2862
It is passed directly to the xtrabackup child process.
 
2863
Try 'xtrabackup --help' for more details.
 
2864
 
 
2865
=item --encrypt-threads
 
2866
 
 
2867
This option specifies the number of worker threads that will be used
 
2868
for parallel encryption. It is passed directly to the xtrabackup
 
2869
child process. Try 'xtrabackup --help' for more details.
 
2870
 
 
2871
=item --encrypt-chunk-size
 
2872
 
 
2873
This option specifies the size of the internal working buffer for each
 
2874
encryption thread, measured in kilobytes. It is passed directly to the
 
2875
xtrabackup child process. Try 'xtrabackup --help' for more details.
 
2876
 
2784
2877
=item --export
2785
2878
 
2786
2879
This option is passed directly to xtrabackup's --export option. It enables exporting individual tables for import into another server. See the xtrabackup documentation for details.