Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions dump.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/bin/bash -e

psql -h localhost -U "$POSTGRES_USER" -d postgres -c "drop database if exists $POSTGRES_DB;"
psql -h localhost -U "$POSTGRES_USER" -d postgres -c "create database $POSTGRES_DB;"
export PGPASSWORD="$POSTGRES_PASSWORD"

sql() {
psql -h localhost -U "$POSTGRES_USER" -d $1 -c "$2"
}

sql postgres "drop database if exists $POSTGRES_DB;"
sql postgres "create database $POSTGRES_DB;"

# We exclude some tables:
#
# - 'serverdb_*' because it is huge and usually not needed locally
# - 'apps_application' because it contains access tokens for production
ssh "$REMOTE_DB" \
"pg_dump -O -x --exclude-table-data='serverdb_*' -d serveradmin | gzip -9 -c " \
"pg_dump -O -x --exclude-table-data='serverdb_*' --exclude-table-data='apps_application' -d serveradmin | gzip -9 -c " \
| gunzip -c \
| psql -h localhost -U "$POSTGRES_USER" -d "$POSTGRES_DB"
| psql -h localhost -U "$POSTGRES_USER" -d "$POSTGRES_DB"
Loading