From d6c26a63fd4ae5906378a609af244b03f44114c6 Mon Sep 17 00:00:00 2001 From: Nick Santamaria Date: Tue, 9 Jan 2024 09:59:47 +1100 Subject: [PATCH] Added db-dump-sanitized.sh script (#232) --- images/php/Dockerfile.cli | 1 + images/php/db-build.sh | 7 +------ images/php/db-dump-sanitized.sh | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100755 images/php/db-dump-sanitized.sh diff --git a/images/php/Dockerfile.cli b/images/php/Dockerfile.cli index e32ff184..8115480b 100644 --- a/images/php/Dockerfile.cli +++ b/images/php/Dockerfile.cli @@ -39,6 +39,7 @@ COPY redis-cluster.services.yml /bay COPY redis-single.services.yml /bay COPY settings.php /bay COPY db-build.sh /bay +COPY db-dump-sanitized.sh /bay COPY mtk /bay/mtk # Change worker pool from dynamic to static. Change default value to 24. diff --git a/images/php/db-build.sh b/images/php/db-build.sh index 57501e3f..9a9535a4 100755 --- a/images/php/db-build.sh +++ b/images/php/db-build.sh @@ -26,12 +26,7 @@ cleanup() { if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then trap cleanup EXIT info "creating sanitized database dump with mtk - https://github.com/skpr/mtk" - mtk dump \ - --user "${MARIADB_USERNAME}" \ - --password "${MARIADB_PASSWORD}" \ - --port "${MARIADB_PORT}" \ - --host "${MARIADB_HOST}" \ - "${MARIADB_DATABASE}" > "${DB_TEMPORARY_FILE}" || fatal "failed to dump database" + /bay/db-dump-sanitized.sh > "${DB_TEMPORARY_FILE}" || fatal "failed to dump database" info "pushing database dump to s3 - ${S3_OBJECT_PATH}" aws s3 cp --no-progress "${DB_TEMPORARY_FILE}" "${S3_OBJECT_PATH}" || fatal "failed to push dump to s3" diff --git a/images/php/db-dump-sanitized.sh b/images/php/db-dump-sanitized.sh new file mode 100755 index 00000000..79f720fc --- /dev/null +++ b/images/php/db-dump-sanitized.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +#/ Usage: ./db-dump-sanitized.sh +#/ Description: dumps a sanitized database to stdout +#/ Options: +#/ --help: Display this help message +usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; } +expr "$*" : ".*--help" > /dev/null && usage + +mtk dump \ + --user "${MARIADB_USERNAME}" \ + --password "${MARIADB_PASSWORD}" \ + --port "${MARIADB_PORT}" \ + --host "${MARIADB_HOST}" \ + "${MARIADB_DATABASE}"