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

     1  function get_current_time() {
     2    curr_time=$(psql -U ${DP_DB_USER} -h ${DP_DB_HOST} -d postgres -t -c "SELECT now() AT TIME ZONE 'UTC'")
     3    echo $curr_time
     4  }
     5  
     6  function stat_and_save_backup_info() {
     7    export PATH="$PATH:$DP_DATASAFED_BIN_PATH"
     8    export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH"
     9    START_TIME=$1
    10    STOP_TIME=$2
    11    if [ -z $STOP_TIME ]; then
    12      STOP_TIME=$(get_current_time)
    13    fi
    14    START_TIME=$(date -d "${START_TIME}" -u '+%Y-%m-%dT%H:%M:%SZ')
    15    STOP_TIME=$(date -d "${STOP_TIME}" -u '+%Y-%m-%dT%H:%M:%SZ')
    16    TOTAL_SIZE=$(datasafed stat / | grep TotalSize | awk '{print $2}')
    17    echo "{\"totalSize\":\"$TOTAL_SIZE\",\"timeRange\":{\"start\":\"${START_TIME}\",\"end\":\"${STOP_TIME}\"}}" >"${DP_BACKUP_INFO_FILE}"
    18  }
    19  
    20  # if the script exits with a non-zero exit code, touch a file to indicate that the backup failed,
    21  # the sync progress container will check this file and exit if it exists
    22  function handle_exit() {
    23    exit_code=$?
    24    if [ $exit_code -ne 0 ]; then
    25      echo "failed with exit code $exit_code"
    26      touch "${DP_BACKUP_INFO_FILE}.exit"
    27      exit 1
    28    fi
    29  }