Implement restore, rename chart to be postgresql-rclone.
Showing
4 changed files
with
143 additions
and
37 deletions
1 | apiVersion: v2 | 1 | apiVersion: v2 |
2 | name: postgresql-backup-s3 | 2 | name: postgresql-rclone |
3 | description: A Helm chart for Kubernetes | 3 | description: A Helm chart for Kubernetes |
4 | 4 | ||
5 | # A chart can be either an 'application' or a 'library' chart. | 5 | # A chart can be either an 'application' or a 'library' chart. | ... | ... |
1 | {{/* | 1 | {{/* |
2 | Expand the name of the chart. | 2 | Expand the name of the chart. |
3 | */}} | 3 | */}} |
4 | {{- define "postgresql-backup-s3.name" -}} | 4 | {{- define "postgresql-rclone.name" -}} |
5 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | 5 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
6 | {{- end }} | 6 | {{- end }} |
7 | 7 | ||
... | @@ -10,7 +10,7 @@ Create a default fully qualified app name. | ... | @@ -10,7 +10,7 @@ Create a default fully qualified app name. |
10 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | 10 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
11 | If release name contains chart name it will be used as a full name. | 11 | If release name contains chart name it will be used as a full name. |
12 | */}} | 12 | */}} |
13 | {{- define "postgresql-backup-s3.fullname" -}} | 13 | {{- define "postgresql-rclone.fullname" -}} |
14 | {{- if .Values.fullnameOverride }} | 14 | {{- if .Values.fullnameOverride }} |
15 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | 15 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
16 | {{- else }} | 16 | {{- else }} |
... | @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name. | ... | @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name. |
26 | {{/* | 26 | {{/* |
27 | Create chart name and version as used by the chart label. | 27 | Create chart name and version as used by the chart label. |
28 | */}} | 28 | */}} |
29 | {{- define "postgresql-backup-s3.chart" -}} | 29 | {{- define "postgresql-rclone.chart" -}} |
30 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | 30 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
31 | {{- end }} | 31 | {{- end }} |
32 | 32 | ||
33 | {{/* | 33 | {{/* |
34 | Common labels | 34 | Common labels |
35 | */}} | 35 | */}} |
36 | {{- define "postgresql-backup-s3.labels" -}} | 36 | {{- define "postgresql-rclone.labels" -}} |
37 | helm.sh/chart: {{ include "postgresql-backup-s3.chart" . }} | 37 | helm.sh/chart: {{ include "postgresql-rclone.chart" . }} |
38 | {{ include "postgresql-backup-s3.selectorLabels" . }} | 38 | {{ include "postgresql-rclone.selectorLabels" . }} |
39 | {{- if .Chart.AppVersion }} | 39 | {{- if .Chart.AppVersion }} |
40 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | 40 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
41 | {{- end }} | 41 | {{- end }} |
... | @@ -45,15 +45,15 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} | ... | @@ -45,15 +45,15 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} |
45 | {{/* | 45 | {{/* |
46 | Selector labels | 46 | Selector labels |
47 | */}} | 47 | */}} |
48 | {{- define "postgresql-backup-s3.selectorLabels" -}} | 48 | {{- define "postgresql-rclone.selectorLabels" -}} |
49 | app.kubernetes.io/name: {{ include "postgresql-backup-s3.name" . }} | 49 | app.kubernetes.io/name: {{ include "postgresql-rclone.name" . }} |
50 | app.kubernetes.io/instance: {{ .Release.Name }} | 50 | app.kubernetes.io/instance: {{ .Release.Name }} |
51 | {{- end }} | 51 | {{- end }} |
52 | 52 | ||
53 | {{/* | 53 | {{/* |
54 | Create the name of the service account to use | 54 | Create the name of the service account to use |
55 | */}} | 55 | */}} |
56 | {{- define "postgresql-backup-s3.serviceAccountName" -}} | 56 | {{- define "postgresql-rclone.serviceAccountName" -}} |
57 | {{- if .Values.serviceAccount.create }} | 57 | {{- if .Values.serviceAccount.create }} |
58 | {{- default (include "postgresql-backup-restore.fullname" .) .Values.serviceAccount.name }} | 58 | {{- default (include "postgresql-backup-restore.fullname" .) .Values.serviceAccount.name }} |
59 | {{- else }} | 59 | {{- else }} | ... | ... |
... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
2 | apiVersion: v1 | 2 | apiVersion: v1 |
3 | kind: PersistentVolumeClaim | 3 | kind: PersistentVolumeClaim |
4 | metadata: | 4 | metadata: |
5 | name: {{ include "postgresql-backup-s3.fullname" . }} | 5 | name: {{ include "postgresql-rclone.fullname" . }}-backups |
6 | spec: | 6 | spec: |
7 | storageClassName: {{ .Values.backup.pvc.storageClassName }} | 7 | storageClassName: {{ .Values.backup.pvc.storageClassName }} |
8 | accessModes: | 8 | accessModes: |
... | @@ -14,7 +14,7 @@ spec: | ... | @@ -14,7 +14,7 @@ spec: |
14 | apiVersion: v1 | 14 | apiVersion: v1 |
15 | kind: ConfigMap | 15 | kind: ConfigMap |
16 | metadata: | 16 | metadata: |
17 | name: {{ include "postgresql-backup-s3.fullname" . }}-local | 17 | name: {{ include "postgresql-rclone.fullname" . }}-backup-local |
18 | data: | 18 | data: |
19 | POSTGRES_DB: |- | 19 | POSTGRES_DB: |- |
20 | {{- range $database := .Values.postgresql.databases }} | 20 | {{- range $database := .Values.postgresql.databases }} |
... | @@ -25,7 +25,7 @@ data: | ... | @@ -25,7 +25,7 @@ data: |
25 | apiVersion: v1 | 25 | apiVersion: v1 |
26 | kind: Secret | 26 | kind: Secret |
27 | metadata: | 27 | metadata: |
28 | name: {{ include "postgresql-backup-s3.fullname" . }}-auth | 28 | name: {{ include "postgresql-rclone.fullname" . }}-auth |
29 | stringData: | 29 | stringData: |
30 | POSTGRES_USER: {{ .Values.postgresql.auth.postgresqlUser }} | 30 | POSTGRES_USER: {{ .Values.postgresql.auth.postgresqlUser }} |
31 | POSTGRES_PASSWORD: {{ .Values.postgresql.auth.postgresqlPassword }} | 31 | POSTGRES_PASSWORD: {{ .Values.postgresql.auth.postgresqlPassword }} |
... | @@ -34,7 +34,7 @@ stringData: | ... | @@ -34,7 +34,7 @@ stringData: |
34 | apiVersion: v1 | 34 | apiVersion: v1 |
35 | kind: ConfigMap | 35 | kind: ConfigMap |
36 | metadata: | 36 | metadata: |
37 | name: {{ include "postgresql-backup-s3.fullname" . }}-rclone | 37 | name: {{ include "postgresql-rclone.fullname" . }}-rclone |
38 | data: | 38 | data: |
39 | {{ .Values.rclone.config | toYaml | nindent 2 }} | 39 | {{ .Values.rclone.config | toYaml | nindent 2 }} |
40 | {{- end }} | 40 | {{- end }} |
... | @@ -43,17 +43,17 @@ data: | ... | @@ -43,17 +43,17 @@ data: |
43 | apiVersion: v1 | 43 | apiVersion: v1 |
44 | kind: Secret | 44 | kind: Secret |
45 | metadata: | 45 | metadata: |
46 | name: {{ include "postgresql-backup-s3.fullname" . }}-rclone | 46 | name: {{ include "postgresql-rclone.fullname" . }}-rclone |
47 | stringData: | 47 | stringData: |
48 | {{ .Values.rclone.secret | toYaml | nindent 2 }} | 48 | {{ .Values.rclone.secret | toYaml | nindent 2 }} |
49 | {{- end }} | 49 | {{- end }} |
50 | --- | 50 | --- |
51 | apiVersion: batch/v1beta1 | 51 | apiVersion: batch/v1 |
52 | kind: CronJob | 52 | kind: CronJob |
53 | metadata: | 53 | metadata: |
54 | name: {{ include "postgresql-backup-s3.fullname" . }} | 54 | name: {{ include "postgresql-rclone.fullname" . }}-backup |
55 | labels: | 55 | labels: |
56 | {{- include "postgresql-backup-s3.labels" . | nindent 4 }} | 56 | {{- include "postgresql-rclone.labels" . | nindent 4 }} |
57 | spec: | 57 | spec: |
58 | schedule: {{ .Values.backup.schedule }} | 58 | schedule: {{ .Values.backup.schedule }} |
59 | startingDeadlineSeconds: 3600 | 59 | startingDeadlineSeconds: 3600 |
... | @@ -68,29 +68,29 @@ spec: | ... | @@ -68,29 +68,29 @@ spec: |
68 | imagePullSecrets: | 68 | imagePullSecrets: |
69 | {{- toYaml .Values.imagePullSecrets | nindent 12 }} | 69 | {{- toYaml .Values.imagePullSecrets | nindent 12 }} |
70 | volumes: | 70 | volumes: |
71 | - name: dbdumps | 71 | - name: backups |
72 | persistentVolumeClaim: | 72 | persistentVolumeClaim: |
73 | claimName: {{ include "postgresql-backup-s3.fullname" . }} | 73 | claimName: {{ include "postgresql-rclone.fullname" . }}-backups |
74 | - name: postgresql-auth | 74 | - name: postgresql-auth |
75 | secret: | 75 | secret: |
76 | secretName: {{ include "postgresql-backup-s3.fullname" . }}-auth | 76 | secretName: {{ include "postgresql-rclone.fullname" . }}-auth |
77 | - name: local-config | 77 | - name: local-config |
78 | configMap: | 78 | configMap: |
79 | name: {{ include "postgresql-backup-s3.fullname" . }}-local | 79 | name: {{ include "postgresql-rclone.fullname" . }}-local |
80 | {{- if .Values.rclone.enabled }} | 80 | {{- if .Values.rclone.enabled }} |
81 | - name: rclone-auth | 81 | - name: rclone-auth |
82 | secret: | 82 | secret: |
83 | secretName: {{ include "postgresql-backup-s3.fullname" . }}-rclone | 83 | secretName: {{ include "postgresql-rclone.fullname" . }}-rclone |
84 | - name: rclone-config | 84 | - name: rclone-config |
85 | configMap: | 85 | configMap: |
86 | name: {{ include "postgresql-backup-s3.fullname" . }}-rclone | 86 | name: {{ include "postgresql-rclone.fullname" . }}-rclone |
87 | {{- end }} | 87 | {{- end }} |
88 | initContainers: | 88 | initContainers: |
89 | - name: dump-databases | 89 | - name: dump-databases |
90 | image: "{{ .Values.local.image.repository }}:{{ .Values.local.image.tag }}" | 90 | image: "{{ .Values.local.image.repository }}:{{ .Values.local.image.tag }}" |
91 | imagePullPolicy: {{ .Values.local.image.pullPolicy }} | 91 | imagePullPolicy: {{ .Values.local.image.pullPolicy }} |
92 | volumeMounts: | 92 | volumeMounts: |
93 | - name: dbdumps | 93 | - name: backups |
94 | mountPath: /backups | 94 | mountPath: /backups |
95 | - name: local-config | 95 | - name: local-config |
96 | mountPath: /config | 96 | mountPath: /config |
... | @@ -100,7 +100,7 @@ spec: | ... | @@ -100,7 +100,7 @@ spec: |
100 | - name: BACKUP_KEEP_DAYS | 100 | - name: BACKUP_KEEP_DAYS |
101 | valueFrom: | 101 | valueFrom: |
102 | configMapKeyRef: | 102 | configMapKeyRef: |
103 | name: {{ include "postgresql-backup-s3.fullname" . }}-local | 103 | name: {{ include "postgresql-rclone.fullname" . }}-local |
104 | key: BACKUP_KEEP_DAYS | 104 | key: BACKUP_KEEP_DAYS |
105 | - name: BACKUP_DIR | 105 | - name: BACKUP_DIR |
106 | value: /backups | 106 | value: /backups |
... | @@ -118,7 +118,7 @@ spec: | ... | @@ -118,7 +118,7 @@ spec: |
118 | image: "{{ .Values.rclone.image.repository }}:{{ .Values.rclone.image.tag }}" | 118 | image: "{{ .Values.rclone.image.repository }}:{{ .Values.rclone.image.tag }}" |
119 | imagePullPolicy: {{ .Values.rclone.image.pullPolicy }} | 119 | imagePullPolicy: {{ .Values.rclone.image.pullPolicy }} |
120 | volumeMounts: | 120 | volumeMounts: |
121 | - name: dbdumps | 121 | - name: backups |
122 | mountPath: /backups | 122 | mountPath: /backups |
123 | - name: rclone-config | 123 | - name: rclone-config |
124 | mountPath: /config | 124 | mountPath: /config |
... | @@ -126,9 +126,9 @@ spec: | ... | @@ -126,9 +126,9 @@ spec: |
126 | mountPath: /secret | 126 | mountPath: /secret |
127 | envFrom: | 127 | envFrom: |
128 | - configMapRef: | 128 | - configMapRef: |
129 | name: {{ include "postgresql-backup-s3.fullname" . }}-rclone | 129 | name: {{ include "postgresql-rclone.fullname" . }}-rclone |
130 | - secretRef: | 130 | - secretRef: |
131 | name: {{ include "postgresql-backup-s3.fullname" . }}-rclone | 131 | name: {{ include "postgresql-rclone.fullname" . }}-rclone |
132 | {{- if .Values.rclone.crypt.enabled }} | 132 | {{- if .Values.rclone.crypt.enabled }} |
133 | env: | 133 | env: |
134 | - name: RCLONE_CRYPT_REMOTE | 134 | - name: RCLONE_CRYPT_REMOTE |
... | @@ -144,8 +144,111 @@ spec: | ... | @@ -144,8 +144,111 @@ spec: |
144 | - name: show-dumps | 144 | - name: show-dumps |
145 | image: bash | 145 | image: bash |
146 | volumeMounts: | 146 | volumeMounts: |
147 | - name: dbdumps | 147 | - name: backups |
148 | mountPath: /backups | 148 | mountPath: /backups |
149 | command: ["ls"] | 149 | command: ["ls"] |
150 | args: ["-alR", "/backups"] | 150 | args: ["-alR", "/backups"] |
151 | --- | ||
152 | apiVersion: v1 | ||
153 | kind: PersistentVolumeClaim | ||
154 | metadata: | ||
155 | name: {{ include "postgresql-rclone.fullname" . }}-restores | ||
156 | spec: | ||
157 | storageClassName: {{ .Values.restore.pvc.storageClassName }} | ||
158 | accessModes: | ||
159 | - ReadWriteOnce | ||
160 | resources: | ||
161 | requests: | ||
162 | storage: {{ .Values.restore.pvc.size }} | ||
163 | --- | ||
164 | apiVersion: batch/v1 | ||
165 | kind: Job | ||
166 | metadata: | ||
167 | name: {{ include "postgresql-rclone.fullname" . }}-restore | ||
168 | labels: | ||
169 | {{- include "postgresql-rclone.labels" . | nindent 4 }} | ||
170 | spec: | ||
171 | template: | ||
172 | spec: | ||
173 | restartPolicy: OnFailure | ||
174 | imagePullSecrets: | ||
175 | {{- toYaml .Values.imagePullSecrets | nindent 12 }} | ||
176 | volumes: | ||
177 | - name: restores | ||
178 | persistentVolumeClaim: | ||
179 | claimName: {{ include "postgresql-rclone.fullname" . }}-restores | ||
180 | {{- if .Values.rclone.enabled }} | ||
181 | - name: rclone-auth | ||
182 | secret: | ||
183 | secretName: {{ include "postgresql-rclone.fullname" . }}-rclone | ||
184 | - name: rclone-config | ||
185 | configMap: | ||
186 | name: {{ include "postgresql-rclone.fullname" . }}-rclone | ||
187 | {{- end }} | ||
188 | initContainers: | ||
189 | {{- if .Values.rclone.enabled }} | ||
190 | - name: rclone | ||
191 | image: "{{ .Values.rclone.image.repository }}:{{ .Values.rclone.image.tag }}" | ||
192 | imagePullPolicy: {{ .Values.rclone.image.pullPolicy }} | ||
193 | volumeMounts: | ||
194 | - name: restores | ||
195 | mountPath: /restores | ||
196 | - name: rclone-config | ||
197 | mountPath: /config | ||
198 | - name: rclone-auth | ||
199 | mountPath: /secret | ||
200 | envFrom: | ||
201 | - configMapRef: | ||
202 | name: {{ include "postgresql-rclone.fullname" . }}-rclone | ||
203 | - secretRef: | ||
204 | name: {{ include "postgresql-rclone.fullname" . }}-rclone | ||
205 | {{- if .Values.rclone.crypt.enabled }} | ||
206 | env: | ||
207 | - name: RCLONE_CRYPT_REMOTE | ||
208 | value: ":s3:$(S3_BUCKET)/$(S3_PREFIX)/last/" | ||
209 | {{- end }} | ||
210 | {{- if .Values.rclone.crypt.enabled }} | ||
211 | args: ["copy", ":crypt:", "/restores/"] | ||
212 | {{- else }} | ||
213 | args: ["-v", "copy", ":s3:$(S3_BUCKET)/$(S3_PREFIX)/last/", "/restores/.work/"] | ||
214 | {{- end }} | ||
215 | {{- end }} | ||
216 | - name: link-latest | ||
217 | image: "{{ .Values.bash.image.repository }}:{{ .Values.bash.image.tag }}" | ||
218 | imagePullPolicy: {{ .Values.bash.image.pullPolicy }} | ||
219 | volumeMounts: | ||
220 | - name: restores | ||
221 | mountPath: /restores | ||
222 | command: | ||
223 | - bash | ||
224 | - -cx | ||
225 | - |- | ||
226 | find /restores/.work -maxdepth 1 -mindepth 1 -name '*.sql.gz' | \ | ||
227 | sort | \ | ||
228 | awk '{split($1, a, /-([^-]*)-([^-]*)$/)} !uniq[a[1] a[2] a[3]]++' | \ | ||
229 | while read file; do \ | ||
230 | ln -f "$file" "/restores/" | ||
231 | done | ||
232 | - name: show-restores | ||
233 | image: "{{ .Values.bash.image.repository }}:{{ .Values.bash.image.tag }}" | ||
234 | imagePullPolicy: {{ .Values.bash.image.pullPolicy }} | ||
235 | volumeMounts: | ||
236 | - name: restores | ||
237 | mountPath: /restores | ||
238 | command: ["ls"] | ||
239 | args: ["-alR", "/restores"] | ||
240 | |||
241 | containers: | ||
242 | - name: ready | ||
243 | image: "{{ .Values.bash.image.repository }}:{{ .Values.bash.image.tag }}" | ||
244 | imagePullPolicy: {{ .Values.bash.image.pullPolicy }} | ||
245 | volumeMounts: | ||
246 | - name: restores | ||
247 | mountPath: /restores | ||
248 | command: | ||
249 | - bash | ||
250 | - -cx | ||
251 | - |- | ||
252 | touch /restores/.restored | ||
253 | |||
151 | 254 | ... | ... |
... | @@ -2,13 +2,11 @@ | ... | @@ -2,13 +2,11 @@ |
2 | # This is a YAML-formatted file. | 2 | # This is a YAML-formatted file. |
3 | # Declare variables to be passed into your templates. | 3 | # Declare variables to be passed into your templates. |
4 | 4 | ||
5 | s3: | 5 | bash: |
6 | bucket: "" | 6 | image: |
7 | prefix: "" | 7 | repository: bash |
8 | region: "us-east-1" | 8 | tag: latest |
9 | provider: "aws" | 9 | pullPolicy: IfNotPresent |
10 | accessKey: "" | ||
11 | secretKey: "" | ||
12 | 10 | ||
13 | postgresql: | 11 | postgresql: |
14 | host: postgresql.postgresql.svc.cluster.local | 12 | host: postgresql.postgresql.svc.cluster.local |
... | @@ -33,6 +31,11 @@ backup: | ... | @@ -33,6 +31,11 @@ backup: |
33 | storageClassName: "" | 31 | storageClassName: "" |
34 | size: 10Gi | 32 | size: 10Gi |
35 | 33 | ||
34 | restore: | ||
35 | pvc: | ||
36 | storageClassName: "" | ||
37 | size: 10Gi | ||
38 | |||
36 | rclone: | 39 | rclone: |
37 | enabled: false | 40 | enabled: false |
38 | image: | 41 | image: | ... | ... |
-
Please register or sign in to post a comment