<?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>How to Restore a Database in CUBRID</title>
        <link>http://www.cubrid.org/?mid=restore_cubrid_database</link>
        <description>How to Restore a Database in CUBRID</description>
        <language>en</language>
        <pubDate>Wed, 23 Feb 2011 10:39:04 -0800</pubDate>
        <lastBuildDate>Wed, 28 Sep 2011 05:24:30 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>How to Restore a Database in CUBRID</title>
            <dc:creator>admin</dc:creator>
            <link>http://www.cubrid.org/restore_cubrid_database</link>
            <guid isPermaLink="true">http://www.cubrid.org/restore_cubrid_database</guid>
                                    <description><![CDATA[<h1>How to Restore a Database in CUBRID</h1>

<div class="category"><a href="/backup_cubrid_database">⇐How to Backup a Datababase</a><a class="pdf right" href="ftp://ftp.cubrid.org/CUBRID_Docs/Tutorials/how-to-restore-database-in-cubrid.pdf">Download this document in PDF</a>
</div>

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

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

<ul>
	<li>In the command line using the <b>cubrid restoredb</b> utility.</li>
	<li>Using the <a href="/cubrid_manager">CUBRID Manager</a> GUI database administration tool.</li>
</ul>

<p class="important">Note: When we talk about backup and restore, we need to mention that <b>the restore environment must have the same operating system and the same version of CUBRID as the backup environment</b>.</p>

<p class="important">If you need to migrate your database from other database systems to CUBRID or from older version of CUBRID to the latest, there is another dedicated tool called the <a href="/cubrid_migration_toolkit">CUBRID Migration Toolkit</a> (CMT) which supports such scenarios.</p>

<h2>CUBRID restoredb utility</h2>

<p>The syntax of the tool is:</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>For complete information about the usage of this utility, please consult the online manual at <a href="/cubrid_backup_restore_2#CUBRID-restoredb-utility-1">http://www.cubrid.org/cubrid_backup_restore_2#CUBRID-restoredb-utility-1 </a> or the offline help available within the CUBRID Manager client.</p>

<p class="important"><b>Note</b>: This tool can be executed only in a standalone mode (it will not work in a client-server mode, as the <b>backupdb</b> tool does). For more explanation, read further.</p>

<h3>Restore examples</h3>

<p>In this example we will assume that we have the backup files we have created in the previous <a href="/backup_cubrid_database">How to Backup a Database in CUBRID</a> tutorial.</p>

<p>First of all, you can always get the list of the available backups, by executing the following command:</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 class="important">The database you are trying to restore <b>should be stopped before you run the restoredb</b> tool. Otherwise, you are subject to receive the following error message.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/restoredb-list-error.png" alt="restoredb list error" width="579" height="156" editor_component="image_link"/></p>

<p>To stop the database, type the following command where demodb is the name of your database:</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 server stop demodb
</div>
</div>

<p>Once you execute the cubrid restoredb --list demodb command successfully, you will obtain the information about the available backups for the specified database:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/restoredb-list-information.png" alt="restoredb list information" width="514" height="433" editor_component="image_link"/></p>

<p>Please note that by default the level 0, i.e. full backup will show up if exists. Using the “<b>-l</b>” parameter, you can obtain information about specific level backups:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/restoredb-list-level-2.png" alt="restoredb list level 2" width="483" height="383" editor_component="image_link"/></p>

<p>What we will do now is a simple exercise which will show the steps to be taken to quickly restore a database state.</p>

<p>Let’s connect to the <b>demodb</b> database and delete all the data from the table <b>code</b>. So, first let’s enter the CSQL command line tool by typing:</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;csql –C –u dba demodb
</div>
</div>

<p>To truncate the table code type</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; truncate code;
&gt; ;x
</div>
</div>

<p>The <b>;x</b> command will tell CSQL to execute the statement.</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/csql-truncate-table.png" alt="CSQL truncate table" width="496" height="556" editor_component="image_link"/></p>

<p>And now let’s perform a database restore, to the point of the last backup:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/cubrid-stop-database-restore.png" alt="CUBRID stop database and restore" width="501" height="279" editor_component="image_link"/></p>

<p class="important">Remember, it is not in the scope of this tutorial to go through all the available options for performing a restore using the <b>restoredb</b> tool. See <a href="/cubrid_backup_restore_2">http://www.cubrid.org/cubrid_backup_restore_2</a> for more information.</p>

<p>Finally, let’s verify that the data which was previously deleted from the <b>code</b> table has been restored:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/csql-check-database.png" alt="CSQL check database" width="481" height="382" editor_component="image_link"/></p>

<p>And if you used the “<b>-o</b>” option for the restore command, then you will find detailed information about the restore procedure, saved in the specified file; for example:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/restoredb-log-file.png" alt="restoredb log file" width="601" height="368" editor_component="image_link"/></p>

<p>As you can see from this exercise, restoring a database to a previous state is not at all a difficult task. The key to the process is to have the appropriate backups in place and to develop and implement an efficient backup strategy for your CUBRID installation.</p>

<h2>Restore database using CUBRID Manager Client</h2>

<p>In the example above, we showed you how to restore a database using the <b>restoredb</b> command line tool. In addition to this, there is another easy way to restore a database – which is using the interface provided by the CUBRID Manager client.</p>

<p>To restore a database, you can do one of the followings:</p>
<ul>
<li>Click the <b>Restore Database</b> <img src="http://www.cubrid.org/files/attach/images/49/157/028/cm-restore-database-icon.png" alt="CUBRID Manager Restore database icon" width="16" height="16" editor_component="image_link"/> icon from the toolbar.</li>
<li>Right-click on the database in the navigation tree and then select <b>Restore Database</b>.</li>
<li>Select <b>Action -&gt; Restore Database</b> in the main menu.</li>
</ul>

<p class="important">Remember, a database restore can be performed only when the database server is not running; therefore, menus will be disabled while the database is running.</p>

<p>When using one of these options, the CUBRID Manager client will display the dialog shown below, where you can setup all the options needed to perform the restore:</p>

<p><img src="http://www.cubrid.org/files/attach/images/49/157/028/cm-restore-database.png" alt="CUBRID Manager restore database window" width="565" height="554" editor_component="image_link"/></p>

<p>In the CUBRID Manager client, there are other features available related to the backup and restore, which were not presented in this tutorial. As we already mentioned in the 1st part of the tutorial, we highly encourage you to try out the rich backup &amp; restore options provided by the CUBRID Manager client interface.</p>

<div class="important">
<p>In addition, we strongly recommend reading about two other very useful CUBRID tools:</p>
<ul>
<li>cubrid loaddb</li>
<li>cubrid unloaddb</li>
</ul>
<p>These tools can be used for easy data export &amp; import, including the databases schema.</p>
</div>

<h2>See also</h2>

<ul>
	<li><a href="/backup_cubrid_database" target="_self">How to Backup a Database in CUBRID</a></li><li><a href="/cubrid_backup_restore" target="_self">CUBRID Backup &amp; Restore – Part I (Backup)</a></li>
	<li><a href="/cubrid_backup_restore_2" target="_self">CUBRID Backup &amp; Restore – Part II (Restore)</a></li>
	<li><a href="/tutorials" target="_self">CUBRID Tutorials</a></li>
	<li><a href="/cubrid_automated_scripts_hosting_service" target="_self">Admin Scripts</a></li>
	<li><a href="/how_to_do_replication_on_unix_and_linux" target="_self">CUBRID Replication</a></li>
	<li><a href="http://blog.cubrid.org/cubrid-story/architecture-of-cubrid/" 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>
</ul>

<h2>Getting Help</h2>

<p>If you have any questions related the CUBRID 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, 23 Feb 2011 09:39:30 -0800</pubDate>
                                </item>
            </channel>
</rss>
