How to backup postgres database in sql file using php script?

I have the following situation.

I have a PHP script that imports a CSV file and then updates the postgres database

Now I need to back up the database before the import happens.

PHP files run on one server and postgres database on another server

I tried exec(pg_dump db_name -CdiOv > /tmp/db_name_backup.sql), but I don't think this will work, since db is on a different server.

I'm not sure how to do this, I can make the correct PHP code by backing up, but that means it starts up.

Any hangover will be appreciated.

+3
source share
2 answers

depesz, -h , , . :

exec("export PGPASSWORD=mypassword && export PGUSER=myuser && pg_dump -h yourremotehost db_name -CdiOv > /tmp/db_name_backup.sql && unset PGPASSWORD && unset PGUSER");

~/.pgpass, . http://www.issociate.de/board/post/43225/pg_dump_+_cronjob.html http://forum.soft32.com/linux/Backup-Postgressql-ftopict460054.html

+4

pg_dump - -h.

- "-CdiOv"?

+1

Source: https://habr.com/ru/post/1716220/


All Articles