This topic describes how to restore data by table.
Limitations
Only user tables can be restored. Temporary tables, views, materialized views, materialized view logs, and indexes cannot be restored.
The source and target tenants must be compatible. For example, you can restore a table from an Oracle-compatible tenant to another Oracle-compatible tenant or a MySQL-compatible tenant.
The name of the table to be restored must exactly match the name of the table stored in the system. For example, in Oracle mode, if you create a table named
testbut the system stores it asTEST, you must specify the table name asTESTduring the restore. Otherwise, the system will return an error, indicating that the table does not exist.Like tenant-level restore, table-level restore is supported only from a lower version to the same version or a higher version. In the same version, reverse restore is not supported between minor versions.
In addition to the specified table, many attributes related to the table will be restored during table restore. However, some attributes are not restored. For more information, see the Schema information restored section in this topic.
Prerequisites
A restore process for a specified table requires a temporary tenant. Therefore, before you restore a table, you need to create a resource pool for the temporary tenant in the cluster to which the target tenant belongs. For more information, see Prepare for a table 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 only full backup is performed, you need to configure the password for restoring the backup data.
SET DECRYPTION IDENTIFIED BY 'password';In this example, you need to replace
passwordwith the password added when the backup data is backed up. If the password for full backup is different from that for incremental backup, you need to enter both passwords, separated by a comma (,). The password for full backup should be entered first, and then the password for incremental backup.Here is an example where the passwords for full backup and incremental backup are the same:
SET DECRYPTION IDENTIFIED BY '******';Here is an example where the passwords for 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 format isdatabase_name.table_name1,database_name.table_name2,.... Multiple tables are separated with commas (,).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 asTESTwhen you restore the table. Otherwise, the system will return an error because the table does not exist.If
database_nameortable_namecontains special characters, you must enclose thedatabase_nameortable_namein 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 to which the table is to be restored. You can restore a table only to a user tenant. It cannot be thesystenant or the meta tenant.uri: the path for restoring data backup and log archive. The format is the same as that for a tenant-level physical restore. If a data backup is initiated through PLUS ARCHIVELOG, you only need to specify the path of the archive. Otherwise, you need to specify the paths of both the data backup and the log archive at least. For example:file:///backup/archive, file:///backup/data.{TIME='timestamp'} \| {SCN=scn}: the restore end point. The data and settings in the tenant are restored to the specified end point, which must be included in the end point. If you want to restore the data and settings to a specific time or SCN, you must use the=sign to connect the time or SCN and the specified value. If you do not specify theUNTILclause, the data and settings are restored to the latest point by default.restore_option: specifies thepool_list,locality,primary_zone, andconcurrencyof the auxiliary tenant. The parameters are separated with&. We recommend that you specify the same values as those in the source tenant forlocalityandprimary_zoneto ensure homogeneity.If you do not specify
concurrency, the default value, which is equal to the maximum number of CPU cores allocated to the auxiliary tenant (MAX_CPU), is used. For example, in this topic, the system has allocated 16 CPU cores to the auxiliary tenant in the sys 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 backup path of the tenant's encryption key.password: the encryption password set when backing up the encryption key.
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 but keep the database names unchanged, or you can keep the table names unchanged but rename the databases. You can also rename both the table names and the databases. The source and target table names are separated with a colon (:). Here are some examples:Rename the
studenttable tostudent2in the same database:REMAP TABLE school.student:student2.If the database name remains unchanged when you restore the tables, the system will restore the tables to the database with the same name in the destination tenant by default. If no database with the same name exists, 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
studenttable tostudent2and 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 renamed
database_nameortable_name, the corresponding name must be enclosed in backticks (`).remap_tablegroup_list: the new names of the table groups to which the tables belong. If the source table is bound to a table group, when you restore the tables to the destination tenant, the system will restore the tables to the table group with the same name in the destination tenant. If no table group with the same name exists, the table restore will fail. If the destination tenant has other table groups, you can restore the tables to one of the other table groups. The source and target table group names are separated with a colon (:).For example, restore all tables in the
tg1table group to thenewtg1table group in the destination tenant:REMAP TABLEGROUP tg1:newtg1.remap_tablespace_list: the new names of the table spaces to which the tables belong. In OceanBase Database, a table space is a logical unit, which is currently mainly used for data encryption. If the source table is bound to 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, 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 table space names are separated with a colon (:).For example, restore all tables in the
ts1table space to thenewts1table space: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 to thenewtg1table group, and the table space to which thetbl1table belongs to thenewts1table space. The sample command 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;
Note
If the table data is restored successfully, the table restore is considered successful, even if the restoration of indexes, constraints, or other schema elements fails.
Schema information after restore
After you restore tables, the following schema information is restored. The information that cannot be restored is described as well.
| Schema information | Restorable | Description |
|---|---|---|
| Database | No | The target database must exist in the target tenant for the restore to succeed. For example, assume that the source table belongs to a database named INFO. If you do not use the REMAP TABLE command to rename the table to a different database in the target tenant (the REMAP TABLE command can rename a table to another database in the target tenant), 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, assume that the source table belongs to a tablespace named TS. If you do not use the REMAP TABLE command to rename the table to another tablespace in the target tenant (the REMAP TABLE command can rename a table to another tablespace in the target tenant), 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, assume that the source table belongs to a table group named TG. If you do not use the REMAP TABLE command to rename the table to another table group in the target tenant (the REMAP TABLE command can rename a table to another table group in the target tenant), the table will be placed in a table group named TG in the target tenant. |
| Table | Yes | You can restore only user tables, not system tables or temporary tables. |
| Partition | Yes | N/A |
| Tablet | Yes | N/A |
| Column | Yes | N/A |
| Constraint | Yes | The following constraints are supported for restore:
NoteIf a constraint name is user-defined and exists in the target tenant, the constraint is not restored. |
| Foreign key | Yes | During the restore of a foreign key, the system checks the integrity of the foreign key constraint. If it detects that a referenced row does not exist, the restore of the foreign key fails. |
| View | No | The views related to the restored table 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 related to the restored table are not restored. |
| Synonym | No | The synonyms related to the restored table are not restored. |
| Spatial index | Yes | The spatial indexes are not restored during a restore by table. If the target tenant has a reference coordinate system, 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 corresponding views for the restore progress and results. For more information, see Query the progress of restoring tables and Query the results of restoring tables.
After the restore of 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.