From f08f1eac30b68e6cd82c176fa7cec17367a9ee13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20COELHO?= Date: Thu, 5 Oct 2023 13:51:48 +0200 Subject: [PATCH] Update configmap-script.yaml (#151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update configmap-script.yaml for backup a list of database not juste all or a single one Signed-off-by: Frédéric COELHO * update chart version to 6.1.0 Signed-off-by: Frédéric COELHO * update mysqldump readme for mysql.db for multi db Signed-off-by: Frédéric COELHO * update documentation from values.yaml Signed-off-by: Frédéric COELHO * fixed spaces in configuration table for mysql.db line in readme file Signed-off-by: Frédéric COELHO * Update Chart.yaml Signed-off-by: Frédéric COELHO * Update Chart.yaml Signed-off-by: Frédéric COELHO --------- Signed-off-by: Frédéric COELHO --- charts/mysqldump/Chart.yaml | 2 +- charts/mysqldump/README.md | 4 +-- .../mysqldump/templates/configmap-script.yaml | 29 +++++++++++-------- charts/mysqldump/values.yaml | 4 +-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/charts/mysqldump/Chart.yaml b/charts/mysqldump/Chart.yaml index c6c6a32..4363296 100644 --- a/charts/mysqldump/Chart.yaml +++ b/charts/mysqldump/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -version: 6.1.0 +version: 6.2.0 appVersion: v3.1.1 description: A Helm chart to help backup MySQL databases using mysqldump name: mysqldump diff --git a/charts/mysqldump/README.md b/charts/mysqldump/README.md index 68e732f..aa0dcdd 100644 --- a/charts/mysqldump/README.md +++ b/charts/mysqldump/README.md @@ -50,7 +50,7 @@ The following tables lists the configurable parameters of the mysqldump chart an | image.repository | Name of image to use | monotek/gcloud-mysql | | image.tag | Version of image to use (uses appVersion form Chart.yaml as default if not set) | "" | | image.pullPolicy | Pull Policy to use for image | IfNotPresent | -| mysql.db | single mysql db to backup (optional) | mysql | +| mysql.db | mysql db(s) to backup (optional) | mysql | | mysql.host | mysql host to backup | mysql | | mysql.username | mysql username | root | | mysql.password | mysql password | "" | @@ -72,7 +72,7 @@ The following tables lists the configurable parameters of the mysqldump chart an | persistence.storageClass | storage class to use for PVC | | | persistence.subPath | subPath for PVC | | | allDatabases.enabled | backup all databases | true | -| allDatabases.SingleSqlFile | backup all databases to single file | false | +| allDatabases.SingleSqlFile | backup all databases to single file (works with mysql.db too) | false | | housekeeping.enabled | delete olf backups in pvc | true | | housekeeping.keepDays | keep last x days of backups in PVC | 10 | | saveToDirectory | saves the sql backup to a directory named like the database or alldatabases | false | diff --git a/charts/mysqldump/templates/configmap-script.yaml b/charts/mysqldump/templates/configmap-script.yaml index 258f746..c192eb7 100644 --- a/charts/mysqldump/templates/configmap-script.yaml +++ b/charts/mysqldump/templates/configmap-script.yaml @@ -39,27 +39,32 @@ data: {{ end -}} {{ end -}} - {{ if and (.Values.mysql.db) (eq .Values.allDatabases.enabled false) }} - MYSQL_DB="{{ .Values.mysql.db }}" - echo "Backing up single db ${MYSQL_DB}" - {{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }} - mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME} --databases ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz - rc=$? - {{ else if and (.Values.allDatabases.enabled) (eq .Values.allDatabases.singleBackupFile false)}} - for MYSQL_DB in $(mysql -h "${MYSQL_HOST}" -P ${MYSQL_PORT} -u ${MYSQL_USERNAME} -B -N -e "SHOW DATABASES;"|egrep -v '^(information|performance)_schema$'); do + {{ if (eq .Values.allDatabases.singleBackupFile false) }} + {{ if and (.Values.mysql.db) (eq .Values.allDatabases.enabled false) }} + MYSQL_DBS="{{ .Values.mysql.db }}" + {{ else if (.Values.allDatabases.enabled) }} + MYSQL_DBS=$(mysql -h "${MYSQL_HOST}" -P ${MYSQL_PORT} -u ${MYSQL_USERNAME} -B -N -e "SHOW DATABASES;"|egrep -v '^(information|performance)_schema$') + {{ end }} + for MYSQL_DB in $MYSQL_DBS; do echo "Backing up db ${MYSQL_DB}" {{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }} mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME} --databases ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz rc=$? done - - {{ else if and (.Values.allDatabases.enabled) (.Values.allDatabases.singleBackupFile) }} - echo "Backing up all databases" + {{ else if (.Values.allDatabases.singleBackupFile) }} MYSQL_DB="alldatabases" {{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }} + {{ if and (.Values.mysql.db) (eq .Values.allDatabases.enabled false) }} + echo "Backing up all this databases {{ .Values.mysql.db }}" + mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME} --databases {{ .Values.mysql.db }} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz + rc=$? + {{ else if (.Values.allDatabases.enabled) }} + echo "Backing up all databases" mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME} --all-databases | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz rc=$? - {{- end -}} + {{ end }} + {{ end }} + {{- if or (.Values.upload.googlestoragebucket.enabled) (.Values.upload.ssh.enabled) (.Values.upload.openstack.enabled) (.Values.upload.s3.enabled) -}} {{ if .Values.upload.ssh.enabled -}} diff --git a/charts/mysqldump/values.yaml b/charts/mysqldump/values.yaml index 8ebfd0f..85ad246 100644 --- a/charts/mysqldump/values.yaml +++ b/charts/mysqldump/values.yaml @@ -28,7 +28,7 @@ mysql: # no password means random value password: "" port: 3306 - # db name for single db backup + # db name for db(s) backup db: "" # Get password from existing secret existingSecret: "" @@ -37,7 +37,7 @@ mysql: # use --all-databases if enabled allDatabases: enabled: true - # creates single backup file with all databases + # creates single backup file with all databases (works with mysql.db too) singleBackupFile: false # options to pass to mysqldump