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 = [[]]
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_bug733663(self):
47
innobackupex = test_executor.system_manager.innobackupex_path
48
xtrabackup = test_executor.system_manager.xtrabackup_path
49
master_server = servers[0] # assumption that this is 'master'
50
backup_path = os.path.join(master_server.vardir, '_xtrabackup')
51
tar_file_path = os.path.join(backup_path,'out.tar')
52
output_path = os.path.join(master_server.vardir, 'innobackupex.out')
53
stderr_path = os.path.join(master_server.vardir, 'innobackupex.err')
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)
66
, "--defaults-file=%s" %master_server.cnf_file
69
, "--port=%d" %master_server.master_port
72
, "--ibbackup=%s" %xtrabackup
73
, "%s > %s" %(backup_path,tar_file_path)
76
# The error was that innobackupex / xtrabackup
77
# didn't work when splitting stdout and stderr
78
stdout_file = open(output_path,'w')
79
stderr_file = open(stderr_path,'w')
80
cmd_subproc = subprocess.Popen( cmd
83
, stdout = stdout_file
84
, stderr = stderr_file
87
retcode = cmd_subproc.returncode
90
data_file = open(output_path,'r')
91
output = ''.join(data_file.readlines())
92
self.assertTrue(retcode==0,output)
97
# extract our backup tarball
98
cmd = "tar -ivxf %s" %tar_file_path
99
retcode, output = self.execute_cmd(cmd, output_path, backup_path, True)
100
self.assertEqual(retcode,0,output)
101
# Check for Bug 723318 - seems quicker than separate test case
102
self.assertTrue('xtrabackup_binary' in os.listdir(backup_path)
103
, msg = "Bug723318: xtrabackup_binary not included in tar archive when streaming")
105
# do prepare on backup
109
, "--use-memory=500M"
110
, "--ibbackup=%s" %xtrabackup
114
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
115
self.assertEqual(retcode,0,output)
118
shutil.rmtree(master_server.datadir)
119
os.mkdir(master_server.datadir)
121
# restore from backup
123
, "--defaults-file=%s" %master_server.cnf_file
125
, "--ibbackup=%s" %(xtrabackup)
129
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
130
self.assertEqual(retcode,0, output)
132
# restart server (and ensure it doesn't crash)
133
master_server.start()
134
self.assertEqual(master_server.status,1, 'Server failed restart from restored datadir...')
136
# Check the server is ok
137
query = "SELECT COUNT(*) FROM test.DD"
138
expected_output = ((100L,),)
139
retcode, output = self.execute_query(query, master_server)
140
self.assertEqual(output, expected_output, msg = "%s || %s" %(output, expected_output))
144
server_manager.reset_servers(test_executor.name)