Skip to content

Commit

Permalink
Merge pull request #42 from JarvusInnovations/releases/charts/metabas…
Browse files Browse the repository at this point in the history
…e/r4

feat(metabase): add backup feature
  • Loading branch information
themightychris authored Jan 12, 2025
2 parents 7ae785d + d1dcd9e commit ca63de6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
90 changes: 90 additions & 0 deletions charts/metabase/templates/backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{{- if .Values.backups.enabled -}}
apiVersion: batch/v1
kind: CronJob
metadata:
name: database-backup
namespace: {{ .Release.Namespace }}
spec:
schedule: {{ .Values.backups.schedule | quote }}
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: {{ .Values.images.backup.src }}
envFrom:
- configMapRef:
name: database-config
- secretRef:
name: {{ .Values.backups.secretName }}
env:
- name: PGHOST
value: database
- name: PGPORT
value: {{ .Values.workloads.database.port | quote }}
- name: PGUSER
valueFrom:
configMapKeyRef:
name: database-config
key: POSTGRES_USER
- name: PGPASSWORD
valueFrom:
configMapKeyRef:
name: database-config
key: POSTGRES_PASSWORD
- name: PGDATABASE
valueFrom:
configMapKeyRef:
name: database-config
key: POSTGRES_DB
{{- if .Values.backups.healthchecksUrl }}
- name: HEALTHCHECKS_URL
value: {{ .Values.backups.healthchecksUrl }}
{{- end }}
command:
- /bin/sh
- -c
- |
set -e
echo "Starting backup job..."
# Handle Google credentials if needed
if [ ! -z "$GOOGLE_APPLICATION_CREDENTIALS" ] && [[ "$GOOGLE_APPLICATION_CREDENTIALS" != *.json ]]; then
echo "Writing Google credentials..."
CREDS_JSON="/tmp/google-creds-$$.json"
echo "$GOOGLE_APPLICATION_CREDENTIALS" > "$CREDS_JSON"
export GOOGLE_APPLICATION_CREDENTIALS="$CREDS_JSON"
fi
{{- if .Values.backups.healthchecksUrl }}
echo "Pinging healthcheck start..."
curl -fsS -m 10 --retry 5 -o /dev/null $HEALTHCHECKS_URL/start
{{- end }}
# Backup database
echo "Starting database backup..."
pg_dump \
| restic backup \
--host {{ .Release.Namespace }}-database-backup \
--stdin \
--stdin-filename db-dump.sql
# Prune old backups
echo "Starting backup pruning..."
restic forget \
--keep-last {{ .Values.backups.prune.keepLast }} \
--keep-daily {{ .Values.backups.prune.keepDaily }} \
--keep-weekly {{ .Values.backups.prune.keepWeekly }} \
--prune
{{- if .Values.backups.healthchecksUrl }}
echo "Pinging healthcheck completion..."
curl -fsS -m 10 --retry 5 -o /dev/null $HEALTHCHECKS_URL
{{- end }}
echo "Backup job completed successfully"
restartPolicy: OnFailure
{{- end }}
12 changes: 12 additions & 0 deletions charts/metabase/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ images:
src: metabase/metabase:latest
databaseExporter:
src: quay.io/prometheuscommunity/postgres-exporter:latest
backup:
src: ghcr.io/jarvusinnovations/restic-toolkit:latest

workloads:
database:
Expand Down Expand Up @@ -59,3 +61,13 @@ volumes:
database:
data:
size: 10Gi

backups:
enabled: false
schedule: "40 * * * *"
healthchecksUrl: ~
secretName: "restic"
prune:
keepLast: 3
keepDaily: 7
keepWeekly: 52

0 comments on commit ca63de6

Please sign in to comment.