Backup
The following command will back up a remote database to a file name <file>
on the machine you run this command on.
pg_dump -h <host> -U <username> -W <database> > <file>
Restore
The following command will restart a backup file to a database.
psql -U user -W <database> < <file>
Useful Hints
If you are trying to restore the database to a docker compose project you can use the following command.
# Assuming that db is the name of your database service
docker cp <file> "$(docker compose ps -q db)":/
docker exec -it "$(docker compose ps -q db)" /bin/bash
psql -U user -W v8 < <file>