Debian Codegraph @

docs/gsg_txn/CXX/backuprestore.html

raw
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Backup Procedures</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
10 <link rel="up" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
11 <link rel="prev" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
12 <link rel="next" href="recovery.html" title="Recovery Procedures" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Backup Procedures</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="filemanagement.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 5. Managing DB Files</th>
26 <td width="20%" align="right"> <a accesskey="n" href="recovery.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title" style="clear: both"><a id="backuprestore"></a>Backup Procedures</h2>
36 </div>
37 </div>
38 </div>
39 <div class="toc">
40 <dl>
41 <dt>
42 <span class="sect2">
43 <a href="backuprestore.html#copyutilities">About Unix Copy Utilities</a>
44 </span>
45 </dt>
46 <dt>
47 <span class="sect2">
48 <a href="backuprestore.html#standardbackup">Offline Backups</a>
49 </span>
50 </dt>
51 <dt>
52 <span class="sect2">
53 <a href="backuprestore.html#hotbackup">Hot Backup</a>
54 </span>
55 </dt>
56 <dt>
57 <span class="sect2">
58 <a href="backuprestore.html#incrementalbackups">Incremental Backups</a>
59 </span>
60 </dt>
61 </dl>
62 </div>
63 <p>
64 <span class="emphasis"><em>Durability</em></span> is an important part of your
65 transactional guarantees. It means that once a transaction has been
66 successfully committed, your application will always see the results of that
67 transaction.
68 </p>
69 <p>
70 Of course, no software algorithm can guarantee durability in the face of physical data loss. Hard drives
71 can fail, and if you have not copied your data to locations other than your primary disk drives,
72 then you will lose data when those drives fail. Therefore, in order to truly obtain a durability
73 guarantee, you need to ensure that any data stored on disk is backed up to secondary or alternative storage,
74 such as secondary disk drives, or offline tapes.
75 </p>
76 <p>
77 There are three different types of backups that you can
78 perform with DB databases and log files. They are:
79 </p>
80 <div class="itemizedlist">
81 <ul type="disc">
82 <li>
83 <p>
84 Offline backups
85 </p>
86 <p>
87 This type of backup is perhaps the easiest to perform as it
88 involves simply copying database and log files to an
89 offline storage area. It also gives you a snapshot of the
90 database at a fixed, known point in time. However, you
91 cannot perform this type of a backup while you are performing
92 writes to the database.
93 </p>
94 </li>
95 <li>
96 <p>
97 Hot backups
98 </p>
99 <p>
100 This type of backup gives you a snapshot of your database.
101 Since your application can be writing to the database at the time that the
102 snapshot is being taken, you do not necessarily know what
103 the exact state of the database is for that given snapshot.
104 </p>
105 </li>
106 <li>
107 <p>
108 Incremental backups
109 </p>
110 <p>
111 This type of backup refreshes a previously performed backup.
112 </p>
113 </li>
114 </ul>
115 </div>
116 <p>
117 Once you have performed a backup, you can
118 perform <span class="emphasis"><em>catastrophic recovery</em></span> to restore
119 your databases from the backup. See
120 <a class="xref" href="recovery.html#catastrophicrecovery" title="Catastrophic Recovery">Catastrophic Recovery</a>
121 for more information.
122 </p>
123 <p>
124 Note that you can also maintain a hot failover. See
125 <a class="xref" href="hotfailover.html" title="Using Hot Failovers">Using Hot Failovers</a>
126 for more information.
127 </p>
128 <div class="sect2" lang="en" xml:lang="en">
129 <div class="titlepage">
130 <div>
131 <div>
132 <h3 class="title"><a id="copyutilities"></a>About Unix Copy Utilities</h3>
133 </div>
134 </div>
135 </div>
136 <p>
137
138 If you are copying database files you must copy databases atomically,
139 in multiples of the database page size. In other words, the reads made by
140 the copy program must not be interleaved with writes by
141 other threads of control, and the copy program must read the
142 databases in multiples of the underlying database page size.
143 Generally, this is not a problem because operating systems
144 already make this guarantee and system utilities normally
145 read in power-of-2 sized chunks, which are larger than the
146 largest possible Berkeley DB database page size.
147 </p>
148 <p>
149 On some platforms (most notably, some releases of Solaris), the copy utility (<code class="literal">cp</code>) was
150 implemented using the <code class="function">mmap()</code> system call rather than the
151 <code class="function">read()</code> system call. Because <code class="function">mmap()</code> did not make the same
152 guarantee of read atomicity as did <code class="function">read()</code>, the <code class="literal">cp</code> utility
153 could create corrupted copies of the databases.
154 </p>
155 <p>
156 Also, some platforms have implementations of the <code class="literal">tar</code> utility that performs 10KB block
157 reads by default. Even when an output block size is specified, the utility will still not read the
158 underlying databases in multiples of the specified block size. Again, the result can be a corrupted backup.
159 </p>
160 <p>
161 To fix these problems, use the <code class="literal">dd</code> utility instead of <code class="literal">cp</code> or
162 <code class="literal">tar</code>. When you use <code class="literal">dd</code>, make sure you specify a block size that is
163 equal to, or an even multiple of, your database page size. Finally, if you plan to use a system
164 utility to copy database files, you may want to use a system call trace utility (for example,
165 <code class="literal">ktrace</code> or <code class="literal">truss</code>) to make sure you are not using a I/O size that is
166 smaller than your database page size. You can also use these utilities to make sure the system utility is
167 not using a system call other than <code class="function">read()</code>.
168 </p>
169 </div>
170 <div class="sect2" lang="en" xml:lang="en">
171 <div class="titlepage">
172 <div>
173 <div>
174 <h3 class="title"><a id="standardbackup"></a>Offline Backups</h3>
175 </div>
176 </div>
177 </div>
178 <p>
179 To create an offline backup:
180 </p>
181 <div class="orderedlist">
182 <ol type="1">
183 <li>
184 <p>
185 Commit or abort all on-going transactions.
186 </p>
187 </li>
188 <li>
189 <p>
190 Pause all database writes.
191 </p>
192 </li>
193 <li>
194 <p>
195 Force a checkpoint. See
196 <a class="xref" href="filemanagement.html#checkpoints" title="Checkpoints">Checkpoints</a>
197 for details.
198 </p>
199 </li>
200 <li>
201 <p>
202 Copy all your database files to the backup location.
203 <span>
204 Note that you can simply copy all of the database
205 files, or you can determine which database files
206 have been written during the lifetime of the current
207 logs. To do this, use either the
208 <span>
209
210 <code class="methodname">DbEnv::log_archive()</code>
211 method with the <code class="literal">DB_ARCH_DATA</code>
212 option,
213 </span>
214
215
216 or use the <span class="command"><strong>db_archive</strong></span>
217 command with the <code class="literal">-s</code> option.
218 </span>
219 </p>
220 <p>
221 However, be aware that backing up just the modified databases only works if you have all of your
222 log files. If you have been removing log files for any reason then using
223 <span>
224 <code class="methodname">log_archive()</code>
225 </span>
226
227
228 can result in an
229 unrecoverable backup because you might not be notified of a database file that was modified.
230 </p>
231 </li>
232 <li>
233 <p>
234 Copy the <span class="emphasis"><em>last</em></span> log file to your backup location.
235 Your log files are named
236 <code class="literal">log.<span class="emphasis"><em>xxxxxxxxxx</em></span></code>,
237 where <span class="emphasis"><em>xxxxxxxxxx</em></span> is a
238 sequential number. The last log file is the file
239 with the highest number.
240 </p>
241 </li>
242 </ol>
243 </div>
244 </div>
245 <div class="sect2" lang="en" xml:lang="en">
246 <div class="titlepage">
247 <div>
248 <div>
249 <h3 class="title"><a id="hotbackup"></a>Hot Backup</h3>
250 </div>
251 </div>
252 </div>
253 <p>
254 To create a hot backup, you do not have to stop database
255 operations. Transactions may be on-going and you can be writing
256 to your database at the time of the backup. However, this means
257 that you do not know exactly what the state of your database is
258 at the time of the backup.
259 </p>
260 <p>
261 You can use the <span class="command"><strong>db_hotbackup</strong></span> command
262 line utility to create a hot backup. This program
263 optionally runs a checkpoint, and then copies all necessary
264 files to a target directory.
265 </p>
266 <p>
267 You can also create your own hot backup facility using the
268
269 <code class="methodname">DbEnv::backup()</code>
270
271 method.
272 </p>
273 <p>
274 Alternatively, you can manually create a hot backup as follows:
275 </p>
276 <div class="orderedlist">
277 <ol type="1">
278 <li>
279 <p>
280 <span>
281 Set the <code class="literal">DB_HOTBACKUP_IN_PROGRESS</code> flag in your environment.
282 </span>
283
284
285 <span>
286 For more information, see the
287
288
289 <a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/api_reference/CXX/envset_flags.html" target="_top">
290 DbEnv::set_flags() API reference page.
291 </a>
292
293 </span>
294
295 </p>
296 </li>
297 <li>
298 <p>
299 Copy all your database files to the backup location.
300 <span>
301 Note that you can simply copy all of the database
302 files, or you can determine which database files
303 have been written during the lifetime of the current
304 logs. To do this, use either the
305 <span>
306
307 <code class="methodname">DbEnv::log_archive()</code>
308 with the <code class="literal">DB_ARCH_DATA</code>
309 option,
310 </span>
311
312
313 or use the <span class="command"><strong>db_archive</strong></span>
314 command with the <code class="literal">-s</code> option.
315 </span>
316 </p>
317 </li>
318 <li>
319 <p>
320 Copy all logs to your backup location.
321 </p>
322 </li>
323 <li>
324 <p>
325 <span>
326 Reset the <code class="literal">DB_HOTBACKUP_IN_PROGRESS</code> flag.
327 </span>
328
329 </p>
330 </li>
331 </ol>
332 </div>
333 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
334 <h3 class="title">Note</h3>
335 <p>
336 It is important to copy your database files <span class="emphasis"><em>and
337 then</em></span> your logs. In this way,
338 you can complete or roll back any database operations that were only partially completed
339 when you copied the databases.
340 </p>
341 </div>
342 </div>
343 <div class="sect2" lang="en" xml:lang="en">
344 <div class="titlepage">
345 <div>
346 <div>
347 <h3 class="title"><a id="incrementalbackups"></a>Incremental Backups</h3>
348 </div>
349 </div>
350 </div>
351 <p>
352 Once you have created a full backup (that is, either a
353 offline or hot backup), you can create incremental backups.
354 To do this, simply copy all of your currently existing log
355 files to your backup location.
356 </p>
357 <p>
358 Incremental backups do not require you to run a checkpoint
359 or to cease database write operations.
360 </p>
361 <p>
362 If your application uses the transactional bulk insert
363 optimization, it is important to know that a database
364 copy taken prior to a bulk loading event can no longer
365 be used as the target of an incremental backup. This
366 is true because bulk loading omits logging of some
367 record insertions, so recovery cannot roll forward
368 these insertions. It is recommended that a full
369 backup be scheduled following a bulk loading event.
370 </p>
371 <p>
372 <span>
373 For more information, see the description of the <code class="literal">DB_TXN_BULK</code>
374 flag in the
375
376
377
378 <a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/api_reference/CXX/txnbegin.html" target="_top">
379 DbEnv::txn_begin() API reference page.
380 </a>
381
382 </span>
383
384 </p>
385 <p>
386 When you are working with incremental backups, remember
387 that the greater the number of log files contained in
388 your backup, the longer recovery will take.
389 You should run full backups
390 on some interval, and then do incremental backups on a shorter interval.
391 How frequently you need to run a full backup
392 is determined by the rate at which your databases change and
393 how sensitive your application is to lengthy recoveries
394 (should one be required).
395 </p>
396 <p>
397 You can also shorten recovery time by running recovery against the backup as you take each incremental
398 backup. Running recovery as you go means that there will be less work for DB to do if you should
399 ever need to restore your environment from the backup.
400 </p>
401 </div>
402 </div>
403 <div class="navfooter">
404 <hr />
405 <table width="100%" summary="Navigation footer">
406 <tr>
407 <td width="40%" align="left"><a accesskey="p" href="filemanagement.html">Prev</a> </td>
408 <td width="20%" align="center">
409 <a accesskey="u" href="filemanagement.html">Up</a>
410 </td>
411 <td width="40%" align="right"> <a accesskey="n" href="recovery.html">Next</a></td>
412 </tr>
413 <tr>
414 <td width="40%" align="left" valign="top">Chapter 5. Managing DB Files </td>
415 <td width="20%" align="center">
416 <a accesskey="h" href="index.html">Home</a>
417 </td>
418 <td width="40%" align="right" valign="top"> Recovery Procedures</td>
419 </tr>
420 </table>
421 </div>
422 </body>
423 </html>