This topic describes how to back up data in a cluster by taking OceanBase Database V3.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.
At least one major compaction has been completed for the cluster to be backed up.
Configure a backup task
The content of the configuration file for cluster backup is as follows:
apiVersion: cloud.oceanbase.com/v1
kind: Backup
metadata:
name: ob-backup
namespace: obcluster
spec:
destPath: file:///ob-backup
source:
clusterName: ob-test
clusterID: 1
clusterNamespace: obcluster
schedule:
- name: f # f/i
schedule: '*/10 * * * *'
- name: i
schedule: '*/5 * * * *'
secret: backup-secret
The parameters are described as follows:
destPath: the storage path of the backup data. NFS and OSS are supported. A NFS path is in the format offile:///backuppath. An OSS path is in the format ofoss://oceanbase-test-bucket/backup/?host=xxx.aliyuninc.com&access_id=xxx&access_key=xxx&delete_mode=delete'.source: the information about the source cluster, including the cluster name, cluster ID, and namespace where the cluster resides.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.secret: the secret configured for backup data encryption.
Here is a configuration example of secret:
apiVersion: v1
kind: Secret
metadata:
name: backup-secret
namespace: obcluster
data:
# base64 encoded 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 secret.yaml
Run the following command to create a custom resource for data backup:
kubectl apply -f backup.yaml
View the backup status
Run the following command to view the cluster backup status:
kubectl get backups -AThe returned result is as follows:
NAMESPACE NAME AGE obcluster ob-backup 16hRun the following command to view the backup details:
kubectl get backup ob-backup -n obcluster -o yamlThe returned result is as follows:
apiVersion: cloud.oceanbase.com/v1 kind: Backup metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"cloud.oceanbase.com/v1","kind":"Backup","metadata":{"annotations":{},"name":"ob-backup","namespace":"obcluster"},"spec":{"destPath":"file:///ob-backup","schedule":[{"name":"f","schedule":"*/10 * * * *"},{"name":"i","schedule":"*/5 * * * *"}],"secret":"backup-secret","source":{"clusterID":1,"clusterName":"ob-314","clusterNamespace":"obcluster"}}} creationTimestamp: "2023-07-24T13:18:18Z" finalizers: - cloud.oceanbase.com.finalizers.ob-backup generation: 1 name: ob-backup namespace: obcluster resourceVersion: "380797" uid: b926732e-510c-4e14-8657-972bff04bb1d spec: destPath: file:///ob-backup schedule: - name: f schedule: '*/10 * * * *' - name: i schedule: '*/5 * * * *' secret: backup-secret source: clusterID: 1 clusterName: ob-314 clusterNamespace: obcluster status: backup set: - backupType: D bsKey: 196 clusterName: ob-314 status: SUCCESS tenantID: 1 tenantName: sys - backupType: I bsKey: 195 clusterName: ob-314 status: SUCCESS tenantID: 1 tenantName: sys - backupType: D bsKey: 196 clusterName: ob-314 status: SUCCESS tenantID: 1001 tenantName: tenant3 - backupType: I bsKey: 195 clusterName: ob-314 status: SUCCESS tenantID: 1001 tenantName: tenant3 schedule: - name: FULL nextTime: 2023-07-25 14:00:00 +0800 CST schedule: '*/10 * * * *' - name: INCREMENTAL nextTime: 2023-07-25 13:55:00 +0800 CST schedule: '*/5 * * * *'