Skip to content

Commit

Permalink
ADD ipeer db backup cronjob
Browse files Browse the repository at this point in the history
The old email cronjob template was moved from cronjob.yaml to
cronjob-email.yaml and the new db cronjob template is named
cronjob-backup.yaml.

This migrates the old manually created prod db backup cronjob to one
that's managed by the chart. The old cronjob was no longer working ever
since we started using replication since the db pod names were changed.

New config values were added for this feature under 'cronjob.backup'.
The most important is the ones specifying the nfs mount where we store
the backups, 'cronjob.backup.nfs.path' and 'cronjob.backup.nfs.server'
must be set properly in the env value files.
  • Loading branch information
ionparticle committed Mar 5, 2024
1 parent 8234c01 commit 64e3d58
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ipeer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.9
version: 0.1.11

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
54 changes: 54 additions & 0 deletions ipeer/templates/cronjob-backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- if .Values.cronjob.backup.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "ipeer.fullname" . }}-backup-cronjob
spec:
schedule: {{ .Values.cronjob.backup.schedule | quote }}
jobTemplate:
spec:
template:
spec:
containers:
- name: {{ include "ipeer.fullname" . }}-backup-cronjob
image: "{{ .Values.db.image.repository }}:{{ .Values.db.image.tag }}"
args:
- /bin/sh
- -c
- |
set -e
echo "[$(date)] - Starts backing up ipeer database!"
CURRENT_YEAR=$(date +%Y)
MYSQLDMP_FILE=/db_archives/$CURRENT_YEAR/$IPEER_ENV_NAME-db-$(date +%F_%T).sql.gz
mkdir -p /db_archives/$CURRENT_YEAR
mysqldump -u"$IPEER_DB_USER" -p"$IPEER_DB_PASSWORD" -h"$IPEER_DB_HOST" ipeer --single-transaction --quick | gzip > $MYSQLDMP_FILE
zgrep "Dump completed" $MYSQLDMP_FILE
env:
- name: IPEER_ENV_NAME
value: {{ include "ipeer.fullname" . }}
- name: IPEER_DB_HOST
value: {{ template "ipeer.db.fullname" . }}
- name: IPEER_DB_PORT
value: {{ .Values.db.service.port | quote }}
- name: IPEER_DB_USER
value: {{ .Values.db.auth.username | quote }}
- name: IPEER_DB_PASSWORD
valueFrom:
secretKeyRef:
{{- if .Values.db.disableExternal }}
name: {{ template "ipeer.db.secretName" . }}
key: mariadb-password
{{- else }}
name: {{ template "ipeer.fullname" . }}
key: db_password
{{- end }}
volumeMounts:
- mountPath: /db_archives
name: nfs-volume
restartPolicy: Never
volumes:
- name: nfs-volume
nfs:
path: {{ .Values.cronjob.backup.nfs.path | quote }}
server: {{ .Values.cronjob.backup.nfs.server | quote }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.cronjob.enabled }}
{{- if .Values.cronjob.email.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
Expand Down
9 changes: 8 additions & 1 deletion ipeer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ worker:
enabled: false

cronjob:
enabled: true
email:
enabled: true
backup:
enabled: false
schedule: "00 09 * * *"
nfs:
path: 'REPLACEME'
server: 'REPLACEME'

imagePullSecrets: []
nameOverride: ""
Expand Down

0 comments on commit 64e3d58

Please sign in to comment.