Below some step by step with bash functions example on how to dump your database and restore it to your db server.
✅ Dump the source database to a file.
function pgDumpDB() {
echo 'Type db user: ' && read DBUSER;
echo 'Type db name: ' && read DBNAME;
pg_dump -U $DBNAME -O $DBNAME $DBNAME.sql
}
✅ Copy the dump file to the remote server.
✅ Create a new database in the remote server: CREATE DATABASE name
✅ Restore the dump file on the remote server:
function pgImportDB() {
echo 'Type db user: ' && read DBUSER
echo 'Type db pass: ' && read DBPASS
echo 'Type db name: ' && read DBNAME
psql -U $DBUSER -c "CREATE DATABASE $DBNAME"
psql -U $DBUSER -d $DBNAME -f $DBNAME.sql
}
https://www.postgresqltutorial.com/postgresql-copy-database/