diff --git a/build/backup/backup.sh b/build/backup/backup.sh old mode 100644 new mode 100755 index 0285fb107..fe6805f77 --- a/build/backup/backup.sh +++ b/build/backup/backup.sh @@ -46,7 +46,7 @@ function get_backup_source() { | cut -d . -f 1 } -function request_streaming() { +function request_streaming_57() { local LOCAL_IP local NODE_NAME LOCAL_IP=$(hostname -i | sed -E 's/.*\b([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\b.*/\1/') @@ -115,6 +115,56 @@ function request_streaming() { exit 1 } +function request_streaming() { + local LOCAL_IP + local NODE_NAME + LOCAL_IP=$(hostname -i | sed -E 's/.*\b([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\b.*/\1/') + NODE_NAME=$(get_backup_source) + + if [ -z "$NODE_NAME" ]; then + /opt/percona/peer-list -on-start=/opt/percona/backup/lib/pxc/get-pxc-state.sh -service="$PXC_SERVICE" + log 'ERROR' 'Cannot find node for backup' + log 'ERROR' 'Backup was finished unsuccessful' + exit 1 + fi + + set +o errexit + log 'INFO' 'Garbd was started' + garbd \ + --address "gcomm://$NODE_NAME.$PXC_SERVICE?gmcast.listen_addr=tcp://0.0.0.0:4567" \ + --donor "$NODE_NAME" \ + --group "$PXC_SERVICE" \ + --options "$GARBD_OPTS" \ + --sst "xtrabackup-v2:$LOCAL_IP:4444/xtrabackup_sst//1" \ + --extended-exit-codes \ + --wait-for-recv-script-exit \ + --recv-script="/opt/percona/backup/run_backup.sh" + GARBD_EXIT_CODE=$? + + case ${GARBD_EXIT_CODE} in + 0) + log 'INFO' 'Backup was finished successfully' + exit 0 + ;; + 100) + log 'ERROR' 'Backup was unsuccessful: Generic failure' + exit 1 + ;; + 101) + log 'ERROR' 'Backup was unsuccessful: Donor disappeared' + exit 1 + ;; + 102) + log 'ERROR' 'Backup was unsuccessful: SST request failure' + exit 1 + ;; + *) + log 'ERROR' "Backup was unsuccessful: garbd exited with ${GARBD_EXIT_CODE}" + exit 1 + ;; + esac +} + # TODO: should i remove it? function check_ssl() { CA=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt @@ -149,4 +199,9 @@ elif [ -n "$AZURE_CONTAINER_NAME" ]; then clean_backup_azure fi -request_streaming +XTRABACKUP_VERSION=$(get_xtrabackup_version) +if check_for_version "$XTRABACKUP_VERSION" '2.4.0'; then + request_streaming_57 +else + request_streaming +fi diff --git a/build/backup/run_backup.sh b/build/backup/run_backup.sh index b1d8267dd..ce6272318 100755 --- a/build/backup/run_backup.sh +++ b/build/backup/run_backup.sh @@ -1,7 +1,8 @@ #!/bin/bash -set -o errexit set -o xtrace +set -o errexit +set -o pipefail set -m LIB_PATH='/opt/percona/backup/lib/pxc' @@ -96,7 +97,6 @@ backup_volume() { log 'INFO' "Socat(2) returned $?" fi - trap '' 15 stat xtrabackup.stream if (($(stat -c%s xtrabackup.stream) < 5000000)); then log 'ERROR' 'Backup is empty' @@ -126,20 +126,33 @@ backup_s3() { fi vault_store /tmp/${SST_INFO_NAME} + # this xbcloud command will fail with backup is incomplete + # it's expected since we only upload sst_info + set +o pipefail # shellcheck disable=SC2086 xbstream -C /tmp -c ${SST_INFO_NAME} $XBSTREAM_EXTRA_ARGS \ - | xbcloud put --storage=s3 --parallel="$(grep -c processor /proc/cpuinfo)" --md5 $XBCLOUD_ARGS --s3-bucket="$S3_BUCKET" "$S3_BUCKET_PATH.$SST_INFO_NAME" 2>&1 \ + | xbcloud put --storage=s3 \ + --md5 \ + --parallel="$(grep -c processor /proc/cpuinfo)" \ + $XBCLOUD_ARGS \ + --s3-bucket="$S3_BUCKET" \ + "$S3_BUCKET_PATH.$SST_INFO_NAME" 2>&1 \ | (grep -v "error: http request failed: Couldn't resolve host name" || exit 1) + set -o pipefail if ((SST_FAILED == 0)); then # shellcheck disable=SC2086 socat -u "$SOCAT_OPTS" stdio \ - | xbcloud put --storage=s3 --parallel="$(grep -c processor /proc/cpuinfo)" --md5 $XBCLOUD_ARGS --s3-bucket="$S3_BUCKET" "$S3_BUCKET_PATH" 2>&1 \ - | (grep -v "error: http request failed: Couldn't resolve host name" || exit 1) + | xbcloud put --storage=s3 \ + --md5 \ + --parallel="$(grep -c processor /proc/cpuinfo)" \ + $XBCLOUD_ARGS \ + --s3-bucket="$S3_BUCKET" \ + "$S3_BUCKET_PATH" 2>&1 \ + | (grep -v "error: http request failed: Couldn't resolve host name" || exit 1) & + wait $! fi - trap '' 15 - # shellcheck disable=SC2086 aws $AWS_S3_NO_VERIFY_SSL s3 ls "s3://$S3_BUCKET/$S3_BUCKET_PATH.md5" # shellcheck disable=SC2086 @@ -172,16 +185,27 @@ backup_azure() { fi vault_store /tmp/${SST_INFO_NAME} + # this xbcloud command will fail with backup is incomplete + # it's expected since we only upload sst_info + set +o pipefail # shellcheck disable=SC2086 xbstream -C /tmp -c ${SST_INFO_NAME} $XBSTREAM_EXTRA_ARGS \ - | xbcloud put --storage=azure --parallel="$(grep -c processor /proc/cpuinfo)" $XBCLOUD_ARGS "$BACKUP_PATH.$SST_INFO_NAME" 2>&1 \ + | xbcloud put --storage=azure \ + --parallel="$(grep -c processor /proc/cpuinfo)" \ + $XBCLOUD_ARGS \ + "$BACKUP_PATH.$SST_INFO_NAME" 2>&1 \ | (grep -v "error: http request failed: Couldn't resolve host name" || exit 1) + set -o pipefail if ((SST_FAILED == 0)); then # shellcheck disable=SC2086 socat -u "$SOCAT_OPTS" stdio \ - | xbcloud put --storage=azure --parallel="$(grep -c processor /proc/cpuinfo)" $XBCLOUD_ARGS "$BACKUP_PATH" 2>&1 \ - | (grep -v "error: http request failed: Couldn't resolve host name" || exit 1) + | xbcloud put --storage=azure \ + --parallel="$(grep -c processor /proc/cpuinfo)" \ + $XBCLOUD_ARGS \ + "$BACKUP_PATH" 2>&1 \ + | (grep -v "error: http request failed: Couldn't resolve host name" || exit 1) & + wait $! fi }