We are moving a PHP/PostgreSQL web application from a linux server to Cloud Foundry.
We have the main application running on an instance with PHP, call it the app instance. We have the database running on another instance with Postgres, call it the db instance. The app instance connects to the db instance directly through a host and port through PHP's Postgres extension.
Part of the application uses pg_dump within PHP using php's exec() method. (Ignoring security implications of this..)
If we assume that the app instance doesn't have a pg_dump binary AND can't ssh into the db instance (which does have pg_dump presumably) is there a way to:
I did find this plpgsql function which might be a good option for cloning schemas, but doesn't solve the backup problem. Being able to call pg_dump somehow from PHP would save a lot of code rewriting.
Thanks.
One option would be to vendor pg_dump
with your application.
To do this, spin up an Ubuntu 14.04 container or VM, install Postgres in it and copy pg_dump
out of the VM to your application directory (where you put it doesn't matter really, just not anywhere that would be public). The trick to making this work is that you also have to copy any dependent shared libraries. If you run ldd pg_dump
(full or relative path) in your VM or container, you should be able to get a list of libraries that pg_dump
depends on. Copy those to your app as well, you can put them into the same directory as your pg_dump
binary (although it doesn't really matter where they exist).
Then when you call exec
from your PHP application, you need to do two things. First, use the full path to your pg_dump
binary. Second, you need to set the environment variable LD_LIBRARY_PATH
to point to the location of any required shared libraries. The combination should run the binary that you copied out of the VM while using the shared libraries that you copied out, which should be all you need to run pg_dump
.
The best path would only be to set LD_LIBRARY_PATH
directly and only when you run the binary, but if that's not an option you could add a .profile
file to your application and set it there. Here's an example of what you could put in that file.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/path/to/pg_libs
https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.