Skip to content

Commit

Permalink
WIP with upload
Browse files Browse the repository at this point in the history
  • Loading branch information
s10 committed Jan 28, 2025
1 parent 0cbc16c commit 24a0131
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions common/pxc-db/templates/backup-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ spec:
value: {{ tpl (.Values.backup.s3.config.region) . | quote }}
- name: ENDPOINT
value: {{ tpl (.Values.backup.s3.config.endpointUrl) . | quote }}
- name: VERIFY_TLS
value: "false"
restartPolicy: OnFailure
volumes:
- name: backup-scripts
Expand Down
64 changes: 52 additions & 12 deletions common/pxc-db/templates/bin/_backup.sh.tpl
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@
#!/bin/bash

set -x

export AWS_SHARED_CREDENTIALS_FILE='/tmp/aws-credfile'
export AWS_ENDPOINT_URL="${ENDPOINT}"
export AWS_REGION="${DEFAULT_REGION}"

if [ -n "$VERIFY_TLS" ] && [[ $VERIFY_TLS == "false" ]]; then
AWS_S3_NO_VERIFY_SSL='--no-verify-ssl'
XBCLOUD_ARGS="--insecure"
fi

is_object_exist() {
local bucket="$1"
local object="$2"

aws $AWS_S3_NO_VERIFY_SSL s3api head-object --bucket $bucket --key "$object" || NOT_EXIST=true
if [[ -z "$NOT_EXIST" ]]; then
return 1
fi
}

s3_add_bucket_dest() {
{ set +x; } 2>/dev/null
aws configure set aws_access_key_id "$ACCESS_KEY_ID"
aws configure set aws_secret_access_key "$SECRET_ACCESS_KEY"
set -x
}

dump_databases() {
{ set +x; } 2>/dev/null
mysqldump \
--port="${PXC_NODE_PORT}" \
--host="${PXC_NODE_NAME}" \
--user="${PXC_USERNAME}" \
--password="${PXC_PASS}" \
--single-transaction \
--quick \
--all-databases \
--source-data=1 > /tmp/${date}/dump.sql
set -x
}

compress_dump() {
tar -czPf /tmp/${date}/dump.tar.gz /tmp/${date}/dump.sql
}

date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

mkdir -p /tmp/${date}
touch /tmp/${date}/xtrabackup_tablespaces

dump_databases
compress_dump

mysqldump \
--port="${PXC_NODE_PORT}" \
--host="${PXC_NODE_NAME}" \
--user="${PXC_USERNAME}" \
--password="${PXC_PASS}" \
--single-transaction \
--quick \
--all-databases \
--source-data=1 > /tmp/${date}/dump.sql

xbstream -C /tmp -c ${date} $XBSTREAM_EXTRA_ARGS \
| xbcloud put --parallel="$(grep -c processor /proc/cpuinfo)" --storage=s3 --md5 --s3-bucket="$S3_BUCKET" "$S3_BUCKET_PATH" 2>&1 \
xbstream --directory=/tmp/${date} -c dump.tar.gz $XBSTREAM_EXTRA_ARGS \
| xbcloud put $XBCLOUD_ARGS --parallel="$(grep -c processor /proc/cpuinfo)" --storage=s3 --s3-bucket="$S3_BUCKET" "$S3_BUCKET_PATH/${date}" 2>&1 \
| (grep -v "error: http request failed: Couldn't resolve host name" || exit 1)

rm -fr /tmp/${date}
Expand Down
2 changes: 1 addition & 1 deletion common/pxc-db/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ backup:
s3:
config:
bucket: "pxc-logical-{{ .Values.global.region }}"
prefix: "{{ .Values.name }}/"
prefix: "{{ .Values.name }}"

# -- Default Prometheus alerts and rules.
alerts:
Expand Down

0 comments on commit 24a0131

Please sign in to comment.