Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / docs / programmer_reference / transapp_hotfail.html
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>Hot failover</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="Berkeley DB Programmer's Reference Guide" />
10     <link rel="up" href="transapp.html" title="Chapter 11.  Berkeley DB Transactional Data Store Applications" />
11     <link rel="prev" href="transapp_recovery.html" title="Recovery procedures" />
12     <link rel="next" href="transapp_journal.html" title="Using Recovery on Journaling Filesystems" />
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">Hot failover</th>
22         </tr>
23         <tr>
24           <td width="20%" align="left"><a accesskey="p" href="transapp_recovery.html">Prev</a> </td>
25           <th width="60%" align="center">Chapter 11. 
26                 Berkeley DB Transactional Data Store Applications
27         </th>
28           <td width="20%" align="right"> <a accesskey="n" href="transapp_journal.html">Next</a></td>
29         </tr>
30       </table>
31       <hr />
32     </div>
33     <div class="sect1" lang="en" xml:lang="en">
34       <div class="titlepage">
35         <div>
36           <div>
37             <h2 class="title" style="clear: both"><a id="transapp_hotfail"></a>Hot failover</h2>
38           </div>
39         </div>
40       </div>
41       <p>
42         For some applications, it may be useful to periodically snapshot
43         the database environment for use as a hot failover should the
44         primary system fail.  The following steps can be taken to keep a
45         backup environment in close synchrony with an active environment.
46         The active environment is entirely unaffected by these procedures,
47         and both read and write operations are allowed during all steps
48         described here.
49     </p>
50       <p>
51         The procedure described here is not compatible with the concurrent
52         use of the transactional bulk insert optimization (transactions
53         started with the <a href="../api_reference/C/txnbegin.html#txnbegin_DB_TXN_BULK" class="olink">DB_TXN_BULK</a> flag). After the bulk optimization
54         is used, the archive must be created again from scratch starting
55         with step 1.
56     </p>
57       <p>
58         The <a href="../api_reference/C/db_hotbackup.html" class="olink">db_hotbackup</a> utility is the preferred way to automate generating a hot
59         failover system.  The first step is to run <a href="../api_reference/C/db_hotbackup.html" class="olink">db_hotbackup</a> utility without the
60         <span class="bold"><strong>-u</strong></span> flag.  This will create hot
61         backup copy of the databases in your environment.  After that point
62         periodically running the <a href="../api_reference/C/db_hotbackup.html" class="olink">db_hotbackup</a> utility with the 
63         <span class="bold"><strong>-u</strong></span> flag will copy the new
64         log files and run recovery on the backup copy to bring it current
65         with the primary environment.
66     </p>
67       <p>
68         Note that you can also create your own hot backup solution using
69         the <a href="../api_reference/C/envbackup.html" class="olink">DB_ENV-&gt;backup()</a> or <a href="../api_reference/C/envdbbackup.html" class="olink">DB_ENV-&gt;dbbackup()</a> methods.
70     </p>
71       <p>
72         To implement your own hot fail over system, the steps below can be
73         followed. However, care should be taken on non-UNIX based systems
74         when copying the database files to be sure that they are either
75         quiescent, or that either the <a href="../api_reference/C/envbackup.html" class="olink">DB_ENV-&gt;backup()</a> or <a href="../api_reference/C/db_copy.html" class="olink">db_copy()</a> routine is
76         used to ensure atomic reads of the database pages.
77     </p>
78       <div class="orderedlist">
79         <ol type="1">
80           <li>
81             <p>
82                 Run the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility with the <span class="bold"><strong>-s</strong></span> option in the active environment
83                 to identify all of the active environment's database files, and
84                 copy them to the backup directory.
85             </p>
86             <p>
87                 If the database files are stored in a separate directory from
88                 the other Berkeley DB files, it will be simpler (and much
89                 faster!) to copy the directory itself instead of the individual
90                 files (see <a href="../api_reference/C/envadd_data_dir.html" class="olink">DB_ENV-&gt;add_data_dir()</a> for additional information).
91             </p>
92             <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
93               <h3 class="title">Note</h3>
94               <p>
95                     If any of the database files did not have an open <a href="../api_reference/C/db.html" class="olink">DB</a>
96                     handle during the lifetime of the current log files,
97                     the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility will not list them in its output. This
98                     is another reason it may be simpler to use a separate
99                     database file directory and copy the entire directory
100                     instead of archiving only the files listed by the
101                     <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility.
102                 </p>
103             </div>
104           </li>
105           <li>
106             Remove all existing log files from the backup directory.
107         </li>
108           <li>
109             Run the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility with the <span class="bold"><strong>-l</strong></span>
110             option in the active environment to identify all of the active
111             environment's log files, and copy them to the backup directory.
112         </li>
113           <li>
114             Run the <a href="../api_reference/C/db_recover.html" class="olink">db_recover</a> utility with the <span class="bold"><strong>-c</strong></span>
115             option in the backup directory to catastrophically recover the
116             copied environment.
117         </li>
118         </ol>
119       </div>
120       <p>
121         Steps 2, 3 and 4 may be repeated as often as you like.  If Step 1
122         (the initial copy of the database files) is repeated, then Steps 2,
123         3 and 4 <span class="bold"><strong>must</strong></span> be performed at least
124         once in order to ensure a consistent database environment
125         snapshot.
126     </p>
127       <p>
128         These procedures must be integrated with your other archival
129         procedures, of course.  If you are periodically removing log files
130         from your active environment, you must be sure to copy them to the
131         backup directory before removing them from the active directory.
132         Not copying a log file to the backup directory and subsequently
133         running recovery with it present may leave the backup snapshot of
134         the environment corrupted.  A simple way to ensure this never
135         happens is to archive the log files in Step 2 as you remove them
136         from the backup directory, and move inactive log files from your
137         active environment into your backup directory (rather than copying
138         them), in Step 3.  The following steps describe this procedure in
139         more detail:
140     </p>
141       <div class="orderedlist">
142         <ol type="1">
143           <li>
144             Run the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility with the <span class="bold"><strong>-s</strong></span>
145             option in the active environment to identify all of the active
146             environment's database files, and copy them to the backup
147             directory.
148         </li>
149           <li>
150             Archive all existing log files from the backup directory, moving them
151             to a backup device such as CD-ROM, alternate disk, or tape.
152         </li>
153           <li>
154             Run the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility (without any option) in the active environment
155             to identify all of the log files in the active environment that are
156             no longer in use, and <span class="bold"><strong>move</strong></span> them to
157             the backup directory.
158         </li>
159           <li>
160             Run the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility with the <span class="bold"><strong>-l</strong></span>
161             option in the active environment to identify all of the remaining
162             log files in the active environment, and <span class="bold"><strong>copy</strong></span> the log files to the backup
163             directory.
164         </li>
165           <li>
166             Run the <a href="../api_reference/C/db_recover.html" class="olink">db_recover</a> utility with the <span class="bold"><strong>-c</strong></span>
167             option in the backup directory to catastrophically recover the
168             copied environment.
169         </li>
170         </ol>
171       </div>
172       <p>
173         As before, steps 2, 3, 4 and 5 may be repeated as often as you
174         like.  If Step 1 (the initial copy of the database files) is
175         repeated, then Steps 2 through 5 
176         <span class="bold"><strong>must</strong></span> be performed at least once in
177         order to ensure a consistent database environment snapshot.
178     </p>
179     </div>
180     <div class="navfooter">
181       <hr />
182       <table width="100%" summary="Navigation footer">
183         <tr>
184           <td width="40%" align="left"><a accesskey="p" href="transapp_recovery.html">Prev</a> </td>
185           <td width="20%" align="center">
186             <a accesskey="u" href="transapp.html">Up</a>
187           </td>
188           <td width="40%" align="right"> <a accesskey="n" href="transapp_journal.html">Next</a></td>
189         </tr>
190         <tr>
191           <td width="40%" align="left" valign="top">Recovery procedures </td>
192           <td width="20%" align="center">
193             <a accesskey="h" href="index.html">Home</a>
194           </td>
195           <td width="40%" align="right" valign="top"> Using Recovery on Journaling Filesystems</td>
196         </tr>
197       </table>
198     </div>
199   </body>
200 </html>