Skip to content

Commit d1ba873

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Add support for multi-repo backups
This starts with an example for setting up multiple backup repos for both a local Kubernetes volume and S3.
1 parent 4996a02 commit d1ba873

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

helm/postgres/templates/_s3.tpl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{{/* Allow for S3 secret information to be stored in a Secret */}}
22
{{- define "postgres.s3" }}
33
[global]
4-
{{- if .Values.s3 }}
5-
{{- if .Values.s3.key }}
6-
repo1-s3-key={{ .Values.s3.key }}
7-
{{- end }}
8-
{{- if .Values.s3.keySecret }}
9-
repo1-s3-key-secret={{ .Values.s3.keySecret }}
10-
{{- end }}
11-
{{- if .Values.s3.encryptionPassphrase }}
12-
repo1-cipher-pass={{ .Values.s3.encryptionPassphrase }}
13-
{{- end }}
4+
{{- if .s3 }}
5+
{{- if .s3.key }}
6+
repo{{ add .index 1 }}-s3-key={{ .s3.key }}
7+
{{- end }}
8+
{{- if .s3.keySecret }}
9+
repo{{ add .index 1 }}-s3-key-secret={{ .s3.keySecret }}
10+
{{- end }}
11+
{{- if .s3.encryptionPassphrase }}
12+
repo{{ add .index 1 }}-cipher-pass={{ .s3.encryptionPassphrase }}
13+
{{- end }}
1414
{{- end }}
1515
{{ end }}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
{{- if .Values.s3 }}
1+
{{- if or .Values.multiBackupRepos .Values.s3 }}
22
apiVersion: v1
33
kind: Secret
44
metadata:
55
name: {{ default .Release.Name .Values.name }}-pgbackrest-secret
66
type: Opaque
77
data:
8+
{{- if .Values.multiBackupRepos }}
9+
{{- range $index, $repo := .Values.multiBackupRepos }}
10+
{{- if $repo.s3 }}
11+
{{- $args := dict "s3" $repo.s3 "index" $index }}
812
s3.conf: |-
9-
{{ include "postgres.s3" . | b64enc }}
13+
{{ include "postgres.s3" $args | b64enc }}
14+
{{- end }}
15+
{{- end }}
16+
{{- else if .Values.s3 }}
17+
{{- $args := dict "s3" .Values.s3 "index" 0 }}
18+
s3.conf: |-
19+
{{ include "postgres.s3" $args | b64enc }}
20+
{{- end }}
1021
{{- end }}

helm/postgres/templates/postgres.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ spec:
4040
{{- end }}
4141
{{- if .Values.pgBackRestConfig }}
4242
{{ toYaml .Values.pgBackRestConfig | indent 6 }}
43+
{{- else if .Values.multiBackupRepos }}
44+
configuration:
45+
- secret:
46+
name: {{ default .Release.Name .Values.name }}-pgbackrest-secret
47+
global:
48+
{{- range $index, $repo := .Values.multiBackupRepos }}
49+
{{- if $repo.s3 }}
50+
repo{{ add $index 1 }}-path: /pgbackrest/{{ $.Release.Namespace }}/{{ default $.Release.Name $.Values.name }}/repo{{ add $index 1 }}
51+
{{- end }}
52+
{{- end }}
53+
repos:
54+
{{- range $index, $repo := .Values.multiBackupRepos }}
55+
- name: repo{{ add $index 1 }}
56+
{{- if $repo.volume }}
57+
volume:
58+
volumeClaimSpec:
59+
accessModes:
60+
- "ReadWriteOnce"
61+
resources:
62+
requests:
63+
storage: {{ default "1Gi" $repo.volume.backupsSize | quote }}
64+
{{- else if $repo.s3 }}
65+
s3:
66+
bucket: {{ $repo.s3.bucket | quote }}
67+
endpoint: {{ $repo.s3.endpoint | quote }}
68+
region: {{ $repo.s3.region | quote }}
69+
{{- end }}
70+
{{- end }}
4371
{{- else if .Values.s3 }}
4472
configuration:
4573
- secret:

helm/postgres/values.yaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
# Backups / pgBackRest Settings #
166166
#################################
167167

168-
# backupsSize sets the storage size of the backups to a PVC. This can be
169-
# overridden by "pgBackRestConfig", if set. Defaults to the value velow.
168+
# backupsSize sets the storage size of the backups to a volume in Kubernetes.
169+
# can be overridden by "pgBackRestConfig", if set. Defaults to the value velow.
170170
# backupsSize: 1Gi
171171

172172
# s3 allows for AWS S3 or an S3 compatible storage system to be used for
@@ -189,6 +189,27 @@
189189
# # built-in encrpytion system.
190190
# encryptionPassphrase: ""
191191

192+
# multiBackupRepos allows for backing up to multiple repositories. This is
193+
# effectively uses the "quickstarts" for each of the backup types (volume, s3,
194+
# gcs, azure). You can have any permutation of these types. You can set up to 4.
195+
# can be overwritten by "pgBackRestConfig".
196+
#
197+
# You can't set "multiBackupRepos" and any of the individual quickstarts at the
198+
# same time. "multiBackupRepos" will take precedence.
199+
#
200+
# Below is an example that enables one of each backup type. Note all of the
201+
# available quickstart options are presented below; please see the backup types
202+
# if you want to see how each option works.
203+
# multiBackupRepos:
204+
# - volume:
205+
# backupsSize: 1Gi
206+
# - s3:
207+
# bucket: ""
208+
# endpoint: ""
209+
# region: ""
210+
# key: ""
211+
# keySecret: ""
212+
192213
# pgBackRestConfig allows for the configuration of every pgBackRest option
193214
# except for "image", which is set by "pgBackRest".
194215
# pgBackRestConfig: {}

0 commit comments

Comments
 (0)