NAS-123939 / 24.04 / fix postgres backup in nextcloud (#1513)

* fix postgres backup in nextcloud

* fix value fetching
This commit is contained in:
Stavros Kois
2023-09-12 21:35:54 +03:00
committed by GitHub
parent a9dad3ef96
commit 0124e8d02a
4 changed files with 26 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ description: A file sharing server that puts the control and security of your ow
annotations:
title: Nextcloud
type: application
version: 1.6.46
version: 1.6.47
apiVersion: v2
appVersion: 27.0.2
kubeVersion: '>=1.16.0-0'

View File

@@ -6,10 +6,19 @@ metadata:
rollme: {{ randAlphaNum 5 | quote }}
data:
entrypoint.sh: |-
#!/bin/sh
cmd="/docker-entrypoint.sh postgres"
eval "${cmd}" & disown;
until pg_isready; do
sleep 5;
done;
pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName" . }} > /postgres_backups/$BACKUP_NAME;
#!/bin/bash
echo "Fetching password from config.php"
# sed removes ' , => spaces and db* from the string
DBUSER=$(cat /nc-config/config.php | grep "dbuser" | sed "s/dbuser\| \|'\|,\|=>//g")
DBPASS=$(cat /nc-config/config.php | grep "dbpassword" | sed "s/dbpassword\| \|'\|,\|=>//g")
DBNAME=$(cat /nc-config/config.php | grep "dbname" | sed "s/dbname\| \|'\|,\|=>//g")
[ -n "$DBUSER" ] && [ -n "$DBPASS" ] && [ -n "$DBNAME" ] && echo "User, Database and password fetched from config.php"
until pg_isready -U ${POSTGRES_USER} -h ${POSTGRES_HOST}; do sleep 2; done
# pg_dump will automatically use the password from the PGPASSWORD environment variable
echo "Creating backup of ${DBNAME} database as ${DBUSER}"
PGPASSWORD=${DBPASS} pg_dump -U $DBUSER -d $DBNAME --host=${POSTGRES_HOST} > /postgres_backups/$BACKUP_NAME \
&& echo "Backup created successfully" \
|| echo "Backup failed"

View File

@@ -1,6 +1,7 @@
{{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := (. | mustDeepCopy) }}
{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }}
{{ $dbHost := .Values.nextcloudDbHost }}
apiVersion: batch/v1
kind: Job
metadata:
@@ -24,11 +25,16 @@ spec:
env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
- name: BACKUP_NAME
value: {{ template "postgres.backupName" . }}
- name: POSTGRES_HOST
value: {{ $dbHost }}
volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }}
- name: backup-script-configmap
mountPath: /bin/backup_entrypoint.sh
readOnly: true
subPath: entrypoint.sh
- name: nextcloud-data
mountPath: /nc-config
subPath: "config"
command:
- "/bin/backup_entrypoint.sh"
volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }}
@@ -36,4 +42,7 @@ spec:
configMap:
defaultMode: 0700
name: "postgres-backup-hook-config-map"
{{ if .Values.appVolumeMounts }}
{{- include "common.storage.configureAppVolumes" .Values | nindent 8 }}
{{ end }}
{{- end -}}

View File

@@ -1,24 +0,0 @@
{{- if .Values.ixChartContext.isUpgrade -}}
{{ $values := (. | mustDeepCopy) }}
{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }}
apiVersion: batch/v1
kind: Job
metadata:
name: "pre-upgrade-hook1"
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "-1"
"helm.sh/hook-delete-policy": hook-succeeded
rollme: {{ randAlphaNum 5 | quote }}
spec:
template:
metadata:
name: "pre-upgrade-hook1"
spec:
restartPolicy: Never
serviceAccountName: "{{ template "common.names.serviceAccountName" . }}"
containers:
- name: kubectl
image: "bitnami/kubectl:1.19"
command: ["kubectl", "delete" , "deployment", "{{ template "common.names.fullname" . }}", "{{ template "common.names.fullname" $values }}"]
{{- end -}}