This topic describes how to back up data in a tenant by taking OceanBase Database V4.x as an example.
Prerequisites
To back up data to a network file system (NFS), ensure that backup volumes have been configured when the OceanBase cluster is deployed, the NFS can be accessed, and you have the read and write permissions on the NFS.
Configure a backup task
You can back up a specific tenant in a cluster and configure different backup strategies for different tenants in the cluster. The content of the configuration file for tenant backup is as follows:
apiVersion: cloud.oceanbase.com/v1
kind: TenantBackup
metadata:
name: ob-backup
namespace: obcluster
spec:
source:
clusterName: ob-test
clusterID: 1
clusterNamespace: obcluster
tenant:
- name: tenant1
userSecret: tenant1-root-password
backupSecret: tenant1-backup
logArchiveDest: file:///ob-backup/tenant1/log
binding: Optional
pieceSwitchInterval: 1d
dataBackupDest: file:///ob-backup/tenant1/data
schedule:
- name: f # f and i are case insensitive and respectively indicate full data backup and incremental data backup.
schedule: '*/10 * * * *'
- name: i
schedule: '*/5 * * * *'
- name: tenant2
userSecret: tenant2-root-password
backupSecret: tenant2-backup
logArchiveDest: file:///ob-backup/tenant2/log
binding: Optional
pieceSwitchInterval: 1d
dataBackupDest: file:///ob-backup/tenant2/data
schedule:
- name: f # f/i
schedule: '*/10 * * * *'
- name: i
schedule: '*/5 * * * *'
deleteBackupPolicy:
- type: default
name: default
tenants: [tenant1, tenant2]
recoveryWindow: 1d
The key parameters are described as follows:
source: the information about the source cluster, including the cluster name, cluster ID, and namespace where the cluster resides.tenant: the information of the tenant to be backed up.deleteBackupPolicy: the backup data cleanup strategy.
The parameters in the tenant section are described as follows:
userSecret: the secret of the administrator user of the tenant. You need to configure a user with administrative permissions and a password.backupSecret: the secret for encrypting backup data.logArchiveDest: the log archive path.dataBackupDest: the data backup path.binding: the mode for prioritizing archiving and business. This parameter has two values:OptionalandMandatory. If you do not specify this parameter, the default valueOptionaltakes effect.pieceSwitchInterval: the switching interval for pieces. The value range is[1d,7d]. If you do not specify this parameter, the default value1dtakes effect.schedule: the scheduling strategies. You can set strategies respectively namedfandi, which respectively indicate full data backup and incremental data backup. The backup cycle is specified by using a cron expression.
Here is an example of usersecret settings:
apiVersion: v1
kind: Secret
metadata:
name: tenant1-root-password
namespace: obcluster
data:
# base64 encoded
user: cm9vdAo=
password: ******
Here is an example of backupsecret settings:
apiVersion: v1
kind: Secret
metadata:
name: tenant1-backup
namespace: obcluster
data:
incremental: ******
full: ******
The key parameters are described as follows:
incremental: the encryption password for incremental backup.full: the encryption password for full backup.
Initiate a backup
Run the following command to create a backup related secret:
kubectl apply -f user-secret.yaml
kubectl apply -f backup-secret.yaml
Run the following command to create a custom resource for tenant backup:
kubectl apply -f tenant-backup.yaml
View the backup status
Run the following command to view the tenant backup status:
kubectl get tenantbackups -AThe returned result is as follows:
NAMESPACE NAME AGE obcluster ob-backup 16hRun the following command to view the backup details:
kubectl get tenantbackups obtenant-backup -n obcluster -o yamlThe returned result is as follows:
apiVersion: cloud.oceanbase.com/v1 kind: TenantBackup metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"cloud.oceanbase.com/v1","kind":"TenantBackup","metadata":{"annotations":{},"name":"obtenant-backup","namespace":"obcluster"},"spec":{"deleteBackupPolicy":[{"name":"default","recoveryWindow":"1d","tenants":["obtenant"],"type":"default"}],"source":{"clusterID":1,"clusterName":"ob-test","clusterNamespace":"obcluster"},"tenant":[{"backupSecret":"obtenant-backup","binding":"Optional","dataBackupDest":"file:///ob-backup/obtenant/data","logArchiveDest":"file:///ob-backup/obtenant/log","name":"obtenant","pieceSwitchInterval":"1d","schedule":[{"name":"f","schedule":"*/10 * * * *"},{"name":"i","schedule":"*/5 * * * *"}],"userSecret":"obtenant-root-password"}]}} creationTimestamp: "2023-07-24T13:14:15Z" finalizers: - cloud.oceanbase.com.finalizers.obtenant-backup generation: 1 name: obtenant-backup namespace: obcluster resourceVersion: "381222" uid: 25470102-2b8f-46d8-9685-e54f122dc15f spec: deleteBackupPolicy: - name: default recoveryWindow: 1d tenants: - obtenant type: default source: clusterID: 1 clusterName: ob-test clusterNamespace: obcluster tenant: - backupSecret: obtenant-backup binding: Optional dataBackupDest: file:///ob-backup/obtenant/data logArchiveDest: file:///ob-backup/obtenant/log name: obtenant pieceSwitchInterval: 1d schedule: - name: f schedule: '*/10 * * * *' - name: i schedule: '*/5 * * * *' userSecret: obtenant-root-password status: backup set: - backupJobs: - backupSetId: 198 backupType: FULL status: COMPLETED - backupSetId: 199 backupType: INC status: DOING clusterName: ob-test schedule: - name: FULL nextTime: 2023-07-25 14:00:00 +0800 CST schedule: '*/10 * * * *' - name: INCREMENTAL nextTime: 2023-07-25 14:00:00 +0800 CST schedule: '*/5 * * * *' tenantName: obtenant