From a88ddeb51249ef44cf915f10edc5f009488c0536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Sat, 26 Jan 2019 19:03:49 +0100 Subject: [PATCH] added directory option (#10813) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Bauer --- stable/mysqldump/Chart.yaml | 4 +- stable/mysqldump/README.md | 88 ++++++++++++----------- stable/mysqldump/templates/configmap.yaml | 13 ++-- stable/mysqldump/values.yaml | 9 ++- 4 files changed, 61 insertions(+), 53 deletions(-) diff --git a/stable/mysqldump/Chart.yaml b/stable/mysqldump/Chart.yaml index 24183c210a..db2beae511 100644 --- a/stable/mysqldump/Chart.yaml +++ b/stable/mysqldump/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 -appVersion: 2.0.0 +appVersion: 2.2.0 description: A Helm chart to help backup MySQL databases using mysqldump name: mysqldump -version: 2.1.3 +version: 2.2.0 keywords: - mysql - mysqldump diff --git a/stable/mysqldump/README.md b/stable/mysqldump/README.md index e2ff63d607..8251e1fd3d 100644 --- a/stable/mysqldump/README.md +++ b/stable/mysqldump/README.md @@ -13,9 +13,9 @@ $ helm install stable/mysqldump \ This chart helps set up a cronjob or one time job to backup a MySQL database with mysqldump into a Persistent Volume. You can specify an existing PVC, or helm will create one for you. - ## Prerequisites - - Kubernetes 1.8 + +- Kubernetes 1.8 ## Installing the Chart @@ -44,49 +44,51 @@ The command removes all the Kubernetes components associated with the chart and The following tables lists the configurable parameters of the mysqldump chart and their default values. -Parameter | Description | Default -------------------------------- | ----------------------------------------- | ------------------------------ -image.repository | Name of image to use | monotek/gcloud-mysql -image.tag | Version of image to use | "6" -image.pullPolicy | Pull Policy to use for image | IfNotPresent -mysql.db | single mysql db to backup (optional) | mysql -mysql.host | mysql host to backup | mysql -mysql.username | mysql username | root -mysql.password | mysql password | "" -mysql.port | mysql port | 3306 -schedule | crontab schedule to run on. set as `now` to run as a one time job | "0/5 * * * *" -options | options to pass onto MySQL | "--opt --single-transaction" -debug | print some extra debug logs during backup | false -successfulJobsHistoryLimit | number of successful jobs to remember | 5 -failedJobsHistoryLimit | number of failed jobs to remember | 5 -persistentVolumeClaim | existing Persistent Volume Claim to backup to, leave blank to create a new one -persistence.enabled | create new PVC (unless `persistentVolumeClaim` is set) | true -persistence.size | size of PVC to create | 8Gi -persistence.accessMode | accessMode to use for PVC | ReadWriteOnce -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 singel file | false -housekeeping.enabled | delete olf backups in pvc | true -housekeeping.keepDays | keep last x days of backups in PVC | 10 -upload.googlestoragebucket.enabled | upload backups to google storage | false -upload.googlestoragebucket.bucketname | google storage address | gs://mybucket/test -upload.googlestoragebucket.jsonKeyfile | json keyfile for serviceaccount | "" -upload.googlestoragebucket.existingSecret | specify a secretname to use | nil -upload.googlestoragebucket.usingGCPController | enable the use of the GCP Service Account Controller | false -upload.googlestoragebucket.serviceAccountName | specify a service account name to use | nil -upload.ssh.enabled | upload backups via ssh | false -upload.ssh.user | ssh user | backup -upload.ssh.host | ssh server url | yourdomain.com -upload.ssh.dir | directory on server | /backup -upload.ssh.privatekey | ssh user private key | "" -resources | resource definitions | {} -nodeSelector | node selector | {} -tolerations | tolerations | [] -affinity | affinity | {} +| Parameter | Description | Default | +| --------------------------------------------- | ------------------------------------------------------------------------------ | ---------------------------- | +| image.repository | Name of image to use | monotek/gcloud-mysql | +| image.tag | Version of image to use | "6" | +| image.pullPolicy | Pull Policy to use for image | IfNotPresent | +| mysql.db | single mysql db to backup (optional) | mysql | +| mysql.host | mysql host to backup | mysql | +| mysql.username | mysql username | root | +| mysql.password | mysql password | "" | +| mysql.port | mysql port | 3306 | +| schedule | crontab schedule to run on. set as `now` to run as a one time job | "0/5 \* \* \* \*" | +| options | options to pass onto MySQL | "--opt --single-transaction" | +| debug | print some extra debug logs during backup | false | +| successfulJobsHistoryLimit | number of successful jobs to remember | 5 | +| failedJobsHistoryLimit | number of failed jobs to remember | 5 | +| persistentVolumeClaim | existing Persistent Volume Claim to backup to, leave blank to create a new one | | +| persistence.enabled | create new PVC (unless `persistentVolumeClaim` is set) | true | +| persistence.size | size of PVC to create | 8Gi | +| persistence.accessMode | accessMode to use for PVC | ReadWriteOnce | +| 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 singel file | 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 | +| upload.googlestoragebucket.enabled | upload backups to google storage | false | +| upload.googlestoragebucket.bucketname | google storage address | gs://mybucket/test | +| upload.googlestoragebucket.jsonKeyfile | json keyfile for serviceaccount | "" | +| upload.googlestoragebucket.existingSecret | specify a secretname to use | nil | +| upload.googlestoragebucket.usingGCPController | enable the use of the GCP Service Account Controller | false | +| upload.googlestoragebucket.serviceAccountName | specify a service account name to use | nil | +| upload.ssh.enabled | upload backups via ssh | false | +| upload.ssh.user | ssh user | backup | +| upload.ssh.host | ssh server url | yourdomain.com | +| upload.ssh.dir | directory on server | /backup | +| upload.ssh.privatekey | ssh user private key | "" | +| resources | resource definitions | {} | +| nodeSelector | node selector | {} | +| tolerations | tolerations | \[] | +| affinity | affinity | {} | ### Auto generating the gcp service account -By enabling the flag `upload.googlestoragebucket.usingGCPController` and having a GCP Service Account Controller deployed in your cluster, it is possible to autogenerate and inject the service account used for the storage bucket access. For more information see https://github.com/kiwigrid/helm-charts/tree/master/charts/gcp-serviceaccount-controller + +By enabling the flag `upload.googlestoragebucket.usingGCPController` and having a GCP Service Account Controller deployed in your cluster, it is possible to autogenerate and inject the service account used for the storage bucket access. For more information see ```console $ helm install stable/mysqldump --name my-release \ diff --git a/stable/mysqldump/templates/configmap.yaml b/stable/mysqldump/templates/configmap.yaml index dd2c1e4d60..c5b7a367d7 100644 --- a/stable/mysqldump/templates/configmap.yaml +++ b/stable/mysqldump/templates/configmap.yaml @@ -47,25 +47,28 @@ data: {{ if .Values.housekeeping.enabled }} echo "delete old backups" - find ${BACKUP_DIR} -maxdepth 1 -mtime +${KEEP_DAYS} -regex "^${BACKUP_DIR}/[0-9]*_.*\.sql\.gz$" -type f -exec rm {} \; + find ${BACKUP_DIR} -maxdepth 2 -mtime +${KEEP_DAYS} -regex "^${BACKUP_DIR}/.*[0-9]*_.*\.sql\.gz$" -type f -exec rm {} \; {{ end -}} {{ if and (.Values.mysql.db) (eq .Values.allDatabases.enabled false) }} MYSQL_DB="{{ .Values.mysql.db }}" echo "Backing up single db ${MYSQL_DB}" - mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} ${MYSQL_DB} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_${MYSQL_DB}.sql.gz + {{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }} + mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --database ${MYSQL_DB} | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz {{ else if and (.Values.allDatabases.enabled) (eq .Values.allDatabases.singleBackupFile false)}} for MYSQL_DB in $(mysql -h "${MYSQL_HOST}" -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} -B -N -e "SHOW DATABASES;"|egrep -v '^(information|performance)_schema$'); do echo "Backing up db ${MYSQL_DB}" - mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} ${MYSQL_DB} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_${MYSQL_DB}.sql.gz + {{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }} + mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --database ${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" MYSQL_DB="alldatabases" - mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --all-databases | gzip > ${BACKUP_DIR}/${TIMESTAMP}_${MYSQL_DB}.sql.gz + {{ if .Values.saveToDirectory }}mkdir -p "${BACKUP_DIR}"/"${MYSQL_DB}"{{ end }} + mysqldump ${MYSQL_OPTS} -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u ${MYSQL_USERNAME}{{ if .Values.mysql.password }} -p${MYSQL_PASSWORD}{{ end }} --all-databases | gzip > ${BACKUP_DIR}/{{ if .Values.saveToDirectory }}${MYSQL_DB}/{{ end }}${TIMESTAMP}_${MYSQL_DB}.sql.gz rc=$? {{- end -}} @@ -79,7 +82,7 @@ data: {{ if .Values.upload.googlestoragebucket.enabled }} echo "upload files to google storage bucket {{ .Values.upload.googlestoragebucket.bucketname }}" gcloud auth activate-service-account --key-file /root/gcloud/{{ .Values.upload.googlestoragebucket.secretFileName }} - gsutil -m rsync -x '.*\.state' -d ${BACKUP_DIR}/ {{ .Values.upload.googlestoragebucket.bucketname }} + gsutil -r -m rsync -x '.*\.state' -d ${BACKUP_DIR}/ {{ .Values.upload.googlestoragebucket.bucketname }} rcu=$? {{ end }} diff --git a/stable/mysqldump/values.yaml b/stable/mysqldump/values.yaml index 2f74a46f0d..5178d55ecf 100644 --- a/stable/mysqldump/values.yaml +++ b/stable/mysqldump/values.yaml @@ -23,17 +23,20 @@ allDatabases: # creates single backup file with all databases singleBackupFile: false -## options to pass to mysqldump +# options to pass to mysqldump options: "--opt --single-transaction" +# save sql backup to a directory named like the database or "alldatabases" +saveToDirectory: false + ## set to `now` to get a one time job, or a cronjob schedule like `0 0 * * *` ## to get a cronjob. schedule: "0 3 * * *" -## enable some debug options +# enable some debug options debug: false -## cronjob history +# cronjob history successfulJobsHistoryLimit: 5 failedJobsHistoryLimit: 5