Skip to content

Commit 2e6b61a

Browse files
committed
chore(postgresql-cluster): Adjust backup strategy
1 parent 76fff18 commit 2e6b61a

5 files changed

Lines changed: 51 additions & 50 deletions

File tree

addons/postgresql-cluster/15/chart/postgresql-cluster/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ backup:
7474

7575
You can modify multiple content at once, there is no need to modify part of it each time.
7676

77-
# Plans
77+
## Plans
7878

7979
| Resource Specification | Cores | MEMORY | Storage SIZE |
8080
| :---: | :---: | :---: | :---: |

addons/postgresql-cluster/15/chart/postgresql-cluster/templates/_helpers.tpl

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -136,43 +136,14 @@ Create patroni envs.
136136
{{- end -}}
137137

138138
{{/*
139-
Create walg envs.
139+
Return true if a configmap object should be created for PG backup.
140140
*/}}
141-
{{- define "backup.envs" }}
142-
{{- if .Values.backup.enabled }}
143-
- name: USE_WALG
144-
value: {{ .Values.backup.enabled | quote }}
145-
{{- if .Values.backup.retainBackups }}
146-
- name: BACKUP_NUM_TO_RETAIN
147-
value: {{ .Values.backup.retainBackups | quote}}
148-
{{- end }}
149-
{{- if .Values.backup.backupThresholdMegabytes }}
150-
- name: WALG_BACKUP_THRESHOLD_MEGABYTES
151-
value: {{ .Values.backup.backupThresholdMegabytes | quote }}
152-
{{- end }}
153-
{{- if .Values.backup.backupThresholdPercentage }}
154-
- name: WALE_BACKUP_THRESHOLD_PERCENTAGE
155-
value: {{ .Values.backup.backupThresholdPercentage | quote }}
156-
{{- end }}
157-
{{- if .Values.backup.s3.used }}
158-
- name: AWS_ACCESS_KEY_ID
159-
value: {{ .Values.backup.s3.awsAccessKeyID | quote }}
160-
- name: AWS_SECRET_ACCESS_KEY
161-
value: {{ .Values.backup.s3.awsSecretAccessKey | quote }}
162-
- name: WALG_S3_PREFIX
163-
value: {{ .Values.backup.s3.walGS3Prefix | quote }}
164-
- name: AWS_ENDPOINT
165-
value: {{ .Values.backup.s3.awsEndpoint | quote }}
166-
- name: AWS_S3_FORCE_PATH_STYLE
167-
value: {{ .Values.backup.s3.awsS3ForcePathStyle | quote }}
168-
- name: AWS_REGION
169-
value: {{ .Values.backup.s3.awsRegion | quote }}
170-
{{- end }}
171-
{{- else }}
172-
- name: USE_WALG
173-
value: ""
174-
{{- end }}
175-
{{- end }}
141+
{{- define "backup.createConfigmap" -}}
142+
{{- if and .Values.backup.enabled }}
143+
{{- true -}}
144+
{{- else -}}
145+
{{- end -}}
146+
{{- end -}}
176147

177148
{{/*
178149
Generate random password
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- if (include "backup.createConfigmap" .) }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ template "common.names.fullname" . }}-backup
6+
namespace: {{ include "common.names.namespace" . | quote }}
7+
labels: {{- include "common.labels.standard" . | nindent 4 }}
8+
{{- if .Values.commonLabels }}
9+
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
10+
{{- end }}
11+
cluster-name: {{ template "patroni.fullname" . }}
12+
{{- if .Values.commonAnnotations }}
13+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
14+
{{- end }}
15+
data:
16+
backup.env: |-
17+
{{- include "common.tplvalues.render" ( dict "value" .Values.backupEnv "context" $ ) | nindent 4 }}
18+
# archive_command.sh: | -
19+
# #/bin/bash
20+
# source backup.env
21+
# [ $USE_WALG ] ? sh /opt/drycc/postgresql/walbackup.sh %p : /bin/true
22+
{{- end -}}

addons/postgresql-cluster/15/chart/postgresql-cluster/templates/statefulset.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ spec:
5656
# fsGroup: postgres
5757
env:
5858
{{- include "patroni.envs" . | indent 8 }}
59-
{{- if .Values.backup.enabled }}
60-
{{- include "backup.envs" . | indent 8 }}
61-
{{- end }}
6259
{{- if .Values.env }}
6360
{{- range $key, $val := .Values.env }}
6461
- name: {{ $key | quote | upper }}
@@ -110,6 +107,9 @@ spec:
110107
- mountPath: "/opt/drycc/postgresql/config/"
111108
name: postgresql-config
112109
# readOnly: true
110+
- mountPath: "/opt/drycc/postgresql/backup/"
111+
name: postgresql-backup
112+
# readOnly: true
113113
resources:
114114
{{ toYaml .Values.resources | indent 10 }}
115115
{{- if .Values.metrics.enabled }}
@@ -175,7 +175,6 @@ spec:
175175
- |
176176
python3 /opt/drycc/postgresql/pgbackup.py 0.0.0.0 9000
177177
env:
178-
{{- include "backup.envs" . | indent 8 }}
179178
- name: PGHOST
180179
value: localhost
181180
- name: PGPASSWORD
@@ -222,6 +221,9 @@ spec:
222221
- name: postgresql-config
223222
configMap:
224223
name: {{ template "common.names.fullname" . }}-postgresql
224+
- name: archive-config
225+
configMap:
226+
name: {{ template "common.names.fullname" . }}-backup
225227
{{- if not .Values.persistentVolume.enabled }}
226228
- name: storage-volume
227229
emptyDir: {}

addons/postgresql-cluster/15/chart/postgresql-cluster/values.yaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ preInitScript: |
8181
track_commit_timestamp: "off"
8282
archive_mode: "on"
8383
archive_timeout: 300s
84-
{{- if .Values.backup.enabled }}
85-
archive_command: sh /opt/drycc/postgresql/walbackup.sh %p
86-
{{- else }}
87-
archive_command: /bin/true
88-
{{- end }}
84+
archive_command: sh /opt/drycc/postgresql/walbackup.sh %p %p
8985
# timescaledb.license: 'timescale'
9086
shared_preload_libraries: 'auto_explain,pg_stat_statements'
9187
log_destination: 'csvlog'
@@ -134,9 +130,20 @@ postInitScript: |
134130
echo "Skipping create admin user"
135131
fi
136132
psql -w -c "CHECKPOINT;CHECKPOINT;"
137-
#norm user
138-
#
139-
#
133+
134+
backupEnv: |
135+
#!/bin/bash
136+
export USE_WALG={{ .Values.backup.enabled | quote }}
137+
export BACKUP_NUM_TO_RETAIN={{ .Values.backup.retainBackups | quote}}
138+
export WALG_BACKUP_THRESHOLD_MEGABYTES={{ .Values.backup.backupThresholdMegabytes | quote }}
139+
export WALE_BACKUP_THRESHOLD_PERCENTAGE={{ .Values.backup.backupThresholdPercentage | quote }}
140+
export AWS_ACCESS_KEY_ID={{ .Values.backup.s3.awsAccessKeyID | quote }}
141+
export AWS_SECRET_ACCESS_KEY={{ .Values.backup.s3.awsSecretAccessKey | quote }}
142+
export WALG_S3_PREFIX={{ .Values.backup.s3.walGS3Prefix | quote }}
143+
export AWS_ENDPOINT={{ .Values.backup.s3.awsEndpoint | quote }}
144+
export AWS_S3_FORCE_PATH_STYLE={{ .Values.backup.s3.awsS3ForcePathStyle | quote }}
145+
export AWS_REGION={{ .Values.backup.s3.awsRegion | quote }}
146+
140147
postgresql:
141148
config: |-
142149
log_min_duration_statement = 1000
@@ -269,7 +276,6 @@ backup:
269276
awsS3ForcePathStyle: "true"
270277
awsRegion: dx-1
271278

272-
273279
persistentVolume:
274280
enabled: true
275281
size: 10G

0 commit comments

Comments
 (0)