6edf09b2 by Adam Heath

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

1 parent c5e87c18
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
apiVersion: v2
name: postgresql-backup-s3
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.0.0"
{{/*
Expand the name of the chart.
*/}}
{{- define "postgresql-backup-s3.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "postgresql-backup-s3.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "postgresql-backup-s3.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "postgresql-backup-s3.labels" -}}
helm.sh/chart: {{ include "postgresql-backup-s3.chart" . }}
{{ include "postgresql-backup-s3.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "postgresql-backup-s3.selectorLabels" -}}
app.kubernetes.io/name: {{ include "postgresql-backup-s3.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "postgresql-backup-s3.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "postgresql-backup-restore.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "postgresql-backup-s3.fullname" . }}
spec:
storageClassName: {{ .Values.backup.pvc.storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.backup.pvc.size }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "postgresql-backup-s3.fullname" . }}-local
data:
POSTGRES_DB: |-
{{- range $database := .Values.postgresql.databases }}
{{ $database }}
{{- end }}{{ .Values.local.postgresDb | quote }}
BACKUP_KEEP_DAYS: {{ .Values.local.backupKeepDays | quote }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "postgresql-backup-s3.fullname" . }}-auth
stringData:
POSTGRES_USER: {{ .Values.postgresql.auth.postgresqlUser }}
POSTGRES_PASSWORD: {{ .Values.postgresql.auth.postgresqlPassword }}
---
{{- if .Values.rclone.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
data:
{{ .Values.rclone.config | toYaml | nindent 2 }}
{{- end }}
---
{{- if .Values.rclone.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
stringData:
{{ .Values.rclone.secret | toYaml | nindent 2 }}
{{- end }}
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ include "postgresql-backup-s3.fullname" . }}
labels:
{{- include "postgresql-backup-s3.labels" . | nindent 4 }}
spec:
schedule: {{ .Values.backup.schedule }}
startingDeadlineSeconds: 3600
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 10
failedJobsHistoryLimit: 10
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
imagePullSecrets:
{{- toYaml .Values.imagePullSecrets | nindent 12 }}
volumes:
- name: dbdumps
persistentVolumeClaim:
claimName: {{ include "postgresql-backup-s3.fullname" . }}
- name: postgresql-auth
secret:
secretName: {{ include "postgresql-backup-s3.fullname" . }}-auth
- name: local-config
configMap:
name: {{ include "postgresql-backup-s3.fullname" . }}-local
{{- if .Values.rclone.enabled }}
- name: rclone-auth
secret:
secretName: {{ include "postgresql-backup-s3.fullname" . }}-rclone
- name: rclone-config
configMap:
name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
{{- end }}
initContainers:
- name: dump-databases
image: "{{ .Values.local.image.repository }}:{{ .Values.local.image.tag }}"
imagePullPolicy: {{ .Values.local.image.pullPolicy }}
volumeMounts:
- name: dbdumps
mountPath: /backups
- name: local-config
mountPath: /config
- name: postgresql-auth
mountPath: /secret
env:
- name: BACKUP_KEEP_DAYS
valueFrom:
configMapKeyRef:
name: {{ include "postgresql-backup-s3.fullname" . }}-local
key: BACKUP_KEEP_DAYS
- name: BACKUP_DIR
value: /backups
- name: POSTGRES_HOST
value: {{ .Values.postgresql.host }}
- name: POSTGRES_DB_FILE
value: /config/POSTGRES_DB
- name: POSTGRES_USER_FILE
value: /secret/POSTGRES_USER
- name: POSTGRES_PASSWORD_FILE
value: /secret/POSTGRES_PASSWORD
command: ["/backup.sh"]
{{- if .Values.rclone.enabled }}
- name: rclone
image: "{{ .Values.rclone.image.repository }}:{{ .Values.rclone.image.tag }}"
imagePullPolicy: {{ .Values.rclone.image.pullPolicy }}
volumeMounts:
- name: dbdumps
mountPath: /backups
- name: rclone-config
mountPath: /config
- name: rclone-auth
mountPath: /secret
envFrom:
- configMapRef:
name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
- secretRef:
name: {{ include "postgresql-backup-s3.fullname" . }}-rclone
{{- if .Values.rclone.crypt.enabled }}
env:
- name: RCLONE_CRYPT_REMOTE
value: ":s3:$(S3_BUCKET)/$(S3_PREFIX)/"
{{- end }}
{{- if .Values.rclone.crypt.enabled }}
args: ["copy", "/backups/", ":crypt:"]
{{- else }}
args: ["copy", "/backups/", ":s3:$(S3_BUCKET)/$(S3_PREFIX)/"]
{{- end }}
{{- end }}
containers:
- name: show-dumps
image: bash
volumeMounts:
- name: dbdumps
mountPath: /backups
command: ["ls"]
args: ["-alR", "/backups"]
# Default values for postgresql-backup-restore.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
s3:
bucket: ""
prefix: ""
region: "us-east-1"
provider: "aws"
accessKey: ""
secretKey: ""
postgresql:
host: postgresql.postgresql.svc.cluster.local
auth:
postgresqlUser: postgres
postgresqlPassword: foobar
databases:
- postgres
- moqui
- keycloak
local:
image:
repository: prodrigestivill/postgres-backup-local
tag: "latest"
pullPolicy: IfNotPresent
backupKeepDays: 288
backup:
schedule: "13 3 * * *"
pvc:
storageClassName: ""
size: 10Gi
rclone:
enabled: false
image:
repository: rclone/rclone
tag: latest
pullPolicy: IfNotPresent
crypt:
enabled: false
password: ""
password2: ""