| 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 |
|
| 209 |
<span> |
| 210 |
<code class="methodname">Environment.getArchiveDatabases()</code>, |
| 211 |
method |
| 212 |
</span> |
| 213 |
|
| 214 |
or use the <span class="command"><strong>db_archive</strong></span> |
| 215 |
command with the <code class="literal">-s</code> option. |
| 216 |
</span> |
| 217 |
</p> |
| 218 |
<p> |
| 219 |
However, be aware that backing up just the modified databases only works if you have all of your |
| 220 |
log files. If you have been removing log files for any reason then using |
| 221 |
|
| 222 |
<span> |
| 223 |
<code class="methodname">getArchiveDatabases()</code>, |
| 224 |
</span> |
| 225 |
|
| 226 |
can result in an |
| 227 |
unrecoverable backup because you might not be notified of a database file that was modified. |
| 228 |
</p> |
| 229 |
</li> |
| 230 |
<li> |
| 231 |
<p> |
| 232 |
Copy the <span class="emphasis"><em>last</em></span> log file to your backup location. |
| 233 |
Your log files are named |
| 234 |
<code class="literal">log.<span class="emphasis"><em>xxxxxxxxxx</em></span></code>, |
| 235 |
where <span class="emphasis"><em>xxxxxxxxxx</em></span> is a |
| 236 |
sequential number. The last log file is the file |
| 237 |
with the highest number. |
| 238 |
</p> |
| 239 |
</li> |
| 240 |
</ol> |
| 241 |
</div> |
| 242 |
</div> |
| 243 |
<div class="sect2" lang="en" xml:lang="en"> |
| 244 |
<div class="titlepage"> |
| 245 |
<div> |
| 246 |
<div> |
| 247 |
<h3 class="title"><a id="hotbackup"></a>Hot Backup</h3> |
| 248 |
</div> |
| 249 |
</div> |
| 250 |
</div> |
| 251 |
<p> |
| 252 |
To create a hot backup, you do not have to stop database |
| 253 |
operations. Transactions may be on-going and you can be writing |
| 254 |
to your database at the time of the backup. However, this means |
| 255 |
that you do not know exactly what the state of your database is |
| 256 |
at the time of the backup. |
| 257 |
</p> |
| 258 |
<p> |
| 259 |
You can use the <span class="command"><strong>db_hotbackup</strong></span> command |
| 260 |
line utility to create a hot backup. This program |
| 261 |
optionally runs a checkpoint, and then copies all necessary |
| 262 |
files to a target directory. |
| 263 |
</p> |
| 264 |
<p> |
| 265 |
You can also create your own hot backup facility using the |
| 266 |
|
| 267 |
|
| 268 |
<code class="methodname">Environment.backup()</code> |
| 269 |
method. |
| 270 |
</p> |
| 271 |
<p> |
| 272 |
Alternatively, you can manually create a hot backup as follows: |
| 273 |
</p> |
| 274 |
<div class="orderedlist"> |
| 275 |
<ol type="1"> |
| 276 |
<li> |
| 277 |
<p> |
| 278 |
|
| 279 |
<span> |
| 280 |
Specify <code class="literal">true</code> to the |
| 281 |
<code class="literal">EnvironmentConfig.setHotbackupInProgress()</code> method. |
| 282 |
</span> |
| 283 |
|
| 284 |
|
| 285 |
<span> |
| 286 |
For more information, see the <code class="literal">setHotbackupInProgress()</code> method in the |
| 287 |
<a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/java/com/sleepycat/db/EnvironmentConfig.html" target="_top"> |
| 288 |
EnvironmentConfig Javadoc page. |
| 289 |
</a> |
| 290 |
</span> |
| 291 |
</p> |
| 292 |
</li> |
| 293 |
<li> |
| 294 |
<p> |
| 295 |
Copy all your database files to the backup location. |
| 296 |
<span> |
| 297 |
Note that you can simply copy all of the database |
| 298 |
files, or you can determine which database files |
| 299 |
have been written during the lifetime of the current |
| 300 |
logs. To do this, use either the |
| 301 |
|
| 302 |
<span> |
| 303 |
<code class="methodname">Environment.getArchiveDatabases()</code>, |
| 304 |
</span> |
| 305 |
|
| 306 |
or use the <span class="command"><strong>db_archive</strong></span> |
| 307 |
command with the <code class="literal">-s</code> option. |
| 308 |
</span> |
| 309 |
</p> |
| 310 |
</li> |
| 311 |
<li> |
| 312 |
<p> |
| 313 |
Copy all logs to your backup location. |
| 314 |
</p> |
| 315 |
</li> |
| 316 |
<li> |
| 317 |
<p> |
| 318 |
|
| 319 |
<span> |
| 320 |
Specify <code class="literal">false</code> to the <code class="literal">EnvironmentConfig.setHotbackupInProgress()</code> method. |
| 321 |
</span> |
| 322 |
</p> |
| 323 |
</li> |
| 324 |
</ol> |
| 325 |
</div> |
| 326 |
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> |
| 327 |
<h3 class="title">Note</h3> |
| 328 |
<p> |
| 329 |
It is important to copy your database files <span class="emphasis"><em>and |
| 330 |
then</em></span> your logs. In this way, |
| 331 |
you can complete or roll back any database operations that were only partially completed |
| 332 |
when you copied the databases. |
| 333 |
</p> |
| 334 |
</div> |
| 335 |
</div> |
| 336 |
<div class="sect2" lang="en" xml:lang="en"> |
| 337 |
<div class="titlepage"> |
| 338 |
<div> |
| 339 |
<div> |
| 340 |
<h3 class="title"><a id="incrementalbackups"></a>Incremental Backups</h3> |
| 341 |
</div> |
| 342 |
</div> |
| 343 |
</div> |
| 344 |
<p> |
| 345 |
Once you have created a full backup (that is, either a |
| 346 |
offline or hot backup), you can create incremental backups. |
| 347 |
To do this, simply copy all of your currently existing log |
| 348 |
files to your backup location. |
| 349 |
</p> |
| 350 |
<p> |
| 351 |
Incremental backups do not require you to run a checkpoint |
| 352 |
or to cease database write operations. |
| 353 |
</p> |
| 354 |
<p> |
| 355 |
If your application uses the transactional bulk insert |
| 356 |
optimization, it is important to know that a database |
| 357 |
copy taken prior to a bulk loading event can no longer |
| 358 |
be used as the target of an incremental backup. This |
| 359 |
is true because bulk loading omits logging of some |
| 360 |
record insertions, so recovery cannot roll forward |
| 361 |
these insertions. It is recommended that a full |
| 362 |
backup be scheduled following a bulk loading event. |
| 363 |
</p> |
| 364 |
<p> |
| 365 |
|
| 366 |
<span> |
| 367 |
For more information, see the <code class="literal">setBulk()</code> method in the |
| 368 |
<a class="ulink" href="http://download.oracle.com/docs/cd/E17076_02/html/java/com/sleepycat/db/TransactionConfig.html" target="_top"> |
| 369 |
TransactionConfig Javadoc page. |
| 370 |
</a> |
| 371 |
</span> |
| 372 |
</p> |
| 373 |
<p> |
| 374 |
When you are working with incremental backups, remember |
| 375 |
that the greater the number of log files contained in |
| 376 |
your backup, the longer recovery will take. |
| 377 |
You should run full backups |
| 378 |
on some interval, and then do incremental backups on a shorter interval. |
| 379 |
How frequently you need to run a full backup |
| 380 |
is determined by the rate at which your databases change and |
| 381 |
how sensitive your application is to lengthy recoveries |
| 382 |
(should one be required). |
| 383 |
</p> |
| 384 |
<p> |
| 385 |
You can also shorten recovery time by running recovery against the backup as you take each incremental |
| 386 |
backup. Running recovery as you go means that there will be less work for DB to do if you should |
| 387 |
ever need to restore your environment from the backup. |
| 388 |
</p> |
| 389 |
</div> |
| 390 |
</div> |
| 391 |
<div class="navfooter"> |
| 392 |
<hr /> |
| 393 |
<table width="100%" summary="Navigation footer"> |
| 394 |
<tr> |
| 395 |
<td width="40%" align="left"><a accesskey="p" href="filemanagement.html">Prev</a> </td> |
| 396 |
<td width="20%" align="center"> |
| 397 |
<a accesskey="u" href="filemanagement.html">Up</a> |
| 398 |
</td> |
| 399 |
<td width="40%" align="right"> <a accesskey="n" href="recovery.html">Next</a></td> |
| 400 |
</tr> |
| 401 |
<tr> |
| 402 |
<td width="40%" align="left" valign="top">Chapter 5. Managing DB Files </td> |
| 403 |
<td width="20%" align="center"> |
| 404 |
<a accesskey="h" href="index.html">Home</a> |
| 405 |
</td> |
| 406 |
<td width="40%" align="right" valign="top"> Recovery Procedures</td> |
| 407 |
</tr> |
| 408 |
</table> |
| 409 |
</div> |
| 410 |
</body> |
| 411 |
</html> |