Skip to main content

Restore data from a backup

tip

Data restoring is available in ob-operator 2.1.0 and later versions.

This topic describes how to restore data from a backup. OBTenant and OBTenantRestore resources are important to data restore from a backup. You must use parameters in the spec.source section in the configuration file of the OBTenant resource to specify the tenant restore source. When the specified parameters take effect, ob-operator creates the OBTenantRestore resources required to execute restore jobs.

Prerequisites

  • Data has been backed up and can be restored.

  • The cluster is running properly and the available resources are sufficient to create a recovery tenant.

  • If the restore source is a Network File System (NFS) volume, make sure that the volume mounted to the OceanBase cluster can be accessed.

Configuration file for restoring data

You can use the configuration file to define tenant resources required for restoring data:

apiVersion: oceanbase.oceanbase.com/v1alpha1  
kind: OBTenant
metadata:
name: t1s
# namespace: oceanbase
spec:
obcluster: obcluster
tenantName: t1s
unitNum: 1
tenantRole: STANDBY
source:
restore:
bakDataSource:
# type: "NFS"
# path: "t1/dataBackup"
type: "OSS"
path: "oss://bucket/backup?host=oss-cn-hangzhou.aliyuncs.com"
ossAccessSecret: "oss-access"
archiveSource:
# type: "NFS"
# path: "t1/logArchive"
type: "OSS"
path: "oss://bucket/archive?host=oss-cn-hangzhou.aliyuncs.com"
ossAccessSecret: "oss-access"
until:
unlimited: true
replayLogUntil:
unlimited: true
tenant: t1
fields: values

The parameters are described as follows:

  • tenantRole: the role of the tenant to be created. Valid values are PRIMARY and STANDBY, which represent the primary and standby tenants, respectively. The default value is PRIMARY. For more information about standby tenants and physical standby databases, see Physical standby database.
  • source: the source of tenant data.
    • restore: the source of the backup data for restore.
      • bakDataSource: the path to the source of the backup data for restore. The data restore source is the same as the data backup destination.
      • archiveSource: the path to the source of archived logs for restore. The log restore source is the same as the log archiving destination.
      • until: the checkpoint to which the data is to be restored.
        • unlimited: specifies whether to restore data to the latest checkpoint.
        • timestamp: the timestamp, in the YYYY-MM-DD HH:mm:ss format, to which you want to restore data. For example, 2023-11-10 09:00:00.
        • scn: the system change number (SCN) to which the data is restored.
      • replayLogUntil: the checkpoint to which the logs of the primary tenant are replayed after data restore. This parameter takes effect only if the standby tenant is restored and the unlimited parameter is not specified. You can specify this parameter as a supplement to the until parameter by using the same configuration method.
    • tenant: the name of the primary tenant. This parameter takes effect only if the standby tenant is restored.
  • The configuration of other parameters is the same as that of a normal tenant.

Example

Initiate a data restore job

Run the following command to restore data to a tenant.

kubectl apply -f tenant_restore.yaml

View the data restore status

  • Run the following command to view the status of the tenant to be restored.
kubectl get obtenants.oceanbase.oceanbase.com -n oceanbase

The command output is as follows:

NAME   STATUS      TENANTNAME   TENANTROLE   CLUSTERNAME   AGE
t1s restoring t1s STANDBY obcluster 27s
  • Run the following command to view the created tenant restore job.
kubectl get obtenantrestores.oceanbase.oceanbase.com -n oceanbase

The command output is as follows:

NAME          STATUS    AGE    TARGETTENANT   TARGETCLUSTER   RESTOREROLE   STATUSINDB
t1s-restore RUNNING 113s t1s obcluster STANDBY WAIT_TENANT_RESTORE_FINISH
  • Run the following command to view details of the tenant restore job:
kubectl describe obtenantrestores.oceanbase.oceanbase.com -n oceanbase

The command output is as follows:

Name:         t1s-restore
Namespace: oceanbase
Labels: oceanbase.oceanbase.com/tenant-name=t1s
ref-obcluster=obcluster
ref-uid=b9317541-6566-4ac0-84fb-9a4c6fca03ba
Annotations: <none>
API Version: oceanbase.oceanbase.com/v1alpha1
Kind: OBTenantRestore
Metadata:
Creation Timestamp: 2023-11-13T03:13:26Z
Generation: 1
Owner References:
API Version: oceanbase.oceanbase.com/v1alpha1
Block Owner Deletion: true
Kind: OBTenant
Name: t1s
UID: b9317541-6566-4ac0-84fb-9a4c6fca03ba
Resource Version: 927784
UID: e439a060-9758-4074-a170-661d3e23a836
Spec:
Primary Tenant: t1
Restore Option: pool_list=pool_t1s_zone1&primary_zone=zone1;&locality=FULL{1}@zone1
Restore Role: STANDBY
Source:
Archive Source:
Oss Access Secret: oss-access
Path: oss://bucket/archive?host=oss-cn-hangzhou.aliyuncs.com
Type: OSS
Bak Data Source:
Oss Access Secret: oss-access
Path: oss://bucket/backup?host=oss-cn-hangzhou.aliyuncs.com
Type: OSS
Replay Log Until:
Unlimited: true
Until:
Unlimited: true
Target Cluster: obcluster
Target Tenant: t1s
Status:
Restore Progress:
backup_cluster_name: obcluster
backup_cluster_version:
backup_dest: oss://bucket/backup?host=oss-cn-hangzhou.aliyuncs.com&access_id=xxx&access_key=yyy,oss://bucket/archive?host=oss-cn-hangzhou.aliyuncs.com&access_id=xxx&access_key=yyy
backup_piece_list: oss://bucket/archive/piece_d1005r10p10?host=oss-cn-hangzhou.aliyuncs.com&access_id=xxx&access_key=yyy
backup_set_list: oss://bucket/backup/backup_set_25_full?host=oss-cn-hangzhou.aliyuncs.com&access_id=xxx&access_key=yyy,oss://bucket/backup/backup_set_26_inc?host=oss-cn-hangzhou.aliyuncs.com&access_id=xxx&access_key=yyy
backup_tenant_id: 1016
backup_tenant_name: t1
Description:
finish_ls_count: 0
finish_tablet_count: 0
finish_timestamp:
job_id: 5
ls_count: 0
restore_option: pool_list=pool_t1s_zone1&primary_zone=zone1;&locality=FULL{1}@zone1
restore_scn: 1697098764718466986
restore_scn_display: 2023-10-12 16:19:24.718466
restore_tenant_id: 1004
restore_tenant_name: t1s
start_timestamp: 2023-11-13 11:13:46.220513
Status: WAIT_TENANT_RESTORE_FINISH
tablet_count: 0
tenant_id: 1
Status: RUNNING
Events: <none>

Check whether the tenant is restored

  • Connect to the sys tenant.
mysql -h$(kubectl get pods -l ref-obcluster=test -o jsonpath='{.items[0].status.podIP}') -P2881 -uroot oceanbase -A -c
  • Check whether the target tenant is restored.
select * from DBA_OB_TENANTS;