The scope of this tutorial is to introduce the CUBRID capabilities for database backup & restore.
This is the 2nd part of the tutorial, focusing on CUBRID restore. If you haven’t read the 1st part of the tutorial (focused on backup), we recommend to first reading it before continuing with this other part.
The CUBRID database restore is a 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.
To perform a database restore, users will typically use the cubrid restoredb utility or the CUBRID Admin GUI client.
CUBRID restoredb utility
The syntax of the tool is:
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
For complete information about the usage of this utility, please consult the online manual at https://www.cubrid.org/manual/en/10.2/admin/admin_utils.html#restoredb or the offline help available within the CUBRID Admin client.
Note: This tool can be executed only in a standalone mode (it will not work in a client-server mode, as the backupdb tool does). For more explanation, read further.
In this example we will assume that we have the backup files we have created in the previous How to Backup a Database in CUBRID tutorial.
First of all, you can always get the list of the available backups, by executing the following command:
cubrid restoredb --list demodb
The database you are trying to restore should be stopped before you run the restoredb tool. Otherwise, you are subject to receive the following error message.
To stop the database, type the following command where demodb is the name of your database:cubrid server stop demodb
Once you execute the cubrid restoredb --list demodb command successfully, you will obtain the information about the available backups for the specified database:
Please note that by default the level 0, i.e. full backup will show up if exists. Using the “-l” parameter, you can obtain information about specific level backups:
What we will do now is a simple exercise which will show the steps to quickly restore a database state.
Let’s connect to the demodb database and delete all the data from the table code. So, first let’s enter the CSQL command line tool by typing
csql –C –u dba demodb
To truncate the table code type
And now let’s perform a database restore, to the point of the last backup:
Remember, it is not in the scope of this tutorial to go through all the available options for performing a restore using the restoredb tool. See https://www.cubrid.org/manual/en/10.2/admin/admin_utils.html#restoredb for more information.
Finally, let’s verify that the data which was previously deleted from the code table has been restored:
And if you used the “-o” option for the restore command, then you will find detailed information about the restore procedure, saved in the specified file; for example:
As you can see from this exercise, restoring a database to a previous state is not a difficult task at all. 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.
Restore database using CUBRID Admin Client
In the example above, we showed you how to restore a database using the restoredb 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 Admin client.
To restore a database, you can do one of the followings:
- Click the Restore Database icon from the toolbar.
- Right-click on the database in the navigation tree and then select Restore Database.
- Select Action -> Restore Database in the main menu.
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.
When using one of these options, the CUBRID Admin client will display the dialog shown below, where you can setup all the options needed to perform the restore:
In the CUBRID Admin 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 & restore options provided by the CUBRID Admin client interface.
In addition, we strongly recommend reading about two other very useful CUBRID tools:
These tools can be used for easy data export & import, including the databases schema.
This concludes the CUBRID Backup & Restore tutorial. Please let us know your feedback and remember to periodically check the CUBRID web site for other tutorials and resources.