Backup & Restore

TOC

Feature Introduction

Database backup and restore are critical functionalities to ensure data security and business continuity. By regularly backing up databases, it is possible to quickly recover data in the event of data loss, corruption, or inadvertent operations, thereby minimizing business interruptions and data loss.

Prerequisites:

Prior to backup, please prepare an external S3 compatible storage based on the volume of business data.

  • External S3 Storage: S3 (Amazon Simple Storage Service) is an object storage service provided by Amazon. If you need to back up data to your own S3 bucket, please confirm with the administrator that the S3 storage has been integrated with your project.

Configure Storage Information

CLI
Web Console

Create S3 secret

kubectl -n ${namespace} create secret generic ${secret_name} --from-literal=AWS_ACCESS_KEY_ID=${access_key} --from-literal=AWS_SECRET_ACCESS_KEY=${secret_key}

Procedure

Configure Automatic Backup

CLI
Web Console

Add automatic backup configuration information in the spec of the mysqlschedules resource.

kubectl patch mysqlschedules -n ${namespace} ${instance_name}-schedule --type='merge' --patch '
spec:
  expiryDays: 7
  full:
    cron: 0 18 * * 6
    enable: true
  incr:
    cron: 0 19 * * 0,1,2,3,4,5
    enable: true
  storage:
    s3:
      bucket: ${bucket}
      endpoint: ${endpoint}
      region: ${region}
      secret:
        name: ${secretName}
'
ParameterDescription
expiryDaysRetention period for backup data
full.cronCron expression for full backup
incr.cronCron expression for incremental backup
storage.s3.bucketBucket name
storage.s3.endpointS3 storage endpoint
storage.s3.regionS3 storage region
storage.s3.secret.nameS3 storage secret name

Create Manual Backup

Prerequisite

Ensure the instance status is Running

CLI
Web Console
  1. Create a data backup

    kubectl -n ${namespace} create -f - <<EOF
    apiVersion: mysql.middleware.alauda.io/v1
    kind: MySQLBackup
    metadata:
      name: ${backup_name}
      namespace: ${namespace}
    spec:
      cluster:
        name: ${instance_name}
      storage:
        s3:
          bucket: ${bucket}
          endpoint: ${endpoint}
          region: ${region}
          secret:
            name: ${secret_name}
      type: ${type}
    EOF
    ParameterDescription
    backup_nameBackup resource name
    namespaceThe namespace where the instance to be backed up resides
    instance_nameThe name of the instance to be backed up
    storage.s3.bucketBucket name
    storage.s3.endpointS3 storage endpoint
    storage.s3.regionS3 storage region
    storage.s3.secret.nameS3 storage secret name
    typeBackup type: full or increment
  2. Wait for the backup to complete and check the backup status

    kubectl get MySQLBackup -n ${namespace} ${backup_name}

Restore Using Backup

CLI
Web Console
  1. Create MySQLRestore to restore data

    kubectl -n ${namespace} create -f - <<EOF
    apiVersion: middleware.alauda.io/v1
    kind: MySQLRestore
    metadata:
      labels:
        mysql/arch: mgr
      name: ${restore_name}
      namespace: ${namespace}
    spec:
      mgr:
        backup:
          name: ${backup_name}
        cluster:
          name: ${target_instance_name}
        source:
          name: ${source_instance_name}
    EOF
    ParameterDescription
    restore_nameRestore resource name
    namespaceThe namespace where the instance to be restored resides
    backup_nameThe full backup resource name to be used
    target_instance_nameThe name of the instance to restore data to
    source_instance_nameThe instance name from which the backup resource is sourced
  2. Wait for the restore to complete and check the restore status

    kubectl get MySQLRestore -n ${namespace} ${restore_name}

Delete Backup

CLI
Web Console
kubectl delete MySQLBackup -n ${namespace} ${backup_name}