1<!--$Id: hotfail.so,v 10.5 2005/02/10 20:02:41 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB Reference Guide: Hot failover</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<a name="2"><!--meow--></a>
12<table width="100%"><tr valign=top>
13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Berkeley DB Transactional Data Store Applications</dl></b></td>
14<td align=right><a href="/transapp/recovery.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/transapp/filesys.html"><img src="/images/next.gif" alt="Next"></a>
15</td></tr></table>
16<p align=center><b>Hot failover</b></p>
17<p>For some applications, it may be useful to periodically snapshot the
18database environment for use as a hot failover should the primary system
19fail.  The following steps can be taken to keep a backup environment in
20close synchrony with an active environment.  The active environment is
21entirely unaffected by these procedures, and both read and write
22operations are allowed during all steps described here.</p>
23<ol>
24<p><li>Run <a href="/utility/db_archive.html">db_archive</a> <b>-s</b> in the active environment to
25identify all of the active environment's database files, and copy them
26to the backup directory.
27<p>If the database files are stored in a separate directory from the other
28Berkeley DB files, it will be simpler (and much faster!) to copy the directory
29itself instead of the individual files (see <a href="/api_c/env_set_data_dir.html">DB_ENV-&gt;set_data_dir</a>
30for additional information).  <b>Note: if any of the database
31files did not have an open <a href="/api_c/db_class.html">DB</a> handle during the lifetime of the
32current log files, <a href="/utility/db_archive.html">db_archive</a> will not list them in its
33output!</b>  This is another reason it may be simpler to use a separate
34database file directory and copy the entire directory instead of
35archiving only the files listed by <a href="/utility/db_archive.html">db_archive</a>.</p>
36<p><li>Remove all existing log files from the backup directory.
37<p><li>Run <a href="/utility/db_archive.html">db_archive</a> <b>-l</b> in the active environment to
38identify all of the active environment's log files, and copy them to
39the backup directory.
40<p><li>Run <a href="/utility/db_recover.html">db_recover</a> <b>-c</b> in the backup directory to
41catastrophically recover the copied environment.
42</ol>
43<p>Steps 2, 3 and 4 may be repeated as often as you like.  If Step 1 (the
44initial copy of the database files) is repeated, then Steps 2, 3 and 4
45<b>must</b> be performed at least once in order to ensure a consistent
46database environment snapshot.</p>
47<p>These procedures must be integrated with your other archival procedures,
48of course.  If you are periodically removing log files from your active
49environment, you must be sure to copy them to the backup directory
50before removing them from the active directory.  Not copying a log file
51to the backup directory and subsequently running recovery with it
52present may leave the backup snapshot of the environment corrupted.  A
53simple way to ensure this never happens is to archive the log files in
54Step 2 as you remove them from the backup directory, and move inactive
55log files from your active environment into your backup directory
56(rather than copying them), in Step 3.  The following steps describe
57this procedure in more detail:</p>
58<ol>
59<p><li>Run <a href="/utility/db_archive.html">db_archive</a> <b>-s</b> in the active environment to
60identify all of the active environment's database files, and copy them
61to the backup directory.
62<p><li>Archive all existing log files from the backup directory, moving them
63to a backup device such as CD-ROM, alternate disk, or tape.
64<p><li>Run <a href="/utility/db_archive.html">db_archive</a> (without any option) in the active environment
65to identify all of the log files in the active environment that are no
66longer in use, and <b>move</b> them to the backup directory.
67<p><li>Run <a href="/utility/db_archive.html">db_archive</a> <b>-l</b> in the active environment to
68identify all of the remaining log files in the active environment, and
69<b>copy</b> the log files to the backup directory.
70<p><li>Run <a href="/utility/db_recover.html">db_recover</a> <b>-c</b> in the backup directory to
71catastrophically recover the copied environment.
72</ol>
73<p>As before, steps 2, 3, 4 and 5 may be repeated as often as you like.
74If Step 1 (the initial copy of the database files) is repeated, then
75Steps 2 through 5 <b>must</b> be performed at least once in order to
76ensure a consistent database environment snapshot.</p>
77<p>For an example of a hot backup implementation in the Berkeley DB distribution,
78see the source code for the <a href="/utility/db_hotbackup.html">db_hotbackup</a> utility.</p>
79<table width="100%"><tr><td><br></td><td align=right><a href="/transapp/recovery.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/transapp/filesys.html"><img src="/images/next.gif" alt="Next"></a>
80</td></tr></table>
81<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
82</body>
83</html>
84