<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>CUBRID Backup &amp; Restore – Part II (Restore)</title>
        <link>http://www.cubrid.org/?mid=cubrid_backup_restore_2</link>
        <description>CUBRID Backup &amp; Restore – Part II (Restore)</description>
        <language>en</language>
        <pubDate>Wed, 09 Feb 2011 03:56:48 -0800</pubDate>
        <lastBuildDate>Fri, 08 Apr 2011 11:10:34 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>CUBRID Backup &amp; Restore – Part II (Restore)</title>
            <dc:creator>admin</dc:creator>
            <link>http://www.cubrid.org/cubrid_backup_restore_2</link>
            <guid isPermaLink="true">http://www.cubrid.org/cubrid_backup_restore_2</guid>
                                    <description><![CDATA[<h1>CUBRID Backup &amp; Restore – Part II (Restore)</h1>

<div class="category"><a href="/cubrid_backup_restore">⇐Part I (Backup)</a><a class="pdf right" href="/files/docs/tutorials/cubrid/CUBRID%20Backup%20&amp;%20Restore%20-%20Part%20II%20(Restore).pdf">Download this document in PDF</a>
</div>

<div class="contents-table"></div>

<p>The scope of this tutorial is to present the database backup &amp; restore capabilities in CUBRID. This is the 2nd part of the tutorial, focusing on <b>CUBRID Restore</b>.</p>

<h2>Database Restore</h2>

<p>A database restore is the procedure of restoring the database to a previous state, by using the backup files, active logs and archive logs created by a database backup procedure.</p>

<p class="important">To perform a database restore, you will use the <b>cubrid restoredb</b> utility or the CUBRID Manager client.</p>

<h2>CUBRID restoredb utility</h2>

<p>The <b>cubrid restoredb</b> utility restores the database from a database backup, by using the information written to all active and archive logs, since the execution of the last backup.</p>

<p>Syntax:</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb [ options ] database_name
[ options ]
-d | -B | -l | -p | -o | -u |
--up-to-date | --backup-file-path | --level | --partial-recovery | --output-file | --replication-mode | --use-database-location-path | --list
</div>
</div>

<p class="important">For a successful restore, you must prepare backup files, active log files and archive log files. <b>This command can be performed only in standalone mode.</b></p>

<p>The following table shows options that can be used with cubrid restoredb. Note that the options are case sensitive.</p>

<table class="blackcap rowbg">
<thead>
	<tr>
		<td width="250">Option</td>
		<td>Description</td>
	</tr>
</thead>
<tbody>
<tr>
<th>-d<br />--up-to-date</th>
<td>Sets the time back when to restore the database or specifies the <b>backuptime</b> keyword.</td>
</tr>
<tr>
<th>-B<br />--backup-file-path</th>
<td>Specifies the folder or the device name where backup files are located.</td>
</tr>
<tr>
<th>-l<br />--level</th>
<td>Sets the recovery level to 0, 1 or 2.
The default value is a full recovery (0).</td>
</tr>
<tr>
<th>-p<br />--partial-recovery</th>
<td>Performs a partial recovery.</td>
</tr>
<tr>
<th>-o<br />--output-file</th>
<td>Specifies the name of the file where recovery information is to be displayed.</td>
</tr>
<tr>
<th>-u<br />--use-database-location-path</th>
<td>Recovers the database to the path specified in the database location file (<b>databases.txt</b>).</td>
</tr>
<tr>
<th>--list</th>
<td>Displays information about backup volumes of the database on the screen.</td>
</tr>
</tbody>
</table>

<h2>Usage examples</h2>

<p>In this section we will present various examples of using the <b>restoredb</b> utility.</p>

<h3>Performing a recovery by specifying a recovery point (-d or --up-to-date)</h3>

<p>The following command recovers <b>demodb</b>. If no option is specified, <b>demodb</b> is recovered to the point of the last commit by default. If no active/archive log files are required to recover to the point of the last commit, the database is recovered only to the point of the last backup.</p> 

<p class="important"><b>Note:</b> If the <b>-D</b> option is not specified, backup files are stored in the folder specified in the <b>databases.txt</b> file.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb demodb
</div>
</div>

<p><b>demodb</b> can be recovered to the given point by using the <b>-d</b> option and the syntax which specifies the date and time of the recovery. The user can specify the recovery point manually in the dd-mm-yyyy:hh:mm:ss (e.g. 14-10-2010:14:10:00) format. If no active log/archive log files are required to recover to the point specified, the database is recovered only to the point of the last backup.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -d 14-10-2010:14:10:00 demodb
</div>
</div>

<p>The following syntax specifies the recovery point by using the <b>-d</b> option and the <b>backuptime</b> keyword and recovers demodb to the point of the last backup.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -d backuptime demodb
</div>
</div>

<h3>Performing a recovery by specifying the directory path to the backup files (-B or --backup-file-path)</h3>

<p>You can specify the directory where backup files are to be located by using the <b>-B</b> option. If this option is not specified, the system retrieves the backup information file (<b>dbname_bkvinf</b>) generated upon a database backup; the backup information file in located in the <b>log_path</b> directory specified in the database location information file (<b>databases.txt</b>). And then it searches the backup files in the directory path specified in the backup information file. However, if the backup information file has been damaged or the location information of the backup files has been deleted, the system will not be able to find the backup files. Therefore, the administrator must manually specify the directory where the backup files are located by using the <b>-B</b> option.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -B /home/cubrid/backup demodb
</div>
</div>

<p>If the backup files of demodb is in the current directory, the administrator can specify the directory where the backup files are located by using the <b>-B</b> option.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -B . demodb
</div>
</div>

<h3>Performing a recovery by specifying the backup level (-l or --level)</h3>

<p>You can perform a restoration by specifying the backup level of the database to 0, 1, or 2.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -l 1 demodb
</div>
</div>

<h3>Performing a partial recovery (-p or --partial-recovery)</h3>

<p>The following command performs a partial recovery without requesting for the user's response, by using the <b>-p</b> option. If active or archive logs written after the backup point are not complete, by default the system displays a request message informing that log files are needed and prompting the user to enter an execution option. A partial recovery can be performed directly without such a request message by using the <b>-p</b> option. Therefore, if the <b>-p</b> option is used when performing a recovery, data is always recovered to the point of the last backup.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -p demodb
</div>
</div>

<p>When the <b>-p</b> option is not specified, the message requesting the user is prompted to select the execution option:</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
***********************************************************
Log Archive /home/cubrid/test/log/demodb_lgar002
 is needed to continue normal execution.
   Type
   -  0 to quit.
   -  1 to continue without present archive. (Partial recovery)
   -  2 to continue after the archive is mounted/loaded. 
   -  3 to continue after changing location/name of archive.
***********************************************************
</div>
</div>

<h3>Storing recovery progress information in the specified file (-o or --output-file)</h3>

<p>The following command writes the recovery progress of the database to the <b>info_restore</b> file by using the <b>-o</b> option.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -o info_restore demodb
</div>
</div>

<h3>Recovering data to the directory specified in the database location file (-u or --use-database-location-path)</h3>

<p>The following syntax recovers the database to the path specified in the database location file (<b>databases.txt</b>) by using the <b>-u</b> option. The <b>-u</b> option is useful when you perform a backup on server A and recover the backup files on server B.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -u demodb
</div>
</div>

<h3>Checking the backup information of the database (--list)</h3>

<p>The following syntax displays the information about backup files of the database by using the <b>--list</b> option; it does not perform recovery.</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb --list demodb
</div>
</div>

<p>The following is an example of backup information displayed as a result of using the <b>--list</b> option. You can identify the path to which backup files of the database are originally stored as well as backup levels:</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
*** BACKUP HEADER INFORMATION ***
Database Name: /local1/testing/demodb
 DB Creation Time: Mon Oct 1 17:27:40 2010
         Pagesize: 4096
Backup Level: 1 (INCREMENTAL LEVEL 1)
        Start_lsa: 513|3688
         Last_lsa: 513|3688
Backup Time: Mon Oct 1 17:32:50 2010
 Backup Unit Num: 0
Release: 8.1.0
     Disk Version: 8
Backup Pagesize: 4096
Zip Method: 0 (NONE)
        Zip Level: 0 (NONE)
Previous Backup level: 0 Time: Mon Oct 1 17:31:40 2010
(start_lsa was -1|-1)
Database Volume name: /local1/testing/demodb_vinf
     Volume Identifier: -5, Size: 308 bytes (1 pages)
Database Volume name: /local1/testing/demodb
     Volume Identifier: 0, Size: 2048000 bytes (500 pages)
Database Volume name: /local1/testing/demodb_lginf
     Volume Identifier: -4, Size: 165 bytes (1 pages)
Database Volume name: /local1/testing/demodb_bkvinf
     Volume Identifier: -3, Size: 132 bytes (1 pages)
</div>
</div>

<p>With the backup information displayed by using the <b>--list</b> option, you can check that backup files have been created at the backup level 1, as well as the point where the full backup of backup level 0 has been performed. To recover the database in the example, you must prepare first backup files for backup levels 0 and 1.</p>

<h2>Backup &amp; Restore on different servers</h2>

<p>The following section shows how to backup <b>demodb</b> on server A and restore it on server B.</p>

<p>Let’s suppose that <b>demodb</b> is backed up in the <b>/home/cubrid/db/demodb</b> folder on server A and we want to restore it into <b>/home/cubrid/data/demodb</b> on server B.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/665/004/backup-restore-different-servers.png" alt="Backup &amp; Restore on different servers" width="510" height="379" editor_component="image_link"/></p>

<p>Here are operations we need to perform:</p>

<h3>Backing up on server A </h3>

<p>Back up <b>demodb</b> on server A. If a backup has been performed earlier, you can perform an incremental backup for data only that have changed since the last backup. The directory where the backup files are created, if not specified in the <b>-D</b> option, is created by default in the location where the log volume is stored. The following is a backup command with recommended options:</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid backupdb -z -t demodb
</div>
</div>

<h3>Editing the database location file on Server B</h3>

<p>Unlike a general scenario where a backup and restore are performed on the same server, in a scenario where backup files are restored using a different server, you need to add the location information on database restore in the database location file (<b>databases.txt</b>) on server B. In the diagram above, it is supposed that <b>demodb</b> is restored in the <b>/home/cubrid/data/demodb</b> directory on server B (having hostname=<b>pmlinux</b>); edit the location information file accordingly and create the directory on server B.</p>
 
<p>Write the database location information in one single line. Separate each item with a space. The line should be written in <b>[database name]</b>. <b>[data volume path] [host name] [log volume path]</b> format:</p>

<p><b>demodb /home/cubrid/data/demodb pmlinux /home/cubrid/data/demodb</b></p>

<h3>Transferring backup/log files to server B</h3>

<p>For a restore, you must prepare a backup file (e.g. <b>demodb_bk0v000</b>) and a backup information file (e.g. <b>demodb_bkvinf</b>) of the database to be backed up. To restore the entire data up to the point of the last commit, you must prepare an active log (e.g. <b>demodb_lgat</b>) and an archive log (e.g. <b>demodb_lgar000</b>). Then, transfer the backup information, active log, and archive log files created on server A to server B - the backup information, active log and archive log files must be located in a directory (e.g. <b>/home/cubrid/temp</b>) on server B.</p>

<h3>Restoring the database on server B</h3>

<p>Perform database restore by calling the <b>cubrid restoredb</b> utility from the folder where the backup, backup information, active log and archive log files which were transferred to server B have been stored. With the -u option, demodb is restored in the directory path from the <b>databases.txt</b> file:</p>

<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -u demodb
</div>
</div>

<p>To call the <b>cubrid restoredb</b> utility from a different path, specify the directory path to the backup file by using the <b>-B</b> option as follows:</p>
 
<div class="code">
<div editor_component="code_highlighter" code_type="plain" file_path="" description="" first_line="1" collapse="false" nogutter="false" nocontrols="false">
&gt;cubrid restoredb -u -B /home/cubrid/temp demodb
</div>
</div>

<h3>Backing up the restored database on server B</h3>

<p>Once the restore of the target database is complete, run the database to check if it has been properly restored. It is also recommended to restore the database again on the server B environment, for safety reasons.</p>

<h2>Restore Database from CUBRID Manager Client</h2>

<p>To restore a database, perform one of the followings (after login to the database):</p>

<ul>
<li>Click Restore Database   from the toolbar. </li>
<li>Right-click the database and then select Restore Database. </li>
<li>Select Action -&gt; Restore Database on the menu. </li>
</ul>

<p class="important">Loading data to restore database can be performed only when the database server is not running; The <b>Restore Database</b> menu is disabled while the database is running.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/665/004/restore-database-window.png" alt="Restore Database" width="565" height="554" editor_component="image_link"/></p>

<p>These are the options you can configure:</p>

<table class="blackcap rowbg">
<thead>
<tr>
<td width="199">Option</td>
<td>Description</td>
</tr>
</thead>
<tbody>
<tr>
<th>Database name</th>
<td>The name of the database to be restored.</td>
</tr>
<tr>
<th>Restored Date and Time</th>
<td>Specifies to which point in time the database is to be restored   back to. If you select <b>Backup</b><b> time</b>, a   restore is performed with the <b>backup</b>time keyword in the restore utility. This means that   the database is restored to the point when the backup   was complete. If you select <b>Specify a   restore date</b>, you can enter the date and time you want.</td>
</tr>
<tr>
<th>Available <b>Backup</b> Information</th>
<td>You can select the   restore level after checking which levels of backing up have been performed   on the target database. The specified file path is the path to the folder   where the files for the backup for the selected level are located.</td>
</tr>
<tr>
<th>Perform partial restore if any log   archive is absent</th>
<td>Performs a partial restore if the cases of incomplete log   information. A database restore can be performed even without archive or   active logs created after the backup point.</td>
</tr>
<tr>
<th>Restore to a path specified by the   user</th>
<td>Restores the database to the path specified in the database   location file (databases.txt).</td>
</tr>
<tr>
<th>Show <b>backup</b> information</th>
<td>Shows the information of the file backed up to the selected backup level.</td>
</tr>
</tbody>
</table>

<p>If you click <b>Show backup information</b>, you will see information associated with the backup selected:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/665/004/restore-database-volume-info.png" alt="Restore Database Volume Information" width="570" height="554" editor_component="image_link"/></p>

<h2>Restore Strategy</h2>

<p>The followings must be considered before planning and executing a database restore:</p>

<ul>
<li><b>Preparing a backup file</b></li>
<ul>
<li>Identify the directory where the backup and log files are to be stored.</li>
<li>If the database has been incrementally backed up, check whether an appropriate backup file for each backup level exists.</li>
<li>Check whether the backed-up CUBRID database and the CUBRID database to be backed up are the same version.</li>
</ul>
<li><b>Choosing a restore method</b></li>
<ul>
<li>Determine whether to perform a partial or full restore.</li>
<li>Determine whether or not to perform a restore using incremental backup files.</li>
<li>Prepare restore tools and devices available.</li>
</ul>
<li><b>Determining restore time</b></li>
<ul>
<li>Identify the point in time when the database server was stopped.</li>
<li>Identify the point in time when the last backup was performed before database failure.</li>
<li>Identify the point in time when the last commit was made before database failure.</li>
</ul>
</ul>

<h3>Example</h3>

<p>The following is an example of a backup and restore process, described chronologically:</p>

<ol>
<li>Performs a full backup of <b>demodb</b>, which stopped running at 2010/8/14 04:30.</li>
<li>Performs the first incremental backup of <b>demodb</b> running at 2010/8/14 10:00.</li>
<li>Performs the first incremental backup of <b>demodb</b> running at 2010/8/14 15:00. Overwrites the first incremental backup file in step 2.</li>
<li>A system failure occurs at 2010/8/14 15:30, and the system administrator prepares the restore of <b>demodb</b>. Sets the restore time as 15:25, which is the time when the last commit was made before the database failure.</li>
<li>The system administrator prepares the full backup file created in Step 1 and the first incremental backup file created in Step 3, restores the <b>demodb</b> database up to the 15:00 time, and then prepares the active and archive logs to restore the database up to 15:25.</li>
</ol>

<table class="blackcap rowbg">
<thead>
<tr>
<td width="150">Option</td>
<td width="200">Command</td>
<td>Description</td>
</tr>
</thead>
<tbody>
<tr>
<td>2010/8/14 04:25</td>
<td>cubrid server stop demodb</td>
<td>Shuts down <b>demodb</b>.</td>
</tr>
<tr>
<td>2010/8/14 04:30</td>
<td>cubrid backupdb -S -D /home/backup -l 0
demodb</td>
<td>Performs a full backup of <b>demodb</b> in offline mode and creates backup files in the specified directory.</td>
</tr>
<tr>
<td>2010/8/14 05:00</td>
<td>cubrid server start demodb</td>
<td>Starts <b>demodb</b>.</td>
</tr>
<tr>
<td>2010/8/14 10:00</td>
<td>cubrid backupdb -C -D /home/backup -l 1
demodb</td>
<td>Performs the first incremental backup   of <b>demodb</b> online and creates backup files in the specified directory.</td>
</tr>
<tr>
<td>2010/8/14 15:00</td>
<td>cubrid backupdb -C -D /home/backup -l 1
demodb</td>
<td>Performs the first incremental backup   of <b>demodb</b> online and creates backup files in the specified directory. Overwrites   the first incremental backup file created at   10:00.</td>
</tr>
<tr>
<td>2010/8/14 15:30</td>
<td></td>
<td>A system failure occurs.</td>
</tr>
<tr>
<td>2010/8/14 15:40</td>
<td>cubrid restoredb -l 1 -d 08/14/2010:15:25:00
demodb</td>
<td>Restores <b>demodb</b> based   on the full backup file, first incremental backup file, active logs and archive logs. The   database is restored to the point of 15:25 by the full and first incremental backup files, the active and archive logs.</td>
</tr>
</tbody>
</table>

<p></p>

<h2>See also</h2>

<ul>
<li><a href="/cubrid_backup_restore">CUBRID Backup &amp; Restore – Part I (Backup)</a></li><li><a href="/webmanual/3.1/admin/admin_db_backup.htm" target="_self">Online Resource for CUBRID Backup and Restore</a></li><li><a href="/cubrid_automated_scripts_hosting_service" target="_self">CUBRID Automated Scripts for DB Hosting Service</a></li><li><a href="/how_to_do_replication_on_unix_and_linux" target="_self">CUBRID Replication</a></li><li><a href="/cubrid_architecture" target="_self">CUBRID Architecture</a></li><li><a href="/webmanual/3.1/admin/admin_db_patchlog.htm" target="_self">Restoring Emergency Database Logs</a></li>
<li><a href="/tutorials">CUBRID Tutorials</a></li>
<li><a href="/manual">CUBRID Manual</a></li>
</ul>

<h2>Getting Help</h2>

<p>This concludes the CUBRID Database Backup &amp; Restore tutorial. If you have any questions related to CUBRID Backup &amp; Restore, you can <a href="http://twitter.com/?status=%40cubrid%20">tweet to @cubrid</a> or post your message on the <a href="http://forum.cubrid.org/" target="_blank">CUBRID Forum</a>.</p>]]></description>
                        <pubDate>Wed, 09 Feb 2011 02:57:23 -0800</pubDate>
                                </item>
            </channel>
</rss>
