1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#!/usr/bin/env python
#
# Copyright (c) 2008-2012 WiredTiger, Inc.
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
import shutil, string, os
from suite_subprocess import suite_subprocess
import wiredtiger, wttest
from helper import compareFiles, confirmDoesNotExist, \
complexPopulate, complexPopulateCheck, simplePopulate, simplePopulateCheck
# test_backup.py
# Utilities: wt backup
# Test backup (both backup cursors and the wt backup command).
class test_backup(wttest.WiredTigerTestCase, suite_subprocess):
dir='backup.dir' # Backup directory name
pfx = 'test_backup'
objs = [
( 'file:' + pfx + '.1', simplePopulate),
( 'file:' + pfx + '.2', simplePopulate),
('table:' + pfx + '.3', simplePopulate),
('table:' + pfx + '.4', simplePopulate),
('table:' + pfx + '.5', complexPopulate),
('table:' + pfx + '.6', complexPopulate),
]
# Populate a set of objects.
def populate(self):
for i in self.objs:
i[1](self, i[0], 'key_format=S', 100)
# Compare the original and backed-up files using the wt dump command.
def compare(self, uri):
self.runWt(['dump', uri], outfilename='orig')
self.runWt(['-h', self.dir, 'dump', uri], outfilename='backup')
compareFiles(self, 'orig', 'backup')
# Test simple backup cursor open/close.
def test_cursor_simple(self):
cursor = self.session.open_cursor('backup:', None, None)
cursor.close()
# Test you can't have more than one backup cursor open at a time.
def test_cursor_single(self):
cursor = self.session.open_cursor('backup:', None, None)
msg = '/there is already a backup cursor open/'
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.open_cursor('backup:', None, None), msg)
cursor.close()
# Test backup of a database using the wt backup command.
def test_backup_database(self):
self.populate()
os.mkdir(self.dir)
self.runWt(['backup', self.dir])
# Make sure all the files were copied.
self.runWt(['list'], outfilename='outfile.orig')
self.runWt(['-h', self.dir, 'list'], outfilename='outfile.backup')
compareFiles(self, 'outfile.orig', 'outfile.backup')
# And that the contents are the same.
for i in self.objs:
self.compare(i[0])
# Check that a URI doesn't exist, both the meta-data and the file names.
def confirmPathDoesNotExist(self, uri):
conn = wiredtiger.wiredtiger_open(self.dir)
session = conn.open_session()
self.assertRaises(wiredtiger.WiredTigerError,
lambda: session.open_cursor(uri, None, None))
conn.close()
import glob
self.assertEqual(
glob.glob(self.dir + '*' + uri.split(":")[1] + '*'), [],
'confirmPathDoesNotExist: URI exists, file name matching \"' +
uri.split(":")[1] + '\" found')
# Backup a set of chosen tables/files using the wt backup command.
def backup_table(self, l):
# Remove any previous backup directories.
shutil.rmtree(self.dir, True)
os.mkdir(self.dir)
# Build a command line of objects to back up and run wt.
o = 'backup'
for i in range(0, len(self.objs)):
if i in l:
o += ' -t ' + self.objs[i][0]
o += ' ' + self.dir
self.runWt(o.split())
# Confirm the objects we backed up exist, with correct contents.
for i in range(0, len(self.objs)):
if i in l:
self.compare(self.objs[i][0])
# Confirm the other objects don't exist.
for i in range(0, len(self.objs)):
if i not in l:
self.confirmPathDoesNotExist(self.objs[i][0])
# Test backup of database subsets.
def test_backup_table(self):
self.populate()
self.backup_table([0,2,4])
self.backup_table([1,3,5])
self.backup_table([0,1,2])
self.backup_table([3,4,5])
# Test backup of random object types fails.
def test_illegal_objects(self):
for target in ('colgroup:xxx', 'index:xxx'):
msg = '/invalid backup target object/'
config = 'target=("%s")' % target
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.open_cursor('backup:', None, config), msg)
# Test cursor reset runs through the list twice.
def test_cursor_reset(self):
self.populate()
cursor = self.session.open_cursor('backup:', None, None)
i = 0
while True:
ret = cursor.next()
if ret != 0:
break;
i += 1
self.assertEqual(ret, wiredtiger.WT_NOTFOUND)
total = i * 2
cursor.reset()
while True:
ret = cursor.next()
if ret != 0:
break;
i += 1
self.assertEqual(ret, wiredtiger.WT_NOTFOUND)
self.assertEqual(i, total)
# Test that named checkpoints can't be deleted while backup cursors are
# open, but that normal checkpoints continue to work.
def test_checkpoint_delete(self):
self.populate()
# Confirm checkpoints are being deleted.
self.session.checkpoint("name=one")
self.session.checkpoint("name=two,drop=(one)")
msg = '/no "one" checkpoint found/'
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.open_cursor(
self.objs[0][0], None, "checkpoint=one"), msg)
# Confirm opening a backup cursor causes checkpoint to fail if dropping
# a named checkpoint, but does not stop a default checkpoint.
cursor = self.session.open_cursor('backup:', None, None)
self.session.checkpoint()
msg = '/checkpoints cannot be dropped/'
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.checkpoint("name=three,drop=(two)"), msg)
self.session.checkpoint()
self.session.checkpoint()
cursor.close()
if __name__ == '__main__':
wttest.run()
|