6edf09b2 by Adam Heath

Backups are now working(local, and optionally pushing to s3 via rclone).

1 parent c5e87c18
1 # Patterns to ignore when building packages.
2 # This supports shell glob matching, relative path matching, and
3 # negation (prefixed with !). Only one pattern per line.
4 .DS_Store
5 # Common VCS dirs
6 .git/
7 .gitignore
8 .bzr/
9 .bzrignore
10 .hg/
11 .hgignore
12 .svn/
13 # Common backup files
14 *.swp
15 *.bak
16 *.tmp
17 *.orig
18 *~
19 # Various IDEs
20 .project
21 .idea/
22 *.tmproj
23 .vscode/
1 apiVersion: v2
2 name: postgresql-backup-s3
3 description: A Helm chart for Kubernetes
4
5 # A chart can be either an 'application' or a 'library' chart.
6 #
7 # Application charts are a collection of templates that can be packaged into versioned archives
8 # to be deployed.
9 #
10 # Library charts provide useful utilities or functions for the chart developer. They're included as
11 # a dependency of application charts to inject those utilities and functions into the rendering
12 # pipeline. Library charts do not define any templates and therefore cannot be deployed.
13 type: application
14
15 # This is the chart version. This version number should be incremented each time you make changes
16 # to the chart and its templates, including the app version.
17 # Versions are expected to follow Semantic Versioning (https://semver.org/)
18 version: 0.0.0
19
20 # This is the version number of the application being deployed. This version number should be
21 # incremented each time you make changes to the application. Versions are not expected to
22 # follow Semantic Versioning. They should reflect the version the application is using.
23 # It is recommended to use it with quotes.
24 appVersion: "0.0.0"
1 {{/*
2 Expand the name of the chart.
3 */}}
4 {{- define "postgresql-backup-s3.name" -}}
5 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6 {{- end }}
7
8 {{/*
9 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).
11 If release name contains chart name it will be used as a full name.
12 */}}
13 {{- define "postgresql-backup-s3.fullname" -}}
14 {{- if .Values.fullnameOverride }}
15 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16 {{- else }}
17 {{- $name := default .Chart.Name .Values.nameOverride }}
18 {{- if contains $name .Release.Name }}
19 {{- .Release.Name | trunc 63 | trimSuffix "-" }}
20 {{- else }}
21 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22 {{- end }}
23 {{- end }}
24 {{- end }}
25
26 {{/*
27 Create chart name and version as used by the chart label.
28 */}}
29 {{- define "postgresql-backup-s3.chart" -}}
30 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31 {{- end }}
32
33 {{/*
34 Common labels
35 */}}
36 {{- define "postgresql-backup-s3.labels" -}}
37 helm.sh/chart: {{ include "postgresql-backup-s3.chart" . }}
38 {{ include "postgresql-backup-s3.selectorLabels" . }}
39 {{- if .Chart.AppVersion }}
40 app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41 {{- end }}
42 app.kubernetes.io/managed-by: {{ .Release.Service }}
43 {{- end }}
44
45 {{/*
46 Selector labels
47 */}}
48 {{- define "postgresql-backup-s3.selectorLabels" -}}
49 app.kubernetes.io/name: {{ include "postgresql-backup-s3.name" . }}
50 app.kubernetes.io/instance: {{ .Release.Name }}
51 {{- end }}
52
53 {{/*
54 Create the name of the service account to use
55 */}}
56 {{- define "postgresql-backup-s3.serviceAccountName" -}}
57 {{- if .Values.serviceAccount.create }}
58 {{- default (include "postgresql-backup-restore.fullname" .) .Values.serviceAccount.name }}
59 {{- else }}
60 {{- default "default" .Values.serviceAccount.name }}
61 {{- end }}
62 {{- end }}
1 ---
2 apiVersion: v1
3 kind: PersistentVolumeClaim
4 metadata:
5 name: {{ include "postgresql-backup-s3.fullname" . }}
6 spec:
7 storageClassName: {{ .Values.backup.pvc.storageClassName }}
8 accessModes:
9 - ReadWriteOnce
10 resources:
11 requests:
12 storage: {{ .Values.backup.pvc.size }}
13 ---
14 apiVersion: v1
15 kind: ConfigMap
16 metadata:
17 name: {{ include "postgresql-backup-s3.fullname" . }}-local
18 data:
19 POSTGRES_DB: |-
20 {{- range $database := .Values.postgresql.databases }}
21 {{ $database }}
22 {{- end }}{{ .Values.local.postgresDb | quote }}
23 BACKUP_KEEP_DAYS: {{ .Values.local.backupKeepDays | quote }}
24 ---
25 apiVersion: v1
26 kind: Secret
27 metadata:
28 name: {{ include "postgresql-backup-s3.fullname" . }}-auth
29 stringData:
30 POSTGRES_USER: {{ .Values.postgresql.auth.postgresqlUser }}
31 POSTGRES_PASSWORD: {{ .Values.postgresql.auth.postgresqlPassword }}
32 ---
33 {{- if .Values.rclone.enabled }}
34 apiVersion: v1
35 kind: ConfigMap
36 metadata:
37 name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
38 data:
39 {{ .Values.rclone.config | toYaml | nindent 2 }}
40 {{- end }}
41 ---
42 {{- if .Values.rclone.enabled }}
43 apiVersion: v1
44 kind: Secret
45 metadata:
46 name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
47 stringData:
48 {{ .Values.rclone.secret | toYaml | nindent 2 }}
49 {{- end }}
50 ---
51 apiVersion: batch/v1beta1
52 kind: CronJob
53 metadata:
54 name: {{ include "postgresql-backup-s3.fullname" . }}
55 labels:
56 {{- include "postgresql-backup-s3.labels" . | nindent 4 }}
57 spec:
58 schedule: {{ .Values.backup.schedule }}
59 startingDeadlineSeconds: 3600
60 concurrencyPolicy: Forbid
61 successfulJobsHistoryLimit: 10
62 failedJobsHistoryLimit: 10
63 jobTemplate:
64 spec:
65 template:
66 spec:
67 restartPolicy: OnFailure
68 imagePullSecrets:
69 {{- toYaml .Values.imagePullSecrets | nindent 12 }}
70 volumes:
71 - name: dbdumps
72 persistentVolumeClaim:
73 claimName: {{ include "postgresql-backup-s3.fullname" . }}
74 - name: postgresql-auth
75 secret:
76 secretName: {{ include "postgresql-backup-s3.fullname" . }}-auth
77 - name: local-config
78 configMap:
79 name: {{ include "postgresql-backup-s3.fullname" . }}-local
80 {{- if .Values.rclone.enabled }}
81 - name: rclone-auth
82 secret:
83 secretName: {{ include "postgresql-backup-s3.fullname" . }}-rclone
84 - name: rclone-config
85 configMap:
86 name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
87 {{- end }}
88 initContainers:
89 - name: dump-databases
90 image: "{{ .Values.local.image.repository }}:{{ .Values.local.image.tag }}"
91 imagePullPolicy: {{ .Values.local.image.pullPolicy }}
92 volumeMounts:
93 - name: dbdumps
94 mountPath: /backups
95 - name: local-config
96 mountPath: /config
97 - name: postgresql-auth
98 mountPath: /secret
99 env:
100 - name: BACKUP_KEEP_DAYS
101 valueFrom:
102 configMapKeyRef:
103 name: {{ include "postgresql-backup-s3.fullname" . }}-local
104 key: BACKUP_KEEP_DAYS
105 - name: BACKUP_DIR
106 value: /backups
107 - name: POSTGRES_HOST
108 value: {{ .Values.postgresql.host }}
109 - name: POSTGRES_DB_FILE
110 value: /config/POSTGRES_DB
111 - name: POSTGRES_USER_FILE
112 value: /secret/POSTGRES_USER
113 - name: POSTGRES_PASSWORD_FILE
114 value: /secret/POSTGRES_PASSWORD
115 command: ["/backup.sh"]
116 {{- if .Values.rclone.enabled }}
117 - name: rclone
118 image: "{{ .Values.rclone.image.repository }}:{{ .Values.rclone.image.tag }}"
119 imagePullPolicy: {{ .Values.rclone.image.pullPolicy }}
120 volumeMounts:
121 - name: dbdumps
122 mountPath: /backups
123 - name: rclone-config
124 mountPath: /config
125 - name: rclone-auth
126 mountPath: /secret
127 envFrom:
128 - configMapRef:
129 name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
130 - secretRef:
131 name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
132 {{- if .Values.rclone.crypt.enabled }}
133 env:
134 - name: RCLONE_CRYPT_REMOTE
135 value: ":s3:$(S3_BUCKET)/$(S3_PREFIX)/"
136 {{- end }}
137 {{- if .Values.rclone.crypt.enabled }}
138 args: ["copy", "/backups/", ":crypt:"]
139 {{- else }}
140 args: ["copy", "/backups/", ":s3:$(S3_BUCKET)/$(S3_PREFIX)/"]
141 {{- end }}
142 {{- end }}
143 containers:
144 - name: show-dumps
145 image: bash
146 volumeMounts:
147 - name: dbdumps
148 mountPath: /backups
149 command: ["ls"]
150 args: ["-alR", "/backups"]
151
1 # Default values for postgresql-backup-restore.
2 # This is a YAML-formatted file.
3 # Declare variables to be passed into your templates.
4
5 s3:
6 bucket: ""
7 prefix: ""
8 region: "us-east-1"
9 provider: "aws"
10 accessKey: ""
11 secretKey: ""
12
13 postgresql:
14 host: postgresql.postgresql.svc.cluster.local
15 auth:
16 postgresqlUser: postgres
17 postgresqlPassword: foobar
18 databases:
19 - postgres
20 - moqui
21 - keycloak
22
23 local:
24 image:
25 repository: prodrigestivill/postgres-backup-local
26 tag: "latest"
27 pullPolicy: IfNotPresent
28 backupKeepDays: 288
29
30 backup:
31 schedule: "13 3 * * *"
32 pvc:
33 storageClassName: ""
34 size: 10Gi
35
36 rclone:
37 enabled: false
38 image:
39 repository: rclone/rclone
40 tag: latest
41 pullPolicy: IfNotPresent
42 crypt:
43 enabled: false
44 password: ""
45 password2: ""
46