Files
k3s/apps/postgres/backup.sh

21 lines
481 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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"