diff --git a/image/tools/entrypoint.sh b/image/tools/entrypoint.sh index 833a3ca..d21ffcf 100755 --- a/image/tools/entrypoint.sh +++ b/image/tools/entrypoint.sh @@ -61,7 +61,7 @@ if [[ "$encryption_engine" ]]; then else encrypted_files="$ARCHIVES_DEST/*" fi -upload_archive "${encrypted_files}" $DATESTAMP backups/$component +upload_archive "${encrypted_files}" $DATESTAMP backups/$PRODUCT_NAME/$component echo '==> Archive upload completed' echo "[$DATESTAMP] Backup completed" diff --git a/image/tools/lib/backend/s3.sh b/image/tools/lib/backend/s3.sh index 99cd38f..e994025 100644 --- a/image/tools/lib/backend/s3.sh +++ b/image/tools/lib/backend/s3.sh @@ -11,10 +11,6 @@ function get_s3_bucket_name { echo "`oc get secret -n default ${BACKEND_SECRET_NAME} -o jsonpath='{.data.AWS_S3_BUCKET_NAME}' | base64 --decode`" } -function get_s3_bucket_suffix { - echo "`oc get secret -n default ${BACKEND_SECRET_NAME} -o jsonpath='{.data.AWS_S3_BUCKET_SUFFIX}' | base64 --decode`" -} - function get_s3_key_id { echo "`oc get secret -n default ${BACKEND_SECRET_NAME} -o jsonpath='{.data.AWS_ACCESS_KEY_ID}' | base64 --decode`" } @@ -32,18 +28,12 @@ function upload_archive { local file_list=$1 local datestamp=$2 + local bucket_folder=$3 local AWS_S3_BUCKET_NAME=$(get_s3_bucket_name) - local AWS_S3_BUCKET_SUFFIX="$(get_s3_bucket_suffix)" local AWS_ACCESS_KEY_ID="$(get_s3_key_id)" local AWS_SECRET_ACCESS_KEY="$(get_s3_access_key)" - if [[ "$AWS_S3_BUCKET_SUFFIX" ]]; then - bucket_folder="$3/$AWS_S3_BUCKET_SUFFIX" - else - bucket_folder=$3 - fi - for fname in ${file_list}; do s3cmd put --access_key ${AWS_ACCESS_KEY_ID} --secret_key ${AWS_SECRET_ACCESS_KEY} --progress ${fname} "s3://$AWS_S3_BUCKET_NAME/$bucket_folder/$datestamp/$(basename ${fname})" rc=$? diff --git a/templates/openshift/README.md b/templates/openshift/README.md index 9330c49..583552d 100644 --- a/templates/openshift/README.md +++ b/templates/openshift/README.md @@ -29,7 +29,8 @@ oc new-app \ -p 'ENCRYPTION_SECRET_NAME=sample-gpg-secret' \ -p 'IMAGE=quay.io/integreatly/backup-container:master' \ -p 'CRON_SCHEDULE=* */1 * * *' \ --p 'NAME=mysql-backup' +-p 'NAME=mysql-backup' \ +-p 'PRODUCT_NAME=3scale' ``` Note: There is knonwn issue in openshift 3.11 around using cronjobs in templates where you may get the following error: `error: no kind "CronJob" is registered for version "batch/v1" in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"`, you will need to process the template first and then piping process command output to `oc apply` command: @@ -43,7 +44,8 @@ oc process \ -p 'ENCRYPTION_SECRET_NAME=sample-gpg-secret' \ -p 'IMAGE=quay.io/integreatly/backup-container:master' \ -p 'CRON_SCHEDULE=* */1 * * *' \ --p 'NAME=mysql-backup' | oc apply -f - +-p 'NAME=mysql-backup' \ +-p 'PRODUCT_NAME=3scale' | oc apply -f - ``` Parameters: @@ -51,6 +53,7 @@ Parameters: ``` NAME DESCRIPTION GENERATOR VALUE NAME Unique job name to be used in several resource name(s) integreatly-cronjob-backup +PRODUCT_NAME Middleware product name to have its data archived COMPONENT Component name to run the backup BACKEND Backend engine to upload the component archive s3 ENCRYPTION Encryption engine to encrypt component archive before uploading it gpg @@ -75,7 +78,8 @@ oc new-app \ -p 'BACKEND_SECRET_NAME=sample-s3-secret' \ -p 'ENCRYPTION_SECRET_NAME=sample-gpg-secret' \ -p 'IMAGE=quay.io/integreatly/backup-container:master' \ --p 'NAME=mysql-backup' +-p 'NAME=mysql-backup' \ +-p 'PRODUCT_NAME=3scale' ``` Parameters: @@ -83,6 +87,7 @@ Parameters: ``` NAME DESCRIPTION GENERATOR VALUE NAME Unique job name to be used in several resource name(s) integreatly-job-backup +PRODUCT_NAME Middleware product name to have its data archived COMPONENT Component name to run the backup BACKEND Backend engine to upload the component archive s3 ENCRYPTION Encryption engine to encrypt component archive before uploading it gpg diff --git a/templates/openshift/backup-cronjob-template.yaml b/templates/openshift/backup-cronjob-template.yaml index 046e1ab..9c783fb 100644 --- a/templates/openshift/backup-cronjob-template.yaml +++ b/templates/openshift/backup-cronjob-template.yaml @@ -47,6 +47,9 @@ parameters: - name: NAME description: Unique job name to be used in several resource name(s) value: integreatly-cronjob-backup + - name: PRODUCT_NAME + description: Middleware product name to have its data archived + required: true - name: COMPONENT description: Component name to run the backup required: true diff --git a/templates/openshift/backup-job-template.yaml b/templates/openshift/backup-job-template.yaml index facaac6..becabfb 100644 --- a/templates/openshift/backup-job-template.yaml +++ b/templates/openshift/backup-job-template.yaml @@ -41,11 +41,16 @@ objects: value: "${ENCRYPTION_SECRET_NAME}" - name: COMPONENT_SECRET_NAME value: "${COMPONENT_SECRET_NAME}" + - name: PRODUCT_NAME + value: "${PRODUCT_NAME}" restartPolicy: Never parameters: - name: NAME description: Unique job name to be used in several resource name(s) value: integreatly-job-backup + - name: PRODUCT_NAME + description: Middleware product name to have its data archived + required: true - name: COMPONENT description: Component name to run the backup required: true