Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
drmalex07 committed Apr 18, 2024
2 parents e5f8ba5 + 30f1a7f commit ab155e3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mariadb-backup/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ appVersion: "10.11"
description: Backup a MariaDB database
name: mariadb-backup
type: application
version: 0.2.0
version: 0.3.0
7 changes: 0 additions & 7 deletions mariadb-backup/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,3 @@ Create the name of the service account to use
{{- end }}
{{- end }}

{{/*
Name of the job
*/}}
{{- define "mariadb-backup.jobName" -}}
{{ (include "mariadb-backup.fullname" .) }}
{{- end }}

73 changes: 67 additions & 6 deletions mariadb-backup/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# vim: set filetype=helm:

{{- $outputFile := .Values.backup.outputFile.fileName| default (printf "%s~%s.sql.gz" .Values.backup.database.name (now| date "20060102150405")) }}
{{- $timestamp := (now | date "20060102150405") }}
{{- $jobName := printf "%s-%s" (include "mariadb-backup.fullname" .) $timestamp }}
{{- $outputName := .Values.backup.outputFile.fileName | default (printf "%s@%s.sql.gz" .Values.backup.database.name $timestamp) }}

apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "mariadb-backup.jobName" . }}
name: {{ $jobName }}
labels:
{{- include "mariadb-backup.labels" . | nindent 4 }}
spec:
Expand Down Expand Up @@ -35,6 +37,12 @@ spec:
claimName: {{ .Values.backup.outputFile.pvcName }}
- name: home
emptyDir: {}
{{- if .Values.backup.s3.bucket }}
- name: s3cmd-config
secret:
secretName: {{ .Values.s3cmd.config.secretName }}
defaultMode: 0640
{{- end }}
initContainers:
- name: prepare-config
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand Down Expand Up @@ -64,7 +72,6 @@ spec:
volumeMounts:
- name: home
mountPath: /var/lib/mysql
containers:
- name: backup
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand All @@ -73,14 +80,14 @@ spec:
env:
- name: DB_NAME
value: {{ .Values.backup.database.name }}
- name: OUTPUT_FILE
value: {{ $outputFile }}
- name: OUTPUT_NAME
value: {{ $outputName }}
command:
- sh
- -xue
- -c
- |-
mariadb-dump --lock-tables -v ${DB_NAME} | gzip -c > ${OUTPUT_FILE}
mariadb-dump --lock-tables -v ${DB_NAME} | gzip -c > "${OUTPUT_NAME}"
workingDir: /work
volumeMounts:
- name: home
Expand All @@ -92,6 +99,60 @@ spec:
subPath: {{ . }}
{{- end }}{{/* with .subPath */}}
{{- end }}{{/* with .Values.backup.outputFile */}}
resources: {{- toYaml .Values.resources | nindent 10 }}
{{- if .Values.backup.s3.bucket }}
- name: s3cmd
image: "{{ .Values.s3cmd.image.repository }}:{{ .Values.s3cmd.image.tag }}"
imagePullPolicy: {{ .Values.s3cmd.image.pullPolicy }}
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
env:
- name: OUTPUT_NAME
value: {{ $outputName }}
- name: DEST_URL
value: {{ printf "s3://%s/%s/%s" (.Values.backup.s3.bucket) (.Values.backup.s3.prefix | default "") $outputName }}
command:
- s3cmd
- --verbose
- --no-preserve
- put
- $(OUTPUT_NAME)
- $(DEST_URL)
workingDir: /work
volumeMounts:
- name: s3cmd-config
mountPath: /.s3cfg
subPath: s3cmd.conf
readOnly: true
{{- with .Values.backup.outputFile }}
- name: output
mountPath: /work
{{- with .subPath }}
subPath: {{ . }}
{{- end }}{{/* with .subPath */}}
{{- end }}{{/* with .Values.backup.outputFile */}}
resources: {{- toYaml .Values.resources | nindent 10 }}
{{- end }}{{/* if .Values.backup.s3.bucket */}}
containers:
- name: stat
image: busybox:1.36
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
env:
- name: OUTPUT_NAME
value: {{ $outputName }}
command:
- stat
- $(OUTPUT_NAME)
workingDir: /work
volumeMounts:
{{- with .Values.backup.outputFile }}
- name: output
mountPath: /work
{{- with .subPath }}
subPath: {{ . }}
{{- end }}{{/* with .subPath */}}
{{- end }}{{/* with .Values.backup.outputFile */}}
resources: {{- toYaml .Values.resources | nindent 10 }}
{{- with .Values.nodeSelector }}
nodeSelector:
Expand Down
15 changes: 15 additions & 0 deletions mariadb-backup/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ tolerations: []
affinity: {}

backup:
# target of the backup (in a PV)
outputFile:
pvcName: backups
subPath: ~
#fileName: backup.sql.gz
# (optional) upload the backup file to an S3 bucket
s3:
bucket: ~
#bucket: backups
#prefix: mariadb
database:
name: example
host: mariadb
Expand All @@ -55,4 +61,13 @@ backup:
secretName: someone-password
key: password

# s3cmd only needed if an s3 bucket is also specified
s3cmd:
image:
repository: ghcr.io/eosc-lot-1/s3cmd
pullPolicy: IfNotPresent
tag: 2-alpine
config:
secretName: s3cmd-config


0 comments on commit ab155e3

Please sign in to comment.