17 lines
524 B
Bash
Executable File
17 lines
524 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
: "${BACKUP_DIR:?Set BACKUP_DIR to the destination directory}"
|
|
: "${POSTGRES_DB:?Set POSTGRES_DB}"
|
|
: "${POSTGRES_USER:?Set POSTGRES_USER}"
|
|
: "${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}"
|
|
|
|
timestamp=$(date -u '+%Y%m%dT%H%M%SZ')
|
|
mkdir -p "$BACKUP_DIR"
|
|
output_path="$BACKUP_DIR/${POSTGRES_DB}-${timestamp}.dump"
|
|
|
|
docker compose -f compose.production.yaml exec -T \
|
|
-e PGPASSWORD="$POSTGRES_PASSWORD" postgres \
|
|
pg_dump -U "$POSTGRES_USER" -Fc "$POSTGRES_DB" > "$output_path"
|
|
|
|
printf '%s\n' "$output_path" |