forked from opea-project/Enterprise-Inference
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostgres-backup-cronjob.yaml
More file actions
73 lines (73 loc) · 2.85 KB
/
postgres-backup-cronjob.yaml
File metadata and controls
73 lines (73 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright (C) 2025-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
{{- if .Values.backup.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: postgres-backup
spec:
schedule: "{{ .Values.backup.postgresBackupSchedule }}" # Moved to values.yaml
jobTemplate:
spec:
template:
spec:
containers:
- name: pg-backup
image: postgres:17.5
env:
- name: PGURL
value: "postgresql://{{ .Values.postgresql.auth.username }}:{{ .Values.postgresql.auth.password }}@genai-gateway-postgresql:5432/{{ .Values.postgresql.auth.database }}"
- name: AWS_ACCESS_KEY_ID
value: "{{ .Values.backup.s3.accessKeyId }}"
- name: AWS_SECRET_ACCESS_KEY
value: "{{ .Values.backup.s3.secretAccessKey }}"
- name: AWS_DEFAULT_REGION
value: "{{ .Values.backup.s3.region }}"
command:
- "/bin/bash"
- "-c"
- |
echo "Waiting for PostgreSQL to be ready..." && \
until pg_isready -d "$PGURL"; do echo "Waiting for PostgreSQL..."; sleep 5; done && \
echo "PostgreSQL is ready. Starting backup..." && \
apt-get update && apt-get install -y awscli && \
{{- if .Values.backup.pvc.enabled }}
BACKUP_DIR=/backup
{{- else }}
BACKUP_DIR=/tmp/backup
mkdir -p $BACKUP_DIR
{{- end }}
BACKUP_FILE=$BACKUP_DIR/backup-$(date +%F-%H-%M).sql && \
pg_dump $PGURL -f $BACKUP_FILE && \
if [ "{{ .Values.backup.s3.enabled }}" = "true" ]; then \
aws s3 cp $BACKUP_FILE s3://{{ .Values.backup.s3.bucket }}/$(basename $BACKUP_FILE); \
echo " Backup uploaded to S3 bucket s3://{{ .Values.backup.s3.bucket }}/$(basename $BACKUP_FILE)"; \
fi
{{- if .Values.backup.pvc.enabled }}
echo "Backup saved to PVC at $BACKUP_FILE"
{{- end }}
{{- if .Values.backup.pvc.enabled }}
volumeMounts:
- name: backup-volume
mountPath: /backup
{{- end }}
restartPolicy: OnFailure
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.backup.pvc.enabled }}
volumes:
- name: backup-volume
persistentVolumeClaim:
claimName: {{ .Values.backup.pvc.claimName }}
{{- end }}
{{- end }}