This topic describes how to restore tables.
Limitations
Only user tables can be restored. Temporary tables, views, and indexes cannot be restored.
The source and target tenants must be compatible. For example, both must be Oracle-compatible tenants or both must be MySQL-compatible tenants.
The name of the table to be restored must exactly match the name of the table stored in the system. For example, in Oracle-compatible mode, if you create a table named
testbut the system actually stores the table asTEST, you must specify the table name asTESTduring the restore. Otherwise, the system will return an error, indicating that the table does not exist.Table restore supports only the same versions as tenant restore. In other words, you can restore a table from a backup created in the same version or a lower version. For example, you can restore a table from a minor backup in a major version. For more information, see Prepare for the restore.
When you restore a table, the system will restore a lot of information related to the table. However, some information is not restored. For more information, see the Schema information restored section below.
Prerequisites
A restore for a specified table requires a temporary tenant. Therefore, before you restore a table, you must create a resource pool for the temporary tenant in the cluster where the target tenant resides. For more information, see Prepare for the restore.
Procedure
Log in to the
systenant of the target cluster as therootuser.(Optional) If the backup data of the specified table is encrypted, configure the encryption information of the backup set.
If a password is added when you back up data, you must configure a password for restoring the backup data.
SET DECRYPTION IDENTIFIED BY 'password';In this example, you must replace
passwordwith the password added when you back up data. If the full backup and incremental backup have different passwords, you need to enter both passwords, separated by a comma (the password of the full backup placed in front of the password of the incremental backup).Here is an example where the passwords of the full backup and incremental backup are the same:
SET DECRYPTION IDENTIFIED BY '******';Here is an example where the passwords of the full backup and incremental backup are different:
SET DECRYPTION IDENTIFIED BY '******','******';Run the following command to restore the specified table.
The SQL syntax is as follows:
ALTER SYSTEM RECOVER TABLE table_name_list TO TENANT dest_tenant_name FROM uri [UNTIL {TIME='timestamp'} | {SCN=scn} ] WITH 'restore_option' [WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password'] [REMAP TABLE remap_table_name_list] [REMAP TABLEGROUP remap_tablegroup_list] [REMAP TABLESPACE remap_tablespace_list] [DESCRIPTION [=] description];The parameters are described as follows:
table_name_list: the name of the table to restore. The tables are separated by commas (,). The format isdatabase_name.table_name1,database_name.table_name2,....When you specify
database_nameandtable_name:You must specify
table_nameexactly the same as the name stored in the system. For example, if you create a table namedtestin Oracle mode, the system actually stores the table name asTEST. Therefore, you must specify the table name asTESTduring restore. Otherwise, the system will return an error because the table does not exist.If special characters are included in
database_nameortable_name, enclose thedatabase_nameortable_namewith backticks (`).You can specify
database_name.*to restore all tables in a database.You can specify
*.*to restore all user tables in a tenant.
dest_tenant_name: the name of the destination tenant where the table is to be restored. You can restore a table only to a user tenant. It cannot be thesystenant or the sys tenant.uri: the path where the data backup is stored and the path where the log archive is stored. It is the same as the parameter in a tenant-level physical restore. If the data backup is initiated through PLUS ARCHIVELOG, you only need to specify one path. Otherwise, you need to specify at least two paths for data backup and log archive, respectively. For example:file:///backup/archive, file:///backup/data'.{TIME='timestamp'} \| {SCN=scn}: the restore end point. The data and settings restored to this point (including this point) will be retained. If you specify theUNTILclause, you must use the format=to connect the specified value. If you do not specify theUNTILclause, the system will restore data and settings to the latest point by default.restore_option: specifies thepool_list,locality,primary_zone, andconcurrencyof the auxiliary tenant. The parameters are separated by&. We recommend that you specify homogeneous values forlocalityandprimary_zoneas those in the source tenant.If you do not specify the
concurrencyparameter, the system will restore data with the maximum number of concurrent threads equal to the number of CPU cores allocated to the auxiliary tenant. For example, in this topic, the system allocates 16 CPU cores to the auxiliary tenant.For more information about the parameters, see Parameters for restoring a table.
WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password': the encryption information of the tenant to be restored. You need to specify this parameter only when the source tenant has transparent encryption enabled.backup_key_path: the path where the encryption key of the tenant is backed up.password: the password for encrypting the encryption key, which is the same as the one added during backup.
For more information about how to back up the encryption key, see the Backup encryption key section in Prepare for data backup.
remap_table_name_list: the new names of the restored tables. You can rename only the table names, keep the table names unchanged but rename the databases to which the tables belong, or rename both the table names and the databases to which the tables belong. The source and target objects are connected by using colons (:). Here are some examples:Rename the table named
studenttostudent2. The database to which the table belongs remains unchanged:REMAP TABLE school.student:student2.If the database to which the table belongs remains unchanged, when you restore the table to the destination tenant, the system will restore the table to the database with the same name in the destination tenant. If no database with the same name exists in the destination tenant, the table restore will fail.
Keep the table name unchanged and change the database name from
schooltocollege:REMAP TABLE school.student:college.student.Rename the table named
studenttostudent2, and change the database name fromschooltocollege:REMAP TABLE school.student:college.student2.Restore all tables in the
schooldatabase to thecollegedatabase:REMAP TABLE school.*:college.*
Note
If special characters are included in the
database_nameortable_nameof the new name, enclose thedatabase_nameortable_namewith backticks (`).remap_tablegroup_list: the new names of the table groups to which the tables belong. If the source table is bound with a table group, when you restore the table to the destination tenant, the system will restore the table to the table group with the same name in the destination tenant. If no table group with the same name exists in the destination tenant, the table restore will fail. If the destination tenant has other table groups, you can restore the table to one of the other table groups. The source and target objects are connected by using colons (:).For example, restore all tables in the source table group
tg1to the destination table groupnewtg1:REMAP TABLEGROUP tg1:newtg1.remap_tablespace_list: the new names of the table spaces to which the tables belong. Table spaces are logical units in OceanBase Database, currently used mainly for data encryption. If the source table is bound with a table space, when you restore the table to the destination tenant, the system will restore the table to the table space with the same name in the destination tenant. If no table space with the same name exists in the destination tenant, the table restore will fail. If the destination tenant has other table spaces, you can restore the table to one of the other table spaces. The source and target objects are connected by using colons (:).For example, restore all tables in the source table space
ts1to the destination table spacenewts1:REMAP TABLESPACE ts1:newts1.
For more information about the parameters, see Parameters for restoring a table.
Restore the
tbl1andtbl2tables from theinfodbdatabase to theinfodbdatabase of the destination tenant, and rename thetbl1table tonewtbl. Additionally, redirect the table group to which thetbl1table belongs tonewtg1, and the table space to which thetbl1table belongs tonewts1. The sample code is as follows:ALTER SYSTEM RECOVER TABLE infodb.tbl1,infodb.tbl2 TO TENANT oracle001 FROM 'file:///data/nfs/backup/data,file:///data/nfs/backup/archive' UNTIL TIME='2023-09-30 00:00:00' WITH 'pool_list=restore_pool' REMAP TABLE infodb.tbl1:newtbl REMAP TABLEGROUP tg1:newtg1 REMAP TABLESPACE ts1:newts1;
Notice
If the table data restore is successful, the table restore is considered successful, even if the restoration of indexes, constraints, or other schema elements fails.
Schema information after restore
After a table restore, the following schema information is restored, along with the tables.
| Schema information | Restorable | Description |
|---|---|---|
| Database | No | The target database must exist in the target tenant for the restore to succeed. For example, if the source table belongs to a database named INFO, a REMAP TABLE command must be used to rename the database to another name in the target tenant. Otherwise, the table will be placed in a database named INFO in the target tenant. |
| Tablespace | No | The target tablespace must exist in the target tenant for the restore to succeed. For example, if the source table belongs to a tablespace named TS, a REMAP TABLE command must be used to rename the tablespace to another name in the target tenant. Otherwise, the table will be placed in a tablespace named TS in the target tenant. |
| Table group | No | The target table group must exist in the target tenant for the restore to succeed. For example, if the source table belongs to a table group named TG, a REMAP TABLE command must be used to rename the table group to another name in the target tenant. Otherwise, the table will be placed in a table group named TG in the target tenant. |
| Table | Yes | Only user tables are restored. System tables and temporary tables are not restored. |
| Partition | Yes | N/A |
| Tablet | Yes | N/A |
| Column | Yes | N/A |
| Constraint | Yes | The following constraints are restored:
NoteConstraints with user-defined names that already exist in the target tenant are not restored. |
| Foreign key | Yes | During the restore of a foreign key, the system checks the integrity of the foreign key constraint. If it finds that the referenced row does not exist, the restore of the foreign key fails. |
| View | No | The views associated with the restored tables are not restored. |
| Local index | Yes | N/A |
| Global index | Yes | N/A |
| Auto-increment column | Yes | N/A |
| Table without a primary key | Yes | N/A |
| Statistics | Yes | N/A |
| Trigger | Yes |
|
| Function, stored procedure, and package | No | The functions, stored procedures, and packages associated with the restored tables are not restored. |
| Synonym | No | The synonyms associated with the restored tables are not restored. |
| Spatial index | Yes | When you restore a table, the spatial indexes on the table are not restored. If a reference coordinate system exists in the target tenant, the spatial indexes are not restored; otherwise, they are restored. |
| LOB | Yes | N/A |
Next steps
After you initiate a restore for a specific table, you can query the view for the restore progress and result. For more information, see Query the progress of restoring a table and Query the result of restoring a table.
After the restore for a specific table is completed, you must manually release the resource pool created for the auxiliary tenant in the cluster where the tenant resides by running the following command.
DROP RESOURCE POOL restore_pool;Here,
restore_poolis the name of the resource pool created for the auxiliary tenant before the restore.For more information about how to delete a resource pool, see Delete a resource pool.