It is very easy to backup a postgres database and restore it. The commands used are pg_dump and pg_restore. A backup can be created in 4 formats:
I usually prefer the custom-format as it “is the most flexible output format” and “is also compressed by default”. The commands are:
pg_dump -U postgres -W dbname -Fc -f filename.db.backup
This file can be restore to a new database with:
pg_restore -U postgres -Fc -d dbname filename.db.backup