Debian Codegraph @

mysql-test/suite/encryption/include/innodb-util.pl

raw
1 #
2 # Utility functions to copy files for WL#5522
3 #
4 # All the tables must be in the same database, you can call it like so:
5 # ib_backup_tablespaces("test", "t1", "blah", ...).
6
7 use File::Copy;
8 use File::Spec;
9
10 sub ib_normalize_path {
11 my ($path) = @_;
12 }
13
14 sub ib_backup_tablespace {
15 my ($db, $table) = @_;
16 my $datadir = $ENV{'MYSQLD_DATADIR'};
17 my $cfg_file = sprintf("%s.cfg", $table);
18 my $ibd_file = sprintf("%s.ibd", $table);
19 my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
20
21 my @args = (File::Spec->catfile($datadir, $db, $ibd_file),
22 File::Spec->catfile($tmpd, $ibd_file));
23
24 copy(@args) or die "copy @args failed: $!";
25
26 my @args = (File::Spec->catfile($datadir, $db, $cfg_file),
27 File::Spec->catfile($tmpd, $cfg_file));
28
29 copy(@args) or die "copy @args failed: $!";
30 }
31
32 sub ib_cleanup {
33 my ($db, $table) = @_;
34 my $datadir = $ENV{'MYSQLD_DATADIR'};
35 my $cfg_file = sprintf("%s.cfg", $table);
36
37 print "unlink: $cfg_file\n";
38
39 # These may or may not exist
40 unlink(File::Spec->catfile($datadir, $db, $cfg_file));
41 }
42
43 sub ib_unlink_tablespace {
44 my ($db, $table) = @_;
45 my $datadir = $ENV{'MYSQLD_DATADIR'};
46 my $ibd_file = sprintf("%s.ibd", $table);
47
48 print "unlink: $ibd_file\n";
49 # This may or may not exist
50 unlink(File::Spec->catfile($datadir, $db, $ibd_file));
51
52 ib_cleanup($db, $table);
53 }
54
55 sub ib_backup_tablespaces {
56 my ($db, @tables) = @_;
57
58 foreach my $table (@tables) {
59 print "backup: $table\n";
60 ib_backup_tablespace($db, $table);
61 }
62 }
63
64 sub ib_discard_tablespace { }
65
66 sub ib_discard_tablespaces { }
67
68 sub ib_restore_cfg_file {
69 my ($tmpd, $datadir, $db, $table) = @_;
70 my $cfg_file = sprintf("%s.cfg", $table);
71
72 my @args = (File::Spec->catfile($tmpd, $cfg_file),
73 File::Spec->catfile($datadir, "$db", $cfg_file));
74
75 copy(@args) or die "copy @args failed: $!";
76 }
77
78 sub ib_restore_ibd_file {
79 my ($tmpd, $datadir, $db, $table) = @_;
80 my $ibd_file = sprintf("%s.ibd", $table);
81
82 my @args = (File::Spec->catfile($tmpd, $ibd_file),
83 File::Spec->catfile($datadir, $db, $ibd_file));
84
85 copy(@args) or die "copy @args failed: $!";
86 }
87
88 sub ib_restore_tablespace {
89 my ($db, $table) = @_;
90 my $datadir = $ENV{'MYSQLD_DATADIR'};
91 my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
92
93 ib_restore_cfg_file($tmpd, $datadir, $db, $table);
94 ib_restore_ibd_file($tmpd, $datadir, $db, $table);
95 }
96
97 sub ib_restore_tablespaces {
98 my ($db, @tables) = @_;
99
100 foreach my $table (@tables) {
101 print "restore: $table .ibd and .cfg files\n";
102 ib_restore_tablespace($db, $table);
103 }
104 }
105
106 sub ib_restore_cfg_files {
107 my ($db, @tables) = @_;
108 my $datadir = $ENV{'MYSQLD_DATADIR'};
109 my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
110
111 foreach my $table (@tables) {
112 print "restore: $table .cfg file\n";
113 ib_restore_cfg_file($tmpd, $datadir, $db, $table);
114 }
115 }
116
117 sub ib_restore_ibd_files {
118 my ($db, @tables) = @_;
119 my $datadir = $ENV{'MYSQLD_DATADIR'};
120 my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
121
122 foreach my $table (@tables) {
123 print "restore: $table .ibd file\n";
124 ib_restore_ibd_file($tmpd, $datadir, $db, $table);
125 }
126 }