Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes and modifications #708

Merged
merged 22 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions charts/barman/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tgz
.vscode
.idea
2 changes: 1 addition & 1 deletion charts/barman/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: barman
type: application
description: Chart for Barman PostgreSQL Backup and Recovery Manager
version: 0.8.1
version: 0.9.0
appVersion: "v2.19"
keywords:
- barman
Expand Down
8 changes: 6 additions & 2 deletions charts/barman/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions charts/barman/examples/barman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ deployment:
# deployment.strategy needs to be set to Recreate if the underlying PVC does
# not support multi-attach.
type: Recreate
additionalENVs:
TZ: "Asia/Tehran"
resources:
requests:
cpu: 100m
Expand Down Expand Up @@ -75,10 +77,13 @@ barman:
lastBackupMaximumAge: "1 day"
backupSchedule: "0 4 * * *"
databaseSlotName: barman
postBackupRetryScript: tar -zcvf data.tar.gz -C /var/lib/barman/pg/base/$BARMAN_BACKUP_ID/data . --remove-files
preRecoveryRetryScript: mkdir /var/lib/barman/pg/base/$BARMAN_BACKUP_ID/data; tar -xvzf data.tar.gz -C /var/lib/barman/pg/base/$BARMAN_BACKUP_ID/data; rm data.tar.gz
# server specific backup configs, add an entry for each db you backup
backups:
- backupMethod: postgres
backupSchedule: "0 4 * * *"
scopeName: "pg"
databaseSlotName: barman
lastBackupMaximumAge: "1 day"
# namespace the db is in
Expand Down
4 changes: 2 additions & 2 deletions charts/barman/templates/configmap-barman-backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
{{- include "barman.labels" . | nindent 4 }}
data:
{{- range .Values.barman.backups }}
{{ .postgresql.host }}.conf: |
[{{ .postgresql.host }}]
{{ .scopeName }}.conf: |
[{{ .scopeName }}]
tongpu marked this conversation as resolved.
Show resolved Hide resolved
active = true
description = "PostgreSQL Database (Streaming-Only)"
conninfo = host={{ .postgresql.host }} user={{ .postgresql.superUser }} dbname={{ .postgresql.superUserDatabase }}
Expand Down
14 changes: 3 additions & 11 deletions charts/barman/templates/configmap-barman-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ metadata:
data:
barman: |
{{- range .Values.barman.backups }}
{{- if hasKey . "createDatabaseSlot" }}
{{- if .createDatabaseSlot }}
* * * * * barman /usr/local/bin/barman receive-wal --create-slot {{ .postgresql.host }}; /usr/local/bin/barman cron
{{- end }}
{{- else }}
{{- if $.Values.barman.createDatabaseSlot }}
* * * * * barman /usr/local/bin/barman receive-wal --create-slot {{ .postgresql.host }}; /usr/local/bin/barman cron
{{- end }}
{{- end }}
* * * * * barman /usr/local/bin/barman cron
{{- if hasKey . "backupSchedule" }}
{{ .backupSchedule }} barman /usr/local/bin/barman backup {{ .postgresql.host }}
{{ .backupSchedule }} barman /usr/local/bin/barman backup {{ .scopeName }}
{{- else }}
{{ $.Values.barman.backupSchedule }} barman /usr/local/bin/barman backup {{ .postgresql.host }}
{{ $.Values.barman.backupSchedule }} barman /usr/local/bin/barman backup {{ .scopeName }}
{{- end }}
{{- end }}
# required by cron
8 changes: 8 additions & 0 deletions charts/barman/templates/configmap-barman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ data:

barman_user = {{ .Values.barman.barmanUser }}

{{- if hasKey .Values.barman "postBackupRetryScript" }}
post_backup_retry_script = {{ .Values.barman.postBackupRetryScript }}
{{- end }}

{{- if hasKey .Values.barman "preRecoveryRetryScript" }}
pre_recovery_retry_script = {{ .Values.barman.preRecoveryRetryScript }}
{{- end }}

; barman_lock_directory = %(barman_home)s
compression = {{ .Values.barman.compression }}
configuration_files_directory = /etc/barman/barman.d
Expand Down
45 changes: 45 additions & 0 deletions charts/barman/templates/configmap-entrypoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "barman.fullname" . }}-entrypoint
labels:
{{- include "barman.labels" . | nindent 4 }}
data:
entrypoint.sh: |
#!/bin/bash

echo "Setting ownership/permissions on ${BARMAN_DATA_DIR} and ${BARMAN_LOG_DIR}"

install -d -m 0700 -o barman -g barman ${BARMAN_DATA_DIR}
install -d -m 0755 -o barman -g barman ${BARMAN_LOG_DIR}

chown -R barman:barman /var/lib/barman/recover

echo "Checking/Creating replication slot"
{{- range .Values.barman.backups }}
{{- if hasKey . "createDatabaseSlot" }}
{{- if .createDatabaseSlot }}
barman replication-status {{ .scopeName }} --minimal --target=wal-streamer | grep barman || barman receive-wal --create-slot {{ .scopeName }}
barman replication-status {{ .scopeName }} --minimal --target=wal-streamer | grep barman || barman receive-wal --reset {{ .scopeName }}
{{- end }}
{{- else }}
{{- if $.Values.barman.createDatabaseSlot }}
barman replication-status {{ .scopeName }} --minimal --target=wal-streamer | grep barman || barman receive-wal --create-slot {{ .scopeName }}
barman replication-status {{ .scopeName }} --minimal --target=wal-streamer | grep barman || barman receive-wal --reset {{ .scopeName }}
{{- end }}
{{- end }}
{{- end }}
if [[ -f /home/barman/.ssh/id_rsa ]]; then
echo "Setting up Barman private key"
chmod 700 ~barman/.ssh
chown barman:barman -R ~barman/.ssh
chmod 600 ~barman/.ssh/id_rsa
fi

echo "Initializing done"

# run barman exporter every hour
exec /usr/local/bin/barman-exporter -l ${BARMAN_EXPORTER_LISTEN_ADDRESS}:${BARMAN_EXPORTER_LISTEN_PORT} -c ${BARMAN_EXPORTER_CACHE_TIME} &
echo "Started Barman exporter on ${BARMAN_EXPORTER_LISTEN_ADDRESS}:${BARMAN_EXPORTER_LISTEN_PORT}"

exec "$@"
3 changes: 3 additions & 0 deletions charts/barman/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ metadata:
{{- include "barman.labels" . | nindent 4 }}
data:
BARMAN_BACKUP_SCHEDULE: {{ .Values.barman.backupSchedule | quote }}
{{- range $i, $val := .Values.deployment.additionalENVs }}
{{ $i }}: {{ $val }}
{{- end }}
7 changes: 7 additions & 0 deletions charts/barman/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ spec:
- mountPath: /etc/cron.d/barman
name: barman-cron-config
subPath: barman
- mountPath: /entrypoint.sh
name: barman-entrypoint
subPath: entrypoint.sh
{{- with .Values.deployment.additionalVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
Expand Down Expand Up @@ -106,6 +109,10 @@ spec:
- name: barman-cron-config
configMap:
name: {{ include "barman.fullname" . }}-cron-config
- name: barman-entrypoint
configMap:
name: {{ include "barman.fullname" . }}-entrypoint
defaultMode: 0775
{{- with .Values.deployment.additionalVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
8 changes: 8 additions & 0 deletions charts/barman/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ deployment:
extraContainers: {}
# -- Specify imagePullSecrets for the deployment
imagePullSecrets: []
# -- Specify additional ENVs for the Deployment
additionalENVs: {}

service:
# -- Specify if a Service should be created
Expand Down Expand Up @@ -105,10 +107,16 @@ barman:
databaseSlotName: barman
# -- Create Database slot
createDatabaseSlot: true
# -- Barman post_backup_retry_script
postBackupRetryScript: ""
# -- Barman pre_recovery_retry_script
preRecoveryRetryScript: ""

backups:
# -- Barman retention policy
- retentionPolicy: "RECOVERY WINDOW of 1 MONTH"
# -- Postgresql server scope-name
scopeName: "pg"
# -- Barman backup method
backupMethod: postgres
# -- Database slot name to be created/used
Expand Down