2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2011 Patrick Crews
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
28
server_requirements = [['--innodb-file-per-table']]
32
# we explicitly use the --no-timestamp option
33
# here. We will be using a generic / vanilla backup dir
36
class basicTest(mysqlBaseTestCase):
39
master_server = servers[0] # assumption that this is 'master'
40
backup_path = os.path.join(master_server.vardir, '_xtrabackup')
42
for del_path in [backup_path]:
43
if os.path.exists(del_path):
44
shutil.rmtree(del_path)
46
def test_ib_stream(self):
47
"""Tests for tar4ibd + symlinks (bug #387587)"""
48
innobackupex = test_executor.system_manager.innobackupex_path
49
xtrabackup = test_executor.system_manager.xtrabackup_path
50
master_server = servers[0] # assumption that this is 'master'
51
backup_path = os.path.join(master_server.vardir, '_xtrabackup')
52
tar_file_path = os.path.join(backup_path,'out.tar')
53
output_path = os.path.join(master_server.vardir, 'innobackupex.out')
54
exec_path = os.path.dirname(innobackupex)
56
# populate our server with a test bed
57
test_cmd = "./gentest.pl --gendata=conf/percona/percona.zz"
58
retcode, output = self.execute_randgen(test_cmd, test_executor, master_server)
60
# Move some of our .ibd files and make symlinks
61
shutil.move( os.path.join(master_server.datadir,'test/CC.ibd')
62
, master_server.vardir)
63
os.symlink(os.path.join(master_server.vardir,'CC.ibd')
64
,os.path.join(master_server.datadir,'test/CC.ibd'))
66
shutil.move( os.path.join(master_server.datadir,'test/BB.ibd')
67
, master_server.vardir)
68
os.symlink(os.path.join(master_server.vardir,'BB.ibd')
69
,os.path.join(master_server.vardir,'BB_link.ibd'))
70
os.symlink(os.path.join(master_server.vardir,'BB_link.ibd')
71
,os.path.join(master_server.datadir,'test/BB.ibd'))
79
, "--defaults-file=%s" %master_server.cnf_file
82
, "--port=%d" %master_server.master_port
85
, "--ibbackup=%s" %xtrabackup
86
, "%s > %s" %(backup_path,tar_file_path)
89
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
90
self.assertTrue(retcode==0,output)
95
# extract our backup tarball
96
cmd = "tar -ivxf %s" %tar_file_path
97
retcode, output = self.execute_cmd(cmd, output_path, backup_path, True)
98
self.assertEqual(retcode,0,output)
99
# Check for Bug 723318 - seems quicker than separate test case
100
self.assertTrue('xtrabackup_binary' in os.listdir(backup_path)
101
, msg = "Bug723318: xtrabackup_binary not included in tar archive when streaming")
103
# do prepare on backup
107
, "--use-memory=500M"
108
, "--ibbackup=%s" %xtrabackup
112
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
113
self.assertEqual(retcode,0,output)
116
shutil.rmtree(master_server.datadir)
117
os.mkdir(master_server.datadir)
119
# Remove our symlinks
120
os.remove(os.path.join(master_server.vardir,'CC.ibd'))
121
os.remove(os.path.join(master_server.vardir,'BB.ibd'))
122
os.remove(os.path.join(master_server.vardir,'BB_link.ibd'))
124
# restore from backup
126
, "--defaults-file=%s" %master_server.cnf_file
128
, "--ibbackup=%s" %(xtrabackup)
132
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
133
self.assertEqual(retcode,0, output)
135
# restart server (and ensure it doesn't crash)
136
master_server.start()
137
self.assertEqual(master_server.status,1, 'Server failed restart from restored datadir...')
139
# Check the server is ok
140
query = "SELECT COUNT(*) FROM test.BB"
141
expected_output = ((10L,),)
142
retcode, output = self.execute_query(query, master_server)
143
self.assertEqual(output, expected_output, msg = "%s || %s" %(output, expected_output))
145
query = "SELECT COUNT(*) FROM test.CC"
146
expected_output = ((100L,),)
147
retcode, output = self.execute_query(query, master_server)
148
self.assertEqual(output, expected_output, msg = "%s || %s" %(output, expected_output))
152
server_manager.reset_servers(test_executor.name)