This topic describes how to perform tenant-level physical restore by using SQL statements. OceanBase Database supports tenant-level full restore based on points in time.
OceanBase Database supports restore within a cluster or across clusters.
After you execute the related statements, the system restores the required macroblock data from the corresponding full and incremental backups at the backup destination to the destination tenant and then pulls and replays the transaction logs.
Prerequisites
The preparations before restore are completed. For more information, see Preparations.
Procedure
Log in to the
systenant of the cluster as therootuser.(Optional) Execute the following statement to set a restore password for the backup.
You need to set a restore password for the backup only if a password is added during data backup.
SET DECRYPTION IDENTIFIED BY 'password';In the statement,
passwordmust be replaced with the password added during data backup. If the password for full backup is different from that for incremental backup, you must enter the password for full backup before that for incremental backup and separate them with a comma.If the password for full backup is the same as that for incremental backup, use the following syntax:
SET DECRYPTION IDENTIFIED BY '******';If the password for full backup is different from that for incremental backup, use the following syntax:
SET DECRYPTION IDENTIFIED BY '******','******';Execute the following statement to set the encryption configuration:
Note
If the data to be restored is not encrypted, or Key Management Service (KMS) of the original version is available, skip this step.
obclient [(none)]> SET @kms_encrypt_info = '<encryption string>';Here,
<encryption string>is the value ofexternal_kms_info, which is a tenant-level parameter.Note
external_kms_infois used to store specific key management information.Start a restore job.
Here are some examples:
Restore to a specified timestamp
ALTER SYSTEM RESTORE dest_tenant_name FROM uri UNTIL TIME='timestamp' WITH 'restore_option' [WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password'] [DESCRIPTION description];Restore to a specified SCN
ALTER SYSTEM RESTORE dest_tenant_name FROM uri UNTIL SCN=scn WITH 'restore_option' [WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password'] [DESCRIPTION description];Restore to the latest timestamp
ALTER SYSTEM RESTORE dest_tenant_name FROM uri WITH 'restore_option' [WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password'] [DESCRIPTION description];
where:
dest_tenant_namespecifies the name of the tenant to be restored.urispecifies the data backup path and log archive path, andUNTIL [TIME|SCN]specifies the end checkpoint for restore.To restore to a specified
TIMEorSCNvalue, join the parameter name and value with an equal sign (=).restore_optionspecifies the restore options, includingpool_list,locality,primary_zone, andconcurrency. Separate the options with ampersands (&). We recommend that you setlocalityandprimary_zoneto the same values as those of the source tenant. Otherwise, load balancing may be performed after the tenant is restored and activated as the primary tenant, which compromises the performance.pool_listspecifies the name of the resource pool created for the tenant to be restored. Multiple resource pools must be separated with commas (,).Localityspecifies the locality of replicas of the tenant to be restored, which must match the zone information ofpool_listof the cluster where the tenant is located. To ensure homogeneity with the source tenant, we recommend that you set the number of full-featured replicas of the tenant to the same as that of the source tenant.primary_zonespecifies the preferred position of the leader of the tenant to be restored, which must match the settings ofpool_listandlocality. To ensure homogeneity with the source tenant, we recommend that you set the number of primary zones with the top priority of the tenant to the same as that of the source tenant.concurrencyspecifies the concurrency for data restore. Ifconcurrencyis not specified, theMAX_CPUvalue assigned to the tenant is used as the default value. In this example, theMAX_CPUvalue is16.
For more information about the parameters, see Parameters related to physical restore.
WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password'specifies the backup information of the key for encrypting the tenant. You need to specify the key backup information for a tenant restore only when the tenant is configured with transparent data encryption (TDE).backup_key_pathspecifies the backup path of the key.passwordspecifies the encryption password for key backup.
For more information about how to back up keys, see Back up a key in Preparations.
For more information about
TIME,SCN, and other parameters, see Parameters related to physical restore.Here are some examples:
OSSNFSCOSS3Object storage services compatible with the S3 protocolRestore the
mysqltenant from an Alibaba Cloud Object Storage Service (OSS) data backup path and an OSS log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pooland restore the key of the source tenant.obclient> ALTER SYSTEM RESTORE mysql FROM 'oss://oceanbase-test-bucket/backup/data/?host=***.aliyun-inc.com&access_id=***&access_key=***,oss://oceanbase-test-bucket/backup/archive/?host=***.aliyun-inc.com&access_id=***&access_key=***' UNTIL TIME='2020-06-01 00:00:00' WITH 'pool_list=restore_pool' WITH KEY FROM 'oss://oceanbase-test-bucket/data_backup_dest/key?host=***.aliyun-inc.com&access_id=***&access_key=***' ENCRYPTED BY '******';Restore the
mysqltenant from a data backup path and a log archive path to the SCN1658285759724047000. Set the resource pool torestore_pool.obclient> ALTER SYSTEM RESTORE mysql FROM 'oss://oceanbase-test-bucket/backup/data/?host=***.aliyun-inc.com&access_id=***&access_key=***,oss://oceanbase-test-bucket/backup/archive/?host=***.aliyun-inc.com&access_id=***&access_key=***' UNTIL SCN=1658285759724047000 WITH 'pool_list=restore_pool';Restore the
mysqltenant from a data backup path and a log archive path to the latest archive timestamp. Set the resource pool torestore_pooland the restoreconcurrencyto50.obclient> ALTER SYSTEM RESTORE mysql FROM 'oss://oceanbase-test-bucket/backup/data/?host=***.aliyun-inc.com&access_id=***&access_key=***,oss://oceanbase-test-bucket/backup/archive/?host=***.aliyun-inc.com&access_id=***&access_key=***' WITH 'pool_list=restore_pool&concurrency=50';Restore the
mysqltenant from a data backup path and a log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pooland the replica locality toF@z1,F@z2,F@z3.obclient> ALTER SYSTEM RESTORE mysql FROM 'oss://oceanbase-test-bucket/backup/data/?host=***.aliyun-inc.com&access_id=***&access_key=***,oss://oceanbase-test-bucket/backup/archive/?host=***.aliyun-inc.com&access_id=***&access_key=***' UNTIL TIME='2020-06-01 00:00:00' WITH 'pool_list=restore_pool&locality=F@z1,F@z2,F@z3';Restore the
mysqltenant from a data backup path and a log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pool, replica locality toF@z1,F@z2,F@z3, andprimary_zonetoz1.obclient> ALTER SYSTEM RESTORE mysql FROM 'oss://oceanbase-test-bucket/backup/data/?host=***.aliyun-inc.com&access_id=***&access_key=***,oss://oceanbase-test-bucket/backup/archive/?host=***.aliyun-inc.com&access_id=***&access_key=***' UNTIL TIME='2020-06-01 00:00:00' WITH 'pool_list=restore_pool&locality=F@z1,F@z2,F@z3&primary_zone=z1';
Except for the
urlparameter, the settings of other parameters are consistent with those used for OSS.Restore the
mysqltenant from a data backup path and a log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pooland restore the key information of the source tenant.obclient> ALTER SYSTEM RESTORE mysql FROM 'file:///data/nfs/backup/data,file:///data/nfs/backup/archive' UNTIL TIME='2020-06-01 00:00:00' WITH 'pool_list=restore_pool' WITH KEY FROM 'file:///data_backup_dest/key' ENCRYPTED BY '******';Restore the
mysqltenant from a data backup path and a log archive path to the latest archive timestamp. Set the resource pool torestore_pooland the restoreconcurrencyto50.obclient> ALTER SYSTEM RESTORE mysql FROM 'file:///data/nfs/backup/data,file:///data/nfs/backup/archive' WITH 'pool_list=restore_pool&concurrency=50';
Except for the
urlparameter, the settings of other parameters are consistent with those used for OSS.Restore the
mysqltenant from a Tencent Cloud Object Storage (COS) data backup path and a COS log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pool.obclient> ALTER SYSTEM RESTORE mysql FROM 'cos://oceanbase-test-appid/backup?host=cos.ap-***x.myqcloud.com&access_id=***&access_key=***&appid=***, cos://oceanbase-test-appid/backup/archive?host=cos.ap-***x.myqcloud.com&access_id=***&access_key=***&appid=***' UNTIL TIME='2020-06-01 00:00:00' WITH 'pool_list=restore_pool';Except for the
urlparameter, the settings of other parameters are consistent with those used for OSS.Restore the
mysqltenant from an Amazon Simple Storage Service (S3) data backup path and an S3 log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pool.obclient> ALTER SYSTEM RESTORE mysql FROM 's3://oceanbase-test-bucket/backup/data/?host=s3.<region>.amazonaws.com&access_id=***&access_key=***&s3_region=***,s3://oceanbase-test-bucket/backup/archive/?host=s3.<region>.amazonaws.com&access_id=***&access_key=***&s3_region=***,' UNTIL TIME='2023-06-01 00:00:00' WITH 'pool_list=restore_pool';Except for the
urlparameter, the settings of other parameters are consistent with those used for OSS.Restore the
mysqltenant from a Huawei Object Storage Service (OBS) data backup path and an OBS log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pool.obclient> ALTER SYSTEM RESTORE mysql FROM 's3://oceanbase-test-bucket/backup/data/?host=obs.***.myhuaweicloud.com&access_id=***&access_key=***,s3://oceanbase-test-bucket/backup/archive/?host=obs.***.myhuaweicloud.com&access_id=***&access_key=***' UNTIL TIME='2023-06-01 00:00:00' WITH 'pool_list=restore_pool';Restore the
mysqltenant from a Google Cloud Storage (GCS) data backup path and a GCS log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pool.obclient> ALTER SYSTEM RESTORE mysql FROM 's3://oceanbase-test-bucket/backup/data/?host=https://storage.googleapis.com&access_id=***&access_key=***,s3://oceanbase-test-bucket/backup/archive/?host=https://storage.googleapis.com&access_id=***&access_key=***' UNTIL TIME='2023-06-01 00:00:00' WITH 'pool_list=restore_pool';Restore the
mysqltenant from a Tencent Cloud Object Storage (COS) data backup path and a COS log archive path to the timestamp2020-06-01 00:00:00. Set the resource pool torestore_pool.obclient> ALTER SYSTEM RESTORE mysql FROM 's3://oceanbase-test/backup/data?host=cos.ap-xxxx.myqcloud.com&access_id=***&access_key=***,s3://oceanbase-test/backup/archive?host=cos.ap-xxxx.myqcloud.com&access_id=***&access_key=***' UNTIL TIME='2023-06-01 00:00:00' WITH 'pool_list=restore_pool';
(Optional) After the meta tenant corresponding to the tenant to be restored is created, set the
ha_high_thread_scoreparameter to specify the number of worker threads for the restore job to speed up the restore.Query the
oceanbase.DBA_OB_TENANTSview to check whether the meta tenant is created.The syntax is as follows:
SELECT * FROM oceanbase.DBA_OB_TENANTS;In the query results, tenant names starting with
META$in theTENANT_NAMEcolumn indicate meta tenants. Meta tenants in theTENANT_STATUS_NORMALstate are successfully created.For more information about the columns in the
DBA_OB_TENANTSview, see DBA_OB_TENANTS.Specify the
ha_high_thread_scoreparameter.The tenant-level
ha_high_thread_scoreparameter specifies the current number of high-availability worker threads with a high priority. The default value is0, and the value range is [0, 100]. We recommend that you set this parameter to10.Here is an example:
ALTER SYSTEM SET ha_high_thread_score =10 TENANT = mysql;
What to do next
After you initiate a restore job, you can query the corresponding views to check the restore progress and results. For more information, see View the physical restore progress.
If you restore a tenant from backup files of an earlier OceanBase Database version to a cluster of a later version, you must upgrade the restored tenant after the restore job is completed. For more information, see Upgrade a tenant after restore.
Physical restore is associated with the Physical Standby Database solution. A physically restored tenant serves as a standby tenant. You can switch it to the PRIMARY role based on your business needs. For information about how to proceed to log replay from the source tenant, see Replay logs to a standby tenant. For information about how to switch a standby tenant to the PRIMARY role, see Convert a standby tenant into primary tenant.
References
For more information about restore, see Restore process.