File: backuprestore.html

package info (click to toggle)
db5.3 5.3.28%2Bdfsg1-0.5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 158,360 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,326; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (411 lines) | stat: -rw-r--r-- 18,709 bytes parent folder | download | duplicates (8)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Backup Procedures</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
    <link rel="up" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
    <link rel="prev" href="filemanagement.html" title="Chapter 5. Managing DB Files" />
    <link rel="next" href="recovery.html" title="Recovery Procedures" />
  </head>
  <body>
    <div xmlns="" class="navheader">
      <div class="libver">
        <p>Library Version 11.2.5.3</p>
      </div>
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Backup Procedures</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="filemanagement.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 5. Managing DB Files</th>
          <td width="20%" align="right"> <a accesskey="n" href="recovery.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="backuprestore"></a>Backup Procedures</h2>
          </div>
        </div>
      </div>
      <div class="toc">
        <dl>
          <dt>
            <span class="sect2">
              <a href="backuprestore.html#copyutilities">About Unix Copy Utilities</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="backuprestore.html#standardbackup">Offline Backups</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="backuprestore.html#hotbackup">Hot Backup</a>
            </span>
          </dt>
          <dt>
            <span class="sect2">
              <a href="backuprestore.html#incrementalbackups">Incremental Backups</a>
            </span>
          </dt>
        </dl>
      </div>
      <p>
            <span class="emphasis"><em>Durability</em></span> is an important part of your
            transactional guarantees. It means that once a transaction has been
            successfully committed, your application will always see the results of that
            transaction. 
        </p>
      <p>
            Of course, no software algorithm can guarantee durability in the face of physical data loss.  Hard drives
            can fail, and if you have not copied your data to locations other than your primary disk drives,
            then you will lose data when those drives fail.  Therefore, in order to truly obtain a durability
            guarantee, you need to ensure that any data stored on disk is backed up to secondary or alternative storage,
            such as secondary disk drives, or offline tapes.
        </p>
      <p>
            There are three different types of backups that you can
            perform with DB databases and log files.  They are:
        </p>
      <div class="itemizedlist">
        <ul type="disc">
          <li>
            <p>
                    Offline backups
                </p>
            <p>
                    This type of backup is perhaps the easiest to perform as it
                    involves simply copying database and log files to an
                    offline storage area. It also gives you a snapshot of the
                    database at a fixed, known point in time. However, you
                    cannot perform this type of a backup while you are performing 
                    writes to the database.
                </p>
          </li>
          <li>
            <p>
                    Hot backups
                </p>
            <p>
                    This type of backup gives you a snapshot of your database.
                    Since your application can be writing to the database at the time that the
                    snapshot is being taken, you do not necessarily know what
                    the exact state of the database is for that given snapshot.
                </p>
          </li>
          <li>
            <p>
                    Incremental backups
                </p>
            <p>
                    This type of backup refreshes a previously performed backup.
                </p>
          </li>
        </ul>
      </div>
      <p>
            Once you have performed a backup, you can
            perform <span class="emphasis"><em>catastrophic recovery</em></span> to restore
            your databases from the backup. See
            <a class="xref" href="recovery.html#catastrophicrecovery" title="Catastrophic Recovery">Catastrophic Recovery</a>
            for more information.
        </p>
      <p>
            Note that you can also maintain a hot failover. See
            <a class="xref" href="hotfailover.html" title="Using Hot Failovers">Using Hot Failovers</a>
            for more information.
        </p>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="copyutilities"></a>About Unix Copy Utilities</h3>
            </div>
          </div>
        </div>
        <p>

               If you are copying database files you must copy databases atomically, 
               in multiples of the database page size. In other words, the reads made by
               the copy program must not be interleaved with writes by
               other threads of control, and the copy program must read the
               databases in multiples of the underlying database page size.
               Generally, this is not a problem because operating systems
               already make this guarantee and system utilities normally
               read in power-of-2 sized chunks, which are larger than the
               largest possible Berkeley DB database page size. 
            </p>
        <p>
                On some platforms (most notably, some releases of Solaris), the copy utility (<code class="literal">cp</code>) was
                implemented using the <code class="function">mmap()</code> system call rather than the
                <code class="function">read()</code> system call. Because <code class="function">mmap()</code> did not make the same
                guarantee of read atomicity as did <code class="function">read()</code>, the <code class="literal">cp</code> utility
                could create corrupted copies of the databases. 
            </p>
        <p>
                Also, some platforms have implementations of the <code class="literal">tar</code> utility that performs 10KB block
                reads by default. Even when an output block size is specified, the utility will still not read the
                underlying databases in multiples of the specified block size. Again, the result can be a corrupted backup.
            </p>
        <p>
                To fix these problems, use the <code class="literal">dd</code> utility instead of <code class="literal">cp</code> or
                <code class="literal">tar</code>. When you use <code class="literal">dd</code>, make sure you specify a block size that is
                equal to, or an even multiple of, your database page size. Finally, if you plan to use a system
                utility to copy database files, you may want to use a system call trace utility (for example, 
                <code class="literal">ktrace</code> or <code class="literal">truss</code>) to make sure you are not using a I/O size that is
                smaller than your database page size. You can also use these utilities to make sure the system utility is
                not using a system call other than <code class="function">read()</code>.
            </p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="standardbackup"></a>Offline Backups</h3>
            </div>
          </div>
        </div>
        <p>
                To create an offline backup:
            </p>
        <div class="orderedlist">
          <ol type="1">
            <li>
              <p>
                        Commit or abort all on-going transactions.
                    </p>
            </li>
            <li>
              <p>
                        Pause all database writes.
                    </p>
            </li>
            <li>
              <p>
                        Force a checkpoint. See 
                            <a class="xref" href="filemanagement.html#checkpoints" title="Checkpoints">Checkpoints</a>
                        for details.
                    </p>
            </li>
            <li>
              <p>
                        Copy all your database files to the backup location. 
                        <span>
                            Note that you can simply copy all of the database
                            files, or you can determine which database files
                            have been written during the lifetime of the current
                            logs. To do this, use either the
                                
                                <span>
                                    <code class="methodname">Environment.getArchiveDatabases()</code>,                                    
                                    method
                                </span>

                                or use the <span class="command"><strong>db_archive</strong></span>
                                command with the <code class="literal">-s</code> option. 
                        </span>
                    </p>
              <p>
                        However, be aware that backing up just the modified databases only works if you have all of your
                        log files. If you have been removing log files for any reason then using
                                
                                <span>
                                    <code class="methodname">getArchiveDatabases()</code>,                                    
                                </span>

                        can result in an
                        unrecoverable backup because you might not be notified of a database file that was modified. 
                    </p>
            </li>
            <li>
              <p>
                        Copy the <span class="emphasis"><em>last</em></span> log file to your backup location.
                        Your log files are named
                        <code class="literal">log.<span class="emphasis"><em>xxxxxxxxxx</em></span></code>,
                        where <span class="emphasis"><em>xxxxxxxxxx</em></span> is a
                        sequential number. The last log file is the file
                        with the highest number.
                    </p>
            </li>
          </ol>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="hotbackup"></a>Hot Backup</h3>
            </div>
          </div>
        </div>
        <p>
                To create a hot backup, you do not have to stop database
                operations. Transactions may be on-going and you can be writing
                to your database at the time of the backup. However, this means
                that you do not know exactly what the state of your database is
                at the time of the backup.
            </p>
        <p>
                You can use the <span class="command"><strong>db_hotbackup</strong></span> command
                line utility to create a hot backup.  This program
                optionally runs a checkpoint, and then copies all necessary
                files to a target directory.                      
            </p>
        <p>
                You can also create your own hot backup facility using the 
                
                
                <code class="methodname">Environment.backup()</code>
                method.
            </p>
        <p>
                Alternatively, you can manually create a hot backup as follows:
            </p>
        <div class="orderedlist">
          <ol type="1">
            <li>
              <p>
		    
		     <span>
                 Specify <code class="literal">true</code> to the 
                 <code class="literal">EnvironmentConfig.setHotbackupInProgress()</code> method.
              </span>  
                 
                
				<span>
				For more information, see the <code class="literal">setHotbackupInProgress()</code> method in the 
				<a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/java/com/sleepycat/db/EnvironmentConfig.html" target="_top">
                    EnvironmentConfig Javadoc page.
                </a>
				</span>
		    </p>
            </li>
            <li>
              <p>
                        Copy all your database files to the backup location. 
                        <span>
                            Note that you can simply copy all of the database
                            files, or you can determine which database files
                            have been written during the lifetime of the current
                            logs. To do this, use either the
                                
                                <span>
                                    <code class="methodname">Environment.getArchiveDatabases()</code>,                                    
                                </span>

                                or use the <span class="command"><strong>db_archive</strong></span>
                                command with the <code class="literal">-s</code> option. 
                        </span>
                    </p>
            </li>
            <li>
              <p>
                        Copy all logs to your backup location.
                    </p>
            </li>
            <li>
              <p>
		    
		    <span>
		    Specify <code class="literal">false</code> to the <code class="literal">EnvironmentConfig.setHotbackupInProgress()</code> method.
		    </span>    
		    </p>
            </li>
          </ol>
        </div>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <h3 class="title">Note</h3>
          <p>
                    It is important to copy your database files <span class="emphasis"><em>and
                    then</em></span> your logs. In this way, 
                    you can complete or roll back any database operations that were only partially completed 
                    when you copied the databases. 
                </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="incrementalbackups"></a>Incremental Backups</h3>
            </div>
          </div>
        </div>
        <p>
                Once you have created a full backup (that is, either a
                offline or hot backup), you can create incremental backups.  
                To do this, simply copy all of your currently existing log
                files to your backup location. 
            </p>
        <p>
                Incremental backups do not require you to run a checkpoint
                or to cease database write operations. 
            </p>
        <p>
	        If your application uses the transactional bulk insert
	        optimization, it is important to know that a database
	        copy taken prior to a bulk loading event can no longer
	        be used as the target of an incremental backup.  This
	        is true because bulk loading omits logging of some
	        record insertions, so recovery cannot roll forward
	        these insertions.  It is recommended that a full
	        backup be scheduled following a bulk loading event.
	        </p>
        <p>
            
            <span>
            For more information, see the <code class="literal">setBulk()</code> method in the 
            <a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/java/com/sleepycat/db/TransactionConfig.html" target="_top">
                    TransactionConfig Javadoc page.
                </a>
            </span>
            </p>
        <p>
                When you are working with incremental backups, remember
                that the greater the number of log files contained in 
                your backup, the longer recovery will take.  
                You should run full backups
                on some interval, and then do incremental backups on a shorter interval.
                How frequently you need to run a full backup
                is determined by the rate at which your databases change and
                how sensitive your application is to lengthy recoveries
                (should one be required).
              </p>
        <p>
                You can also shorten recovery time by running recovery against the backup as you take each incremental
                backup.  Running recovery as you go means that there will be less work for DB to do if you should
                ever need to restore your environment from the backup.
            </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="filemanagement.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="filemanagement.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="recovery.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Chapter 5. Managing DB Files </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Recovery Procedures</td>
        </tr>
      </table>
    </div>
  </body>
</html>