2 # Utility functions to copy files for WL#5522
4 # All the tables must be in the same database, you can call it like so:
5 # ib_backup_tablespaces("test", "t1", "blah", ...).
11 sub ib_normalize_path {
15 sub ib_backup_tablespace {
16 my ($db, $table) = @_;
17 my $datadir = $ENV{
'MYSQLD_DATADIR'};
18 my $cfg_file = sprintf(
"%s.cfg", $table);
19 my $ibd_file = sprintf(
"%s.ibd", $table);
20 my $tmpd = $ENV{
'MYSQLTEST_VARDIR'} .
"/tmp";
22 my @args = (File::Spec->catfile($datadir, $db, $ibd_file),
23 File::Spec->catfile($tmpd, $ibd_file));
25 copy(@args) or die "copy @args failed: $!";
27 my @args = (File::Spec->catfile($datadir, $db, $cfg_file),
28 File::Spec->catfile($tmpd, $cfg_file));
30 copy(@args) or die "copy @args failed: $!";
34 my ($db, $table) = @_;
35 my $datadir = $ENV{
'MYSQLD_DATADIR'};
36 my $cfg_file = sprintf(
"%s.cfg", $table);
38 print
"unlink: $cfg_file\n";
40 # These may or may not exist
41 unlink(File::Spec->catfile($datadir, $db, $cfg_file));
44 sub ib_unlink_tablespace {
45 my ($db, $table) = @_;
46 my $datadir = $ENV{
'MYSQLD_DATADIR'};
47 my $ibd_file = sprintf(
"%s.ibd", $table);
49 print
"unlink: $ibd_file\n";
50 # This may or may not exist
51 unlink(File::Spec->catfile($datadir, $db, $ibd_file));
53 ib_cleanup($db, $table);
56 sub ib_backup_tablespaces {
57 my ($db, @tables) = @_;
59 foreach my $table (@tables) {
60 print
"backup: $table\n";
61 ib_backup_tablespace($db, $table);
65 sub ib_discard_tablespace { }
67 sub ib_discard_tablespaces { }
69 sub ib_restore_cfg_file {
70 my ($tmpd, $datadir, $db, $table) = @_;
71 my $cfg_file = sprintf(
"%s.cfg", $table);
73 my @args = (File::Spec->catfile($tmpd, $cfg_file),
74 File::Spec->catfile($datadir,
"$db", $cfg_file));
76 copy(@args) or die "copy @args failed: $!";
79 sub ib_restore_ibd_file {
80 my ($tmpd, $datadir, $db, $table) = @_;
81 my $ibd_file = sprintf(
"%s.ibd", $table);
83 my @args = (File::Spec->catfile($tmpd, $ibd_file),
84 File::Spec->catfile($datadir, $db, $ibd_file));
86 copy(@args) or die "copy @args failed: $!";
89 sub ib_restore_tablespace {
90 my ($db, $table) = @_;
91 my $datadir = $ENV{
'MYSQLD_DATADIR'};
92 my $tmpd = $ENV{
'MYSQLTEST_VARDIR'} .
"/tmp";
94 ib_restore_cfg_file($tmpd, $datadir, $db, $table);
95 ib_restore_ibd_file($tmpd, $datadir, $db, $table);
98 sub ib_restore_tablespaces {
99 my ($db, @tables) = @_;
101 foreach my $table (@tables) {
102 print
"restore: $table .ibd and .cfg files\n";
103 ib_restore_tablespace($db, $table);
107 sub ib_restore_cfg_files {
108 my ($db, @tables) = @_;
109 my $datadir = $ENV{
'MYSQLD_DATADIR'};
110 my $tmpd = $ENV{
'MYSQLTEST_VARDIR'} .
"/tmp";
112 foreach my $table (@tables) {
113 print
"restore: $table .cfg file\n";
114 ib_restore_cfg_file($tmpd, $datadir, $db, $table);
118 sub ib_restore_ibd_files {
119 my ($db, @tables) = @_;
120 my $datadir = $ENV{
'MYSQLD_DATADIR'};
121 my $tmpd = $ENV{
'MYSQLTEST_VARDIR'} .
"/tmp";
123 foreach my $table (@tables) {
124 print
"restore: $table .ibd file\n";
125 ib_restore_ibd_file($tmpd, $datadir, $db, $table);