github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/apecloud-mysql/dataprotection/backup.sh (about)

     1  #!/bin/bash
     2  set -e
     3  set -o pipefail
     4  
     5  # if the script exits with a non-zero exit code, touch a file to indicate that the backup failed,
     6  # the sync progress container will check this file and exit if it exists
     7  function handle_exit() {
     8    exit_code=$?
     9    if [ $exit_code -ne 0 ]; then
    10      echo "failed with exit code $exit_code"
    11      touch "${DP_BACKUP_INFO_FILE}.exit"
    12      exit 1
    13    fi
    14  }
    15  trap handle_exit EXIT
    16  
    17  export PATH="$PATH:$DP_DATASAFED_BIN_PATH"
    18  export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH"
    19  START_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
    20  xtrabackup --compress=zstd --backup --safe-slave-backup --slave-info --stream=xbstream \
    21    --host=${DP_DB_HOST} --port=${DP_DB_PORT} \
    22    --user=${DP_DB_USER} --password=${DP_DB_PASSWORD} \
    23    --datadir=${DATA_DIR} | datasafed push - "/${DP_BACKUP_NAME}.xbstream"
    24  STOP_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
    25  TOTAL_SIZE=$(datasafed stat / | grep TotalSize | awk '{print $2}')
    26  echo "{\"totalSize\":\"$TOTAL_SIZE\",\"timeRange\":{\"start\":\"${START_TIME}\",\"end\":\"${STOP_TIME}\"}}" >"${DP_BACKUP_INFO_FILE}"