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">
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" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">Hot failover</th>
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
28 <td width="20%" align="right"> <a accesskey="n" href="transapp_journal.html">Next</a></td>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
37 <h2 class="title" style="clear: both"><a id="transapp_hotfail"></a>Hot failover</h2>
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
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
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.
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->backup()</a> or <a href="../api_reference/C/envdbbackup.html" class="olink">DB_ENV->dbbackup()</a> methods.
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->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.
78 <div class="orderedlist">
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.
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->add_data_dir()</a> for additional information).
92 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
93 <h3 class="title">Note</h3>
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.
106 Remove all existing log files from the backup directory.
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.
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
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
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
141 <div class="orderedlist">
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
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.
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.
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
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
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.
180 <div class="navfooter">
182 <table width="100%" summary="Navigation footer">
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>
188 <td width="40%" align="right"> <a accesskey="n" href="transapp_journal.html">Next</a></td>
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>
195 <td width="40%" align="right" valign="top"> Using Recovery on Journaling Filesystems</td>