def dump_db_to_file(dump_path, database, no_owner=True, **kwargs):
    # Set a .pgpass file up so we're not prompted for a password.
    set_pgpass(database)
    
    cmd = ['pg_dump', '-i']
    
    # Add some common postgres options.
    add_common_options_to_cmd(cmd, database, **kwargs)
    
    # Plain formatting
    cmd.append('--format=p')

    if no_owner:
        cmd.append('--no-owner')

    cmd.append(database['NAME'])
    
    print "pg_dumping database '%s' to %s" % (database['NAME'], dump_path)
    
    # Run pg_dump
    db_dump = Popen(cmd, stdout=PIPE)
    # Open the eventual .tar.bz2 file for writing by bzip2.
    tfile = open(dump_path, 'w')
    # Use bzip2 to dump into the open file handle via stdout.
    db_bzip = Popen(['bzip2'], stdin=db_dump.stdout, stdout=tfile)
    db_bzip.wait()
    tfile.close()
    
    print "Database dump complete."
    
    return dump_path
pg_dumps the specified database to a given path. Passes output through
dataset/ETHPy150Open duointeractive/django-fabtastic/fabtastic/db/postgres.py/dump_db_to_file