How to Restore a Database in CUBRID
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.
- In the command line using the cubrid restoredb utility.
- Using the CUBRID Manager GUI database administration tool.
Note: When we talk about backup and restore, we need to mention that the restore environment must have the same operating system and the same version of CUBRID as the backup environment.
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 CUBRID Migration Toolkit (CMT) which supports such scenarios.
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 http://www.cubrid.org/cubrid_backup_restore_2#CUBRID-restoredb-utility-1 or the offline help available within the CUBRID Manager 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 be taken 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
> truncate code; > ;x
The ;x command will tell CSQL to execute the statement.
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 http://www.cubrid.org/cubrid_backup_restore_2 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 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.
Restore database using CUBRID Manager 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 Manager 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 Manager client will display the dialog shown below, where you can setup all the options needed to perform the restore:
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 & restore options provided by the CUBRID Manager client interface.
In addition, we strongly recommend reading about two other very useful CUBRID tools:
- cubrid loaddb
- cubrid unloaddb
These tools can be used for easy data export & import, including the databases schema.
- How to Backup a Database in CUBRID
- CUBRID Backup & Restore – Part I (Backup)
- CUBRID Backup & Restore – Part II (Restore)
- CUBRID Tutorials
- Admin Scripts
- CUBRID Replication
- CUBRID Architecture
- Restoring Emergency Database Logs