Initial commit: k8s cluster manifests and scripts
This commit is contained in:
20
apps/postgres/backup.sh
Executable file
20
apps/postgres/backup.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# 用途:備份 Postgres 到本機(使用 pg_dumpall)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
BACKUP_DIR="$(cd "$(dirname "$0")" && pwd)/backups"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
POD=$(kubectl get pod -l app=postgres -o jsonpath='{.items[0].metadata.name}')
|
||||
TS=$(date +%Y%m%d_%H%M%S)
|
||||
OUT="$BACKUP_DIR/postgres-backup-$TS.sql"
|
||||
|
||||
echo "使用 Pod:$POD"
|
||||
echo "開始備份..."
|
||||
|
||||
kubectl exec "$POD" -- sh -c 'pg_dumpall -U "$POSTGRES_USER"' > "$OUT"
|
||||
|
||||
echo "備份完成:"
|
||||
echo "$OUT"
|
||||
|
||||
Reference in New Issue
Block a user