views:

137

answers:

1

Hi. I am trying to make a Postgres PHP backup script. I have downloaded one for the command line which looks like this:

#!/bin/bash
find /home/russell/pg_bkp -type f -mtime +7 -exec rm {} \;
time=`date +%Y-%m-%d`; # date in reverse so that lastest date appears last in the list of backup files.
PGPASSWORD=****** pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v -f "/home/russell/pg_bkp/$time.backup" ah3

How can I implement this in PHP? The extension that this creates is .backup. It works great and have used it many times. the data is perfect, but doing it from inside my website would be better. Thanks

A: 

Please, format better the code.

For your question, you can save those command in a file, and then call it throught php via exec or passthru.

In php, you can even write the command with the special apostrophes, `, and it will be executed.

Just make sure the PHP service has the permission to run that script

DaNieL