diff --git a/dump.sh b/dump.sh index 259140b2..fafdff37 100755 --- a/dump.sh +++ b/dump.sh @@ -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" \ No newline at end of file + | psql -h localhost -U "$POSTGRES_USER" -d "$POSTGRES_DB"