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.
Tables stored in columnar storage mode or hybrid row-column storage mode are not supported.
The source and target tenants must be compatible. For example, both must be Oracle-compatible tenants or both must be MySQL-compatible tenants.
The table name specified during the restore must exactly match the name of the table stored in the system. For example, in Oracle-compatible tenant, a table named
testis created. However, the system actually stores the table asTEST. Therefore, 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 supports restoring data only from a lower version or the same version to another lower version or the same version, and does not support reverse restore between subversions of the same version. For more information, see Prepare for the restore.
In addition to the specified tables, many related configurations of the tables are also restored during the restore, but some configurations are not. For more information, see the Schema information restored section below.
Prerequisites
A resource pool is required for the restore process, which needs a temporary tenant. Therefore, before you restore a table, you must create a resource pool 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 full backup and incremental backup are encrypted with different passwords, you need to enter both passwords, separated by a comma (full backup password first, then incremental backup password).Here is an example where full backup and incremental backup are encrypted with the same password:
SET DECRYPTION IDENTIFIED BY '******';Here is an example where full backup and incremental backup are encrypted with different passwords:
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, in the format ofdatabase_name.table_name1,database_name.table_name2,.... Multiple tables are separated with commas (,).When you specify
database_nameandtable_name:The
table_namemust be the same as the name stored in the system. For example, in Oracle mode, if you create a table namedtest, the system stores the table name asTEST. Therefore, when you restore the table, you must specify the name asTEST. Otherwise, the system will return an error because the table does not exist.If special characters are included in
database_nameortable_name, the special characters must be enclosed in 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. Only user tenants, not thesystenant or the sys tenant, are supported.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 need to specify only 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 endpoint. The restore is performed to the specified point in time or SCN and the data at the specified point in time or SCN is included in the restore. If you specifyTIMEorSCN, you must use=to connect the restore endpoint and the specified value. If you do not specify theUNTILclause, the restore is performed to the latest point in time or SCN.restore_option: specifies thepool_list,locality,primary_zone, andconcurrencyof the auxiliary tenant. The parameters are separated with&. We recommend that you specify homogeneouslocalityandprimary_zoneas those of the source tenant.If you do not specify
concurrency, the default value, which is equal to the maximum number of CPU cores allocated to the auxiliary tenant, takes effect. For example, in this topic, the system allocates 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. This clause is required only when the source tenant has been transparently encrypted.backup_key_path: the backup path of the tenant's encryption key.password: the encryption password of the backup key.
For more information about how to back up the encryption key, see the Backup encryption key section in Prepare before 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 separated with a colon (:). Here are some examples:Rename the table named
studenttostudent2in the same database:REMAP TABLE school.student:student2.If the database name remains unchanged during the restore, the system will restore the table to the database with the same name in the destination tenant by default when you create the table. 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 table named
studenttostudent2and 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_namethat is being remapped, the special characters 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, by default 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, the table restore will fail. If the destination tenant has other table groups, you can restore the table to another table group. The source and target table groups are separated with a colon (:).For example, restore all tables in the source table group
tg1to the table group namednewtg1in 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 that is primarily used for data encryption. If the source table is bound to a table space, by default 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 another table space. The source and target table spaces are separated with a colon (:).For example, restore all tables in the source table space
ts1to the table space namednewts1in the destination tenant:REMAP TABLESPACE ts1:newts1.
For more information about the parameters, see Parameters for restoring a table.
Restore the tables
tbl1andtbl2from theinfodbdatabase to theinfodbdatabase in the destination tenant, rename thetbl1table tonewtbl, and redirect the table group and table space to which thetbl1table belongs. Here is an example: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 successful, regardless of whether the restoration of indexes, constraints, or other schema elements fails.
Schema information after restore
After a restore by table, the following schema information is restored.
Schema information |
Restorable |
Description |
|---|---|---|
| Database | No | The database must exist in the target tenant for the restore to succeed. For example, assume that the backup 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 system will place the table in a database named INFO in the target tenant. |
| Tablespace | No | The tablespace must exist in the target tenant for the restore to succeed. For example, assume that the backup table belongs to a tablespace named TS. If you do not use the REMAP TABLE command to rename the table to a different tablespace in the target tenant, the system will place the table in a tablespace named TS in the target tenant. |
| Table group | No | The table group must exist in the target tenant for the restore to succeed. For example, assume that the backup table belongs to a table group named TG. If you do not use the REMAP TABLE command to rename the table to a different table group in the target tenant, the system will place the table in a table group named TG in the target tenant. |
| Table | Yes | Only user tables are restored. System tables, temporary tables, and their data 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 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 restore of a spatial index is performed when you restore a table by table name. The spatial indexes of the referenced tables are not restored. If the target tenant has a reference coordinate system, the spatial indexes are restored. Otherwise, the spatial indexes are not 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 results. For more information, see Query the progress of restoring tables and Query the results of restoring tables.
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.
