简体   繁体   English

pg_dump从一个Cloud Foundry实例到另一个

[英]pg_dump from one Cloud Foundry instance to another

We are moving a PHP/PostgreSQL web application from a linux server to Cloud Foundry. 我们正在将PHP / PostgreSQL Web应用程序从Linux服务器移至Cloud Foundry。

We have the main application running on an instance with PHP, call it the app instance. 我们的主应用程序在具有PHP的实例上运行,将其称为应用程序实例。 We have the database running on another instance with Postgres, call it the db instance. 我们使用Postgres在另一个实例上运行数据库,将其称为db实例。 The app instance connects to the db instance directly through a host and port through PHP's Postgres extension. 应用实例通过PHP的Postgres扩展直接通过主机和端口连接到数据库实例。

Part of the application uses pg_dump within PHP using php's exec() method. 该应用程序的一部分使用PHP的exec()方法在PHP中使用pg_dump。 (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: 如果我们假设该应用程序实例没有pg_dump二进制文件并且不能s​​sh进入数据库实例(大概有pg_dump),那么有一种方法可以:

  • Create a backup of the database on either one of the instances? 在任一实例上创建数据库的备份?
  • Clone a schema in the database? 克隆数据库中的架构?

I did find this plpgsql function which might be a good option for cloning schemas, but doesn't solve the backup problem. 我确实找到了这个plpgsql函数该函数对于克隆架构可能是一个不错的选择,但是并不能解决备份问题。 Being able to call pg_dump somehow from PHP would save a lot of code rewriting. 能够以某种方式从PHP调用pg_dump可以节省很多代码重写。

Thanks. 谢谢。

One option would be to vendor pg_dump with your application. 一种选择是将供应商pg_dump与您的应用程序一起使用。

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). 为此,启动一个Ubuntu 14.04容器或VM,在其中安装Postgres,然后将pg_dump从VM中复制到您的应用程序目录中(您放置它的位置并不重要,只是在任何公共的地方都没有)。 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. 如果在VM或容器中运行ldd pg_dump (完整或相对路径),则应该能够获得pg_dump依赖的库的列表。 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). 将它们也复制到您的应用程序中,您可以将它们与pg_dump二进制文件放在同一目录中(尽管它们存在的位置并不重要)。

Then when you call exec from your PHP application, you need to do two things. 然后,当您从PHP应用程序调用exec时,您需要做两件事。 First, use the full path to your pg_dump binary. 首先,使用pg_dump二进制文件的完整路径。 Second, you need to set the environment variable LD_LIBRARY_PATH to point to the location of any required shared libraries. 其次,您需要设置环境变量LD_LIBRARY_PATH指向任何必需的共享库的位置。 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 . 组合应该使用复制出的共享库来运行从VM复制出的二进制文件,这应该是运行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. 最好的方法是仅在运行二进制文件时直接设置LD_LIBRARY_PATH ,但是如果不这样做,则可以将.profile文件添加到应用程序中并在其中进行设置。 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 https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM