mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-17 18:24:14 +02:00
fix: attempt pgbackup
This commit is contained in:
@@ -44,35 +44,7 @@ spec:
|
|||||||
envFrom: &envFrom
|
envFrom: &envFrom
|
||||||
- secretRef:
|
- secretRef:
|
||||||
name: cloudnative-pg-postgres16-pgdump-secret
|
name: cloudnative-pg-postgres16-pgdump-secret
|
||||||
command:
|
command: /scripts/list_dbs.sh
|
||||||
- "/bin/bash"
|
|
||||||
- "-c"
|
|
||||||
- |
|
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o nounset
|
|
||||||
set -o errexit
|
|
||||||
|
|
||||||
# File to store the list of databases
|
|
||||||
OUTPUT_FILE="/config/db_list"
|
|
||||||
|
|
||||||
# Export PG password to avoid password prompt
|
|
||||||
export PGPASSWORD=$POSTGRES_PASSWORD
|
|
||||||
|
|
||||||
# Generate a regex pattern for exclusion
|
|
||||||
EXCLUDE_PATTERN=$(echo $EXCLUDE_DBS | sed 's/ /\\|/g')
|
|
||||||
|
|
||||||
# List all databases, exclude the ones in EXCLUDE_DBS, and write to the file
|
|
||||||
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -lqt | \
|
|
||||||
cut -d \| -f 1 | \
|
|
||||||
grep -Ev "^\s*($EXCLUDE_PATTERN)\s*$" > "$OUTPUT_FILE"
|
|
||||||
|
|
||||||
# Unset PG password
|
|
||||||
unset PGPASSWORD
|
|
||||||
|
|
||||||
echo "Database list saved to $OUTPUT_FILE"
|
|
||||||
|
|
||||||
cat $OUTPUT_FILE
|
|
||||||
containers:
|
containers:
|
||||||
app:
|
app:
|
||||||
image:
|
image:
|
||||||
@@ -104,3 +76,10 @@ spec:
|
|||||||
path: /var/mnt/vol1/backups/postgresql
|
path: /var/mnt/vol1/backups/postgresql
|
||||||
globalMounts:
|
globalMounts:
|
||||||
- path: /backups
|
- path: /backups
|
||||||
|
scripts:
|
||||||
|
enabled: true
|
||||||
|
type: configMap
|
||||||
|
name: cloudnative-pg-postgres16-pgdump-scripts # overriden by kustomizeconfig
|
||||||
|
defaultMode: 0775
|
||||||
|
globalMounts:
|
||||||
|
- path: /scripts
|
||||||
|
@@ -6,3 +6,11 @@ namespace: default
|
|||||||
resources:
|
resources:
|
||||||
- ./externalsecret.yaml
|
- ./externalsecret.yaml
|
||||||
- ./helmrelease.yaml
|
- ./helmrelease.yaml
|
||||||
|
configMapGenerator:
|
||||||
|
- name: cloudnative-pg-postgres16-pgdump-scripts
|
||||||
|
files:
|
||||||
|
- list_dbs.sh=./scripts/list_dbs.sh
|
||||||
|
generatorOptions:
|
||||||
|
disableNameSuffixHash: true
|
||||||
|
annotations:
|
||||||
|
kustomize.toolkit.fluxcd.io/substitute: disabled
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
|
||||||
|
# File to store the list of databases
|
||||||
|
OUTPUT_FILE="/config/db_list"
|
||||||
|
|
||||||
|
# Export PG password to avoid password prompt
|
||||||
|
export PGPASSWORD="$POSTGRES_PASSWORD"
|
||||||
|
|
||||||
|
# Convert EXCLUDE_DBS to an array
|
||||||
|
IFS=' ' read -r -a EXCLUDE_ARRAY <<< "$EXCLUDE_DBS"
|
||||||
|
|
||||||
|
# List all databases and filter out the excluded ones
|
||||||
|
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -lqt | \
|
||||||
|
cut -d \| -f 1 | \
|
||||||
|
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | \
|
||||||
|
while read -r dbname; do
|
||||||
|
skip=false
|
||||||
|
for exclude in "${EXCLUDE_ARRAY[@]}"; do
|
||||||
|
if [[ "$dbname" == "$exclude" ]]; then
|
||||||
|
skip=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ "$skip" == false ]]; then
|
||||||
|
echo "$dbname"
|
||||||
|
fi
|
||||||
|
done > "$OUTPUT_FILE"
|
||||||
|
|
||||||
|
# Unset PG password
|
||||||
|
unset PGPASSWORD
|
||||||
|
|
||||||
|
echo "Database list saved to $OUTPUT_FILE"
|
||||||
|
|
||||||
|
cat $OUTPUT_FILE
|
Reference in New Issue
Block a user