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
28
from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
30
server_requirements = [['--innodb-file-per-table']]
34
# we explicitly use the --no-timestamp option
35
# here. We will be using a generic / vanilla backup dir
38
class basicTest(mysqlBaseTestCase):
41
master_server = servers[0] # assumption that this is 'master'
42
backup_path = os.path.join(master_server.vardir, 'full_backup')
44
for del_path in [backup_path]:
45
if os.path.exists(del_path):
46
shutil.rmtree(del_path)
48
def test_bug722638(self):
49
self.servers = servers
50
logging = test_executor.logging
51
innobackupex = test_executor.system_manager.innobackupex_path
52
xtrabackup = test_executor.system_manager.xtrabackup_path
53
master_server = servers[0] # assumption that this is 'master'
54
backup_path = os.path.join(master_server.vardir, 'full_backup')
55
output_path = os.path.join(master_server.vardir, 'innobackupex.out')
56
suspended_file = os.path.join(backup_path, 'xtrabackup_debug_sync')
57
exec_path = os.path.dirname(innobackupex)
59
# test to ensure we have a debug build
61
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
62
if 'debug-sync' not in output:
63
logging.warning("Requires --debug-sync support. Skipping test...")
66
# populate our server with a test bed
67
queries = [ "CREATE TABLE t1(a INT) ENGINE=InnoDB"
68
, "INSERT INTO t1 VALUES (1), (2), (3)"
69
, "CREATE TABLE t2(a INT) ENGINE=InnoDB"
70
, "INSERT INTO t2 VALUES (1), (2), (3)"
71
, "CREATE TABLE t3(a INT) ENGINE=InnoDB"
72
, "INSERT INTO t3 VALUES (1), (2), (3)"
73
, "CREATE TABLE t4_old(a INT) ENGINE=InnoDB"
74
, "INSERT INTO t4_old VALUES (1), (2), (3)"
76
retcode, result = self.execute_queries(queries, master_server)
77
self.assertEqual(retcode, 0, msg=result)
81
, "--defaults-file=%s" %master_server.cnf_file
82
, "--datadir=%s" %master_server.datadir
84
, "--target-dir=%s" %backup_path
85
, '--debug-sync="data_copy_thread_func"'
87
output_file = open(output_path,'w')
88
xtrabackup_subproc = subprocess.Popen( cmd
90
, env=test_executor.working_environment
91
, stdout = output_file
92
, stderr = subprocess.STDOUT
95
# Wait for the xtrabackup_suspended file to be created
98
while timeout and not os.path.exists(suspended_file):
102
# Modify the original tables, then change space_ids by running DDL
103
queries = [ "INSERT INTO t1 VALUES (4), (5), (6)"
105
, "CREATE TABLE t1(a CHAR(1)) ENGINE=InnoDB"
106
, 'INSERT INTO t1 VALUES ("1"), ("2"), ("3")'
107
, "INSERT INTO t2 VALUES (4), (5), (6)"
108
, "ALTER TABLE t2 MODIFY a BIGINT"
109
, "INSERT INTO t2 VALUES (7), (8), (9)"
110
, "INSERT INTO t3 VALUES (4), (5), (6)"
112
, "INSERT INTO t3 VALUES (7), (8), (9)"
113
, "INSERT INTO t4_old VALUES (4), (5), (6)"
114
, "ALTER TABLE t4_old RENAME t4"
115
, "INSERT INTO t4 VALUES (7), (8), (9)"
117
retcode, result = self.execute_queries(queries, master_server)
118
self.assertEqual(retcode, 0, msg=result)
123
query = "CHECKSUM TABLE t%d" %(i+1)
124
retcode, result = self.execute_query(query, master_server)
125
self.assertEqual(retcode, 0, msg=result)
126
orig_checksums.append(result)
128
# Resume the xtrabackup process and remove the suspended file
129
xtrabackup_subproc.send_signal(signal.SIGCONT)
131
xtrabackup_subproc.wait()
133
output_file = open(output_path,'r')
134
output = ''.join(output_file.readlines())
135
self.assertEqual(xtrabackup_subproc.returncode,0,msg="Xtrabackup: uh-oh >;)")
137
# Clear our schema so we know the backup restored
138
queries = [ "DROP SCHEMA test"
139
, "CREATE SCHEMA test"
141
retcode, result = self.execute_queries(queries,master_server)
142
self.assertEqual(retcode, 0, result)
144
# prepare our main backup
147
, "--datadir=%s" %master_server.datadir
148
, "--use-memory=500M"
149
, "--target-dir=%s" %backup_path
152
retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
153
self.assertTrue(retcode==0,output)
155
# do final prepare on main backup
158
, "--datadir=%s" %master_server.datadir
159
, "--use-memory=500M"
160
, "--target-dir=%s" %backup_path
163
#retcode, output = self.execute_cmd(cmd, output_path, exec_path, True)
164
#self.assertTrue(retcode==0,output)
170
clear_paths = [master_server.datadir
171
,os.path.join(master_server.datadir,'test')
173
for clear_path in clear_paths:
174
for file_name in os.listdir(clear_path):
175
if file_name.startswith('ib_logfile') or file_name == 'ibdata1' or file_name.endswith('.ibd'):
176
os.remove(os.path.join(clear_path,file_name))
178
# copy our data files back
179
for root, dirs, files in os.walk(backup_path):
181
file_info = root.split(backup_path)[1]
182
for file_name in files:
183
# We do a quick check to make sure
184
# no names start with '/' as os.path
185
# throws a hissy when it sees such things
186
if file_info.startswith('/'):
187
file_info = file_info[1:]
188
if file_name.startswith('/'):
189
file_name = file_name[1:]
190
to_path = os.path.join(master_server.datadir
193
new_dir = os.path.dirname(to_path)
195
if not os.path.exists(new_dir):
198
logging.error("Could not create directory: %s | %s" %(new_dir, e))
200
shutil.copy(os.path.join(root,file_name),to_path)
202
logging.error( "ERROR: Could not copy file: %s | %s" %(file_name, e))
204
# restart server (and ensure it doesn't crash)
205
master_server.start()
206
self.assertTrue(master_server.status==1, 'Server failed restart from restored datadir...')
208
query = "SHOW TABLES IN test"
209
retcode, result = self.execute_query(query, master_server)
210
logging.test_debug("%s: %s" %(query, result))
214
query = "CHECKSUM TABLE t%d" %(i+1)
215
retcode, result = self.execute_query(query, master_server)
216
self.assertEqual(retcode, 0, msg=result)
217
self.assertEqual(result, orig_checksums[i], msg = "%s: %s || %s" %(query, orig_checksums[i], result))
220
server_manager.reset_servers(test_executor.name)