-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.sh
33 lines (26 loc) · 907 Bytes
/
dump.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
set -e
set -o pipefail
# Verify POSTGRES_* parameters
if [ "${POSTGRES_HOST}" = "**None**" ]; then
echo "You need to set the POSTGRES_HOST environment variable."
exit 1
fi
if [ "${POSTGRES_DATABASE}" = "**None**" ]; then
echo "You need to set the POSTGRES_DATABASE environment variable."
exit 1
fi
if [ "${POSTGRES_USER}" = "**None**" ]; then
echo "You need to set the POSTGRES_USER environment variable."
exit 1
fi
if [ "${POSTGRES_PASSWORD}" = "**None**" ]; then
echo "You need to set the POSTGRES_PASSWORD environment variable."
exit 1
fi
# Set parameters for dump
export PGPASSWORD=$POSTGRES_PASSWORD
POSTGRES_HOST_OPTS="-h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER"
# Dump the database
echo "Creating dump of database ${POSTGRES_DATABASE} from host ${POSTGRES_HOST}..."
pg_dump $POSTGRES_HOST_OPTS $POSTGRES_EXTRA_OPTS ${POSTGRES_DATABASE} --file=$BACKUP_FILE