PostgreSQL support added to django-export
A month ago I found django-export on github. django-export is a great Django app to export a database dump and media files with support to export to Amazon S3
The only problem with it was that django-export did not support PostgreSQL which is many Django developers’ database of choice. To solve this I forked Arne Brodowski’s django-export on github and added support for PostgreSQL databases. The result is is available on github
The main issue with PostgreSQL is that there is no way to pass the password in the command line. To work around this problem, I used the .pgpass file. Here’s the set of commands I used:
# Assume that $HOST, $PORT, $DATABASE, $USER and $PASSWORD have been set # Create empty .pgpass if it didn't exist touch ~/.pgpass # Make a copy of current .pgpass mv ~/.pgpass ~/.pgpass.bak # Add entry to .pgpass echo "$HOST:$PORT:$DATABASE:$USER:$PASSWORD" > ~/.pgpass # Apply proper permissions chmod 600 ~/.pgpass # pg_dump piped to bzip (as per django-export) pg_dump -h $HOST -p $PORT -U $USER $DATABASE | bzip2 -c # Restore original .pgpass (will restore an empty file if .pgpass did not exist) mv ~/.pgpass.bak ~/.pgpass
Thanks to Arne Brodowski for a a great Django app.
Advertisement