diff --git a/templates/configmap.yaml b/templates/configmap.yaml new file mode 100644 index 0000000..00383ce --- /dev/null +++ b/templates/configmap.yaml @@ -0,0 +1,80 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "postgresql.fullname" . }}-config + labels: + {{- include "postgresql.labels" . | nindent 4 }} +data: + {{- if .Values.replication.enabled }} + primary-init.sh: | + #!/bin/bash + set -e + + # レプリケーションユーザーの作成 + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER {{ .Values.postgres.replicationUser }} WITH REPLICATION ENCRYPTED PASSWORD '${REPLICATION_PASSWORD}'; + EOSQL + + # pg_hba.confの設定 + echo "host replication {{ .Values.postgres.replicationUser }} 0.0.0.0/0 md5" >> ${PGDATA}/pg_hba.conf + + # postgresql.confの設定 + cat >> ${PGDATA}/postgresql.conf < ${BACKUP_FILE} + + # 古いバックアップの削除 + find ${BACKUP_DIR} -name "backup_*.sql.gz" -mtime +${RETENTION_DAYS} -delete + + echo "Backup completed: ${BACKUP_FILE}" + + # バックアップサイズの確認 + ls -lh ${BACKUP_FILE} + {{- end }} +