We all know how important it is to back up the database, and that is very easy to do in PostgreSQL with pg_dumpall > somefile or pg_dump > somefile. But what if you want to do this from a web page? How do you set the permissions so you can do the dump and copy it to a file that can be downloaded?
I have written a web page using passthru() which calls a simple shell script (savescript) that does this, but there is a problem. The shell script does pg_dumpall > /tmp/dumpfile. It runs fine from the command line, and I end up with the dumpfile in /tmp/dumpfile, owned by me (cehsys/cehsys). However, when I put it into my HTML/PHP web page with passthru("/bin/sh cgi-bin/savescript") there is a problem. My web page writes a file where it is supposed to (/tmp/dumpfile). However, with this method the file is now owned by Apache/Apache and it is only a very brief set of messages.
I have considered adding Apache as a user under postgres, but I'm wondering if that would create unnecessary security holes.
How do you write the PHP and the script to end up with a proper backup? I assume that everybody provides backups in their web sites ... :).
Thanks in advance for your help.
CEH