diff --git a/charts/barman/.helmignore b/charts/barman/.helmignore new file mode 100644 index 000000000..ddc4aa0aa --- /dev/null +++ b/charts/barman/.helmignore @@ -0,0 +1,3 @@ +*.tgz +.vscode +.idea diff --git a/charts/barman/Chart.yaml b/charts/barman/Chart.yaml index 69969584b..afb4a848e 100644 --- a/charts/barman/Chart.yaml +++ b/charts/barman/Chart.yaml @@ -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 diff --git a/charts/barman/README.md b/charts/barman/README.md index 0e574e66a..a00d07315 100644 --- a/charts/barman/README.md +++ b/charts/barman/README.md @@ -1,6 +1,6 @@ # barman -![Version: 0.8.1](https://img.shields.io/badge/Version-0.8.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v2.19](https://img.shields.io/badge/AppVersion-v2.19-informational?style=flat-square) +![Version: 0.9.0](https://img.shields.io/badge/Version-0.9.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v2.19](https://img.shields.io/badge/AppVersion-v2.19-informational?style=flat-square) Chart for Barman PostgreSQL Backup and Recovery Manager @@ -23,7 +23,7 @@ This chart is maintained by [Adfinis](https://adfinis.com/?pk_campaign=github&pk | barman.backupMethod | string | `"postgres"` | Barman backup method | | barman.backupOptions | string | `"concurrent_backup"` | Barman backup options | | barman.backupSchedule | string | `"0 4 * * *"` | Barman backup schedule | -| barman.backups[0] | object | `{"additionalConfiguration":"","backupMethod":"postgres","createDatabaseSlot":true,"databaseSlotName":"barman","lastBackupMaximumAge":"1 day","namespace":"postgresql","postgresql":{"host":"postgresql","port":5432,"replicationPassword":"barman","replicationUser":"barman","superUser":"postgres","superUserDatabase":"postgres","superUserPassword":"postgres"},"retentionPolicy":"RECOVERY WINDOW of 1 MONTH","serviceaccount":"postgresql"}` | Barman retention policy | +| barman.backups[0] | object | `{"additionalConfiguration":"","backupMethod":"postgres","createDatabaseSlot":true,"databaseSlotName":"barman","lastBackupMaximumAge":"1 day","namespace":"postgresql","postgresql":{"host":"postgresql","port":5432,"replicationPassword":"barman","replicationUser":"barman","superUser":"postgres","superUserDatabase":"postgres","superUserPassword":"postgres"},"retentionPolicy":"RECOVERY WINDOW of 1 MONTH","scopeName":"pg","serviceaccount":"postgresql"}` | Barman retention policy | | barman.backups[0].additionalConfiguration | string | `""` | Barman additional Parameters for configuration File | | barman.backups[0].backupMethod | string | `"postgres"` | Barman backup method | | barman.backups[0].createDatabaseSlot | bool | `true` | Create Database slot | @@ -37,13 +37,17 @@ This chart is maintained by [Adfinis](https://adfinis.com/?pk_campaign=github&pk | barman.backups[0].postgresql.superUser | string | `"postgres"` | Postgresql super user | | barman.backups[0].postgresql.superUserDatabase | string | `"postgres"` | Postgresql super user database | | barman.backups[0].postgresql.superUserPassword | string | `"postgres"` | Postgresql super user password | +| barman.backups[0].scopeName | string | `"pg"` | Postgresql server scope-name | | barman.backups[0].serviceaccount | string | `"postgresql"` | service account of the postgresql deployment, not active when barman.createRbac is false | | barman.barmanUser | string | `"barman"` | Barman user | | barman.compression | string | `"gzip"` | Barman backup compression | | barman.createDatabaseSlot | bool | `true` | Create Database slot | | barman.databaseSlotName | string | `"barman"` | Database slot name to be created/used | | barman.lastBackupMaximumAge | string | `"1 day"` | Barman last backup maximum age | +| barman.postBackupRetryScript | string | `""` | Barman post_backup_retry_script | +| barman.preRecoveryRetryScript | string | `""` | Barman pre_recovery_retry_script | | barman.retentionPolicy | string | `"RECOVERY WINDOW of 1 MONTH"` | Barman retention policy | +| deployment.additionalENVs | object | `{}` | Specify additional ENVs for the Deployment | | deployment.additionalVolumeMounts | list | `[]` | Specify additional VolumeMounts for the barman container | | deployment.additionalVolumes | list | `[]` | Specify additional Volumes for the deployment | | deployment.annotations | object | `{}` | Specify deployment annotations | diff --git a/charts/barman/examples/barman.yaml b/charts/barman/examples/barman.yaml index d9142f249..30e1d6bf2 100644 --- a/charts/barman/examples/barman.yaml +++ b/charts/barman/examples/barman.yaml @@ -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 @@ -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 diff --git a/charts/barman/templates/configmap-barman-backups.yaml b/charts/barman/templates/configmap-barman-backups.yaml index 76ad5207e..08cb4a097 100644 --- a/charts/barman/templates/configmap-barman-backups.yaml +++ b/charts/barman/templates/configmap-barman-backups.yaml @@ -6,8 +6,8 @@ metadata: {{- include "barman.labels" . | nindent 4 }} data: {{- range .Values.barman.backups }} - {{ .postgresql.host }}.conf: | - [{{ .postgresql.host }}] + {{ .scopeName }}.conf: | + [{{ .scopeName }}] active = true description = "PostgreSQL Database (Streaming-Only)" conninfo = host={{ .postgresql.host }} user={{ .postgresql.superUser }} dbname={{ .postgresql.superUserDatabase }} diff --git a/charts/barman/templates/configmap-barman-cron.yaml b/charts/barman/templates/configmap-barman-cron.yaml index aaa583376..33a82715d 100644 --- a/charts/barman/templates/configmap-barman-cron.yaml +++ b/charts/barman/templates/configmap-barman-cron.yaml @@ -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 diff --git a/charts/barman/templates/configmap-barman.yaml b/charts/barman/templates/configmap-barman.yaml index a7d9b2c5d..530a6af5a 100644 --- a/charts/barman/templates/configmap-barman.yaml +++ b/charts/barman/templates/configmap-barman.yaml @@ -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 diff --git a/charts/barman/templates/configmap-entrypoint.yaml b/charts/barman/templates/configmap-entrypoint.yaml new file mode 100644 index 000000000..dddf0b7fd --- /dev/null +++ b/charts/barman/templates/configmap-entrypoint.yaml @@ -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 "$@" diff --git a/charts/barman/templates/configmap.yaml b/charts/barman/templates/configmap.yaml index 4aaa7dae9..40f1af9d3 100644 --- a/charts/barman/templates/configmap.yaml +++ b/charts/barman/templates/configmap.yaml @@ -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 }} diff --git a/charts/barman/templates/deployment.yaml b/charts/barman/templates/deployment.yaml index 9ec46e6f2..99f5fac58 100644 --- a/charts/barman/templates/deployment.yaml +++ b/charts/barman/templates/deployment.yaml @@ -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 }} @@ -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 }} diff --git a/charts/barman/values.yaml b/charts/barman/values.yaml index bfe3a3f1f..63eff907f 100644 --- a/charts/barman/values.yaml +++ b/charts/barman/values.yaml @@ -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 @@ -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