Backup: http://www.postgresql.org/docs/current/static/app-pgdump.htm...
In short:
pg_dump -Fc mydb > db.dump
Restore: http://www.postgresql.org/docs/current/static/app-pgrestore....In short:
pg_restore -C -d postgres db.dump
Command directly from the shell: psql -c "psql command"