Skip to content

Commit

Permalink
create new secret for moodle-database values (except password), that …
Browse files Browse the repository at this point in the history
…is used by backup/restore. so that backup/restore can work properly with all possible databases
  • Loading branch information
JannikBadenhop committed Nov 14, 2024
1 parent 63d23a1 commit 8228014
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
13 changes: 7 additions & 6 deletions charts/dbp-moodle/scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ cd "${backup_dir}"
echo "=== Start DB dump ==="
export DATE=$( date "+%Y-%m-%d" )

{{ if .Values.mariadb.enabled }}
MYSQL_PWD="$DATABASE_PASSWORD" mysqldump -h {{ .Release.Name }}-mariadb -P {{ .Values.mariadb.primary.containerPorts.mysql }} -u {{ .Values.mariadb.auth.username }} {{ .Values.mariadb.auth.database }} > moodle_mariadb_dump_$DATE.sql
gzip moodle_mariadb_dump_$DATE.sql
{{ else }}
PGPASSWORD="$DATABASE_PASSWORD" pg_dump -h {{ .Release.Name }}-postgresql -p {{ .Values.postgresql.containerPorts.postgresql }} -U postgres {{ .Values.postgresql.auth.database }} > moodle_postgresqldb_dump_$DATE.sql
gzip moodle_postgresqldb_dump_$DATE.sql
# shellcheck disable=all
{{ if or .Values.mariadb.enabled (eq .Values.moodle.externalDatabase.type "mariadb") }}
MYSQL_PWD="$DATABASE_PASSWORD" mysqldump -h "$DATABASE_HOST" -P "$DATABASE_PORT" -u "$DATABASE_USER" "$DATABASE_NAME" > "moodle_mariadb_dump_${DATE}.sql"
gzip "moodle_mariadb_dump_${DATE}.sql"
{{ else if or .Values.postgresql.enabled (eq .Values.moodle.externalDatabase.type "pgsql") }}
PGPASSWORD="$DATABASE_PASSWORD" pg_dump -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" "$DATABASE_NAME" > "moodle_postgresqldb_dump_${DATE}.sql"
gzip "moodle_postgresqldb_dump_${DATE}.sql"
{{ end }}

# Get moodle folder
Expand Down
21 changes: 21 additions & 0 deletions charts/dbp-moodle/templates/secrets/moodle-database-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: "moodle-database"
namespace: "{{ .Release.Namespace }}"
stringData:
{{ if .Values.moodle.mariadb.enabled -}}
type: "mariadb"
host: "moodle-mariadb-0"
port: "3306"
user: "{{ .Values.moodle.mariadb.username }}"
name: "{{ .Values.moodle.mariadb.database }}"
{{- else if .Values.moodle.externalDatabase -}}
type: "{{ .Values.moodle.externalDatabase.type }}"
host: "{{ .Values.moodle.externalDatabase.host }}"
port: "{{ .Values.moodle.externalDatabase.port }}"
user: "{{ .Values.moodle.externalDatabase.user }}"
name: "{{ .Values.moodle.externalDatabase.database }}"
{{- end }}

22 changes: 22 additions & 0 deletions charts/dbp-moodle/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ moodle:
# -- The mariadb included in bitnami/moodle chart. For this chart usage of mariadb.enabled with moodle.externalDatabase.type="mariadb" is recommended
mariadb:
enabled: false
database: bitnami_moodle
username: bn_moodle
externalDatabase:
# -- Type of DB to provision, possible values are "mariadb" and "pgsql"
type: "mariadb"
Expand Down Expand Up @@ -556,6 +558,26 @@ backup-cronjob:
name: "moodle-backup-job"
create: false
env:
- name: DATABASE_HOST
valueFrom:
secretKeyRef:
name: moodle-database
key: host
- name: DATABASE_PORT
valueFrom:
secretKeyRef:
name: moodle-database
key: port
- name: DATABASE_NAME
valueFrom:
secretKeyRef:
name: moodle-database
key: name
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: moodle-database
key: user
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
Expand Down

0 comments on commit 8228014

Please sign in to comment.