You can initiate a tenant-level backup in OceanBase Database through obshell in two ways:
Call an API
Use an obshell command
This topic describes how to initiate a tenant-level backup through obshell in a three-server OceanBase cluster.
Prerequisites
The OceanBase cluster has been managed by obshell. For more information about how to determine whether the cluster is managed by obshell and how to take over a non-obshell-deployed cluster, see Take over a non-obshell-deployed cluster.
All OBServer nodes in the OceanBase cluster and obshell are running.
Deployment mode
The following table describes the three servers used in this topic (obshell uses the default port 2886):
| Role | IP address | Remarks |
|---|---|---|
| OBServer node | 10.10.10.1 | OceanBase zone1 |
| OBServer node | 10.10.10.2 | OceanBase zone2 |
| OBServer node | 10.10.10.3 | OceanBase zone3 |
Initiate a backup through API
Note
obshell performs security verification on the called API. Therefore, you must encrypt the request and configure the encrypted request header (${request_headers}) and request body (${request_body}) in the curl command before you call the API. For more information, see API hybrid encryption.
Step 1: (Optional) Configure a tenant-level backup
You can call the /api/v1/tenant/:name/backup/config API of any obshell to configure a tenant-level backup.
Note
If you have configured a tenant-level backup, you do not need to call this API again.
For more information about how to call the corresponding API in the CLI, see Configure a backup for a single tenant. This API creates an asynchronous task. For more information about how to check the task progress, see Get task details. Wait for the task to complete, and then the configuration is completed.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X POST -d '${request_body}' http://10.10.10.1:2886/api/v1/tenant/tenant1/backup/config
The request body before encryption is as follows:
{
"data_base_uri":"file:///data/backup/tenant/data",
"archive_base_uri":"file:///data/backup/tenant/archive",
"log_archive_concurrency":50,
"ha_low_thread_score":18,
"piece_switch_interval":"3d",
"archive_lag_target":"1h",
"delete_policy":{
"policy":"",
"recovery_window":"2d"
}
}
For more information about how to request the corresponding API method through obshell-sdk-python, see Configure a backup for a single tenant.
...
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
client.v1.post_tenant_backup_config_sync(
"file:///data/backup/tenant/data",
"file:///data/backup/tenant/archive",
log_archive_concurrency=100,
)
...
For more information about how to request the corresponding API method through obshell-sdk-go, see Configure a backup for a single tenant.
...
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
request := client.V1().NewTenantBackupConfigPostRequest("tenant1", "file:///data/backup/data", "file:///data/backup/archive")
request.SetLogArchiveConcurrency(100)
dag, err := client.V1().TenantBackupConfigSyncWithRequest(request)
...
Step 2: Initiate a tenant-level backup
You can call the /api/v1/tenant/:name/backup API of any obshell to initiate a tenant-level backup.
For more information about how to call the corresponding API in the CLI, see Initiate a backup for a single tenant. This API creates an asynchronous task. For more information about how to check the task progress, see Get task details. Wait for the task to complete, and then the backup is completed.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X POST -d '${request_body}' http://10.10.10.1:2886/api/v1/tenant/tenant1/backup
The request body before encryption is as follows:
{
"mode":"full"
}
For more information about how to request the corresponding API method through obshell-sdk-python, see Initiate a backup for a single tenant.
...
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
client.v1.start_tenant_backup_sync("tenant1", "full")
...
For more information about how to request the corresponding API method through obshell-sdk-go, see Initiate a backup for a single tenant.
...
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
request := client.V1().NewTenantBackupRequest("tenant1")
request.SetBackupMode("full")
dag, err := client.V1().TenantBackupSyncWithRequest(request)
...
Step 3: View the tenant-level backup task
You can call the /api/v1/tenant/:name/backup/overview API of any obshell to view the tenant-level backup task.
For more information about how to call the corresponding API in the CLI, see View a backup task for a single tenant.
[admin@test001 ~]$ curl
-H "Content-Type: application/json"
-X GET
http://10.10.10.1:2886/api/v1/tenant/tenant1/backup/overview
For more information about how to request the corresponding API method through obshell-sdk-python, see View a backup task for a single tenant.
...
client = ClientSet("10.10.10.1", 2886, PasswordAuth("****"))
client.v1.get_tenant_backup_overview("tenant1")
...
For more information about how to request the corresponding API method through obshell-sdk-go, see View a backup task for a single tenant.
...
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
res, err := client.V1().GetTenantBackupOverview("tenant1")
...
Initiate a backup through obshell command
Step 1: Execute the backup
You can execute the obshell tenant backup command on any server to configure a backup and trigger a backup. For more information about this command, see obshell tenant commands.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell tenant backup tenant1 -a 'file:///data/backup/archive' -d 'file:///data/backup/data'
Step 2: Query the backup information
For more information about this command, see obshell backup commands.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell backup show -t tenant1