Skip to content

Commit

Permalink
update mysql backup to use secrets from default namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
pb82 committed Mar 4, 2019
1 parent 02d12af commit 55833a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
31 changes: 24 additions & 7 deletions image/tools/lib/component/mysql.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
function get_mysql_host {
echo "`oc get secret ${COMPONENT_SECRET_NAME} -n default -o jsonpath={.data.MYSQL_HOST} | base64 --decode`"
}

function get_mysql_user {
echo "`oc get secret ${COMPONENT_SECRET_NAME} -n default -o jsonpath={.data.MYSQL_USER} | base64 --decode`"
}

function get_mysql_password {
echo "`oc get secret ${COMPONENT_SECRET_NAME} -n default -o jsonpath={.data.MYSQL_PASSWORD} | base64 --decode`"
}

function component_dump_data {
dest=$1
databases=$(mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'SHOW DATABASES' | tail -n+2 | grep -v information_schema)
for database in $databases; do
ts=$(date '+%H:%M:%S')
mysqldump --single-transaction -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD -R $database | gzip > $dest/archives/$database-$ts.dump.gz
rc=$?
if [ $rc -ne 0 ]; then
local dest=$1
local MYSQL_HOST=$(get_mysql_host)
local MYSQL_USER=$(get_mysql_user)
local MYSQL_PASSWORD=$(get_mysql_password)

databases=$(mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -e 'SHOW DATABASES' | tail -n+2 | grep -v information_schema)

for database in ${databases}; do
local ts=$(date '+%H:%M:%S')
mysqldump --single-transaction -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -R ${database} | gzip > ${dest}/archives/${database}-${ts}.dump.gz
local rc=$?
if [[ ${rc} -ne 0 ]]; then
echo "==> Dump $database: FAILED"
exit 1
fi
Expand Down
10 changes: 5 additions & 5 deletions templates/openshift/backup-cronjob-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ objects:
- "${DEBUG}"
env:
- name: BACKEND_SECRET_NAME
value: ${BACKEND_SECRET_NAME}
value: "${BACKEND_SECRET_NAME}"
- name: ENCRYPTION_SECRET_NAME
value: ${ENCRYPTION_SECRET_NAME}
envFrom:
- secretRef:
name: "${COMPONENT_SECRET_NAME}"
value: "${ENCRYPTION_SECRET_NAME}"
- name: COMPONENT_SECRET_NAME
value: "${COMPONENT_SECRET_NAME}"
restartPolicy: Never
parameters:
- name: NAME
Expand All @@ -59,6 +58,7 @@ parameters:
- name: COMPONENT_SECRET_NAME
description: Component secret name to create environment variables from
required: true
value: dummy
- name: BACKEND_SECRET_NAME
description: Backend secret name to create environment variables from
required: true
Expand Down
9 changes: 4 additions & 5 deletions templates/openshift/backup-job-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ objects:
- "${DEBUG}"
env:
- name: BACKEND_SECRET_NAME
value: ${BACKEND_SECRET_NAME}
value: "${BACKEND_SECRET_NAME}"
- name: ENCRYPTION_SECRET_NAME
value: ${ENCRYPTION_SECRET_NAME}
envFrom:
- secretRef:
name: "${COMPONENT_SECRET_NAME}"
value: "${ENCRYPTION_SECRET_NAME}"
- name: COMPONENT_SECRET_NAME
value: "${COMPONENT_SECRET_NAME}"
restartPolicy: Never
parameters:
- name: NAME
Expand Down

0 comments on commit 55833a5

Please sign in to comment.