MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
innodb-util.inc
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 perl;
8 use File::Copy;
9 use File::Spec;
10 
11 sub ib_normalize_path {
12  my ($path) = @_;
13 }
14 
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";
21 
22  my @args = (File::Spec->catfile($datadir, $db, $ibd_file),
23  File::Spec->catfile($tmpd, $ibd_file));
24 
25  copy(@args) or die "copy @args failed: $!";
26 
27  my @args = (File::Spec->catfile($datadir, $db, $cfg_file),
28  File::Spec->catfile($tmpd, $cfg_file));
29 
30  copy(@args) or die "copy @args failed: $!";
31 }
32 
33 sub ib_cleanup {
34  my ($db, $table) = @_;
35  my $datadir = $ENV{'MYSQLD_DATADIR'};
36  my $cfg_file = sprintf("%s.cfg", $table);
37 
38  print "unlink: $cfg_file\n";
39 
40  # These may or may not exist
41  unlink(File::Spec->catfile($datadir, $db, $cfg_file));
42 }
43 
44 sub ib_unlink_tablespace {
45  my ($db, $table) = @_;
46  my $datadir = $ENV{'MYSQLD_DATADIR'};
47  my $ibd_file = sprintf("%s.ibd", $table);
48 
49  print "unlink: $ibd_file\n";
50  # This may or may not exist
51  unlink(File::Spec->catfile($datadir, $db, $ibd_file));
52 
53  ib_cleanup($db, $table);
54 }
55 
56 sub ib_backup_tablespaces {
57  my ($db, @tables) = @_;
58 
59  foreach my $table (@tables) {
60  print "backup: $table\n";
61  ib_backup_tablespace($db, $table);
62  }
63 }
64 
65 sub ib_discard_tablespace { }
66 
67 sub ib_discard_tablespaces { }
68 
69 sub ib_restore_cfg_file {
70  my ($tmpd, $datadir, $db, $table) = @_;
71  my $cfg_file = sprintf("%s.cfg", $table);
72 
73  my @args = (File::Spec->catfile($tmpd, $cfg_file),
74  File::Spec->catfile($datadir, "$db", $cfg_file));
75 
76  copy(@args) or die "copy @args failed: $!";
77 }
78 
79 sub ib_restore_ibd_file {
80  my ($tmpd, $datadir, $db, $table) = @_;
81  my $ibd_file = sprintf("%s.ibd", $table);
82 
83  my @args = (File::Spec->catfile($tmpd, $ibd_file),
84  File::Spec->catfile($datadir, $db, $ibd_file));
85 
86  copy(@args) or die "copy @args failed: $!";
87 }
88 
89 sub ib_restore_tablespace {
90  my ($db, $table) = @_;
91  my $datadir = $ENV{'MYSQLD_DATADIR'};
92  my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
93 
94  ib_restore_cfg_file($tmpd, $datadir, $db, $table);
95  ib_restore_ibd_file($tmpd, $datadir, $db, $table);
96 }
97 
98 sub ib_restore_tablespaces {
99  my ($db, @tables) = @_;
100 
101  foreach my $table (@tables) {
102  print "restore: $table .ibd and .cfg files\n";
103  ib_restore_tablespace($db, $table);
104  }
105 }
106 
107 sub ib_restore_cfg_files {
108  my ($db, @tables) = @_;
109  my $datadir = $ENV{'MYSQLD_DATADIR'};
110  my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
111 
112  foreach my $table (@tables) {
113  print "restore: $table .cfg file\n";
114  ib_restore_cfg_file($tmpd, $datadir, $db, $table);
115  }
116 }
117 
118 sub ib_restore_ibd_files {
119  my ($db, @tables) = @_;
120  my $datadir = $ENV{'MYSQLD_DATADIR'};
121  my $tmpd = $ENV{'MYSQLTEST_VARDIR'} . "/tmp";
122 
123  foreach my $table (@tables) {
124  print "restore: $table .ibd file\n";
125  ib_restore_ibd_file($tmpd, $datadir, $db, $table);
126  }
127 }
128 EOF