This commit is contained in:
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/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"
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
: "${BACKUP_FILE:?Set BACKUP_FILE to a PostgreSQL custom-format dump}"
|
||||
: "${POSTGRES_DB:?Set POSTGRES_DB}"
|
||||
: "${POSTGRES_USER:?Set POSTGRES_USER}"
|
||||
: "${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}"
|
||||
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
printf '%s\n' "Backup file not found: $BACKUP_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker compose -f compose.production.yaml exec -T \
|
||||
-e PGPASSWORD="$POSTGRES_PASSWORD" postgres \
|
||||
pg_restore --clean --if-exists --no-owner -U "$POSTGRES_USER" -d "$POSTGRES_DB" < "$BACKUP_FILE"
|
||||
Reference in New Issue
Block a user