Postgres-将整个数据库的副本从远程服务器拉到本地开发机 [英] Postgres - Pull a copy of an entire DB from a remote server, to local dev machine

查看:56
本文介绍了Postgres-将整个数据库的副本从远程服务器拉到本地开发机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经试图找到答案,但是答案似乎集中在推"式思维而非拉"式思维上.像这样:

Been trying to find the answer to this, but the answers seem to focus on a "push" mentality rather than "pull". Like this:

将PostgreSQL数据库复制到另一台服务器

我有一台本地VM开发机.Redhat REHEL.我也有一个远程环境,我们将其命名为集成".我对此环境具有SSH访问权限,并且位于远程服务器上的Sudoers组中.

I have a local VM dev machine. Redhat REHEL. I also have a remote environment, let's name it "integration". I have SSH access to this environment and am in the Sudoers group on the remote server.

我想要的是在本地VM上有一种方法,可以在集成时下拉数据库的完整副本,并将其推送到等待的(空)数据库中.我们将该数据库称为"int_backup".

What I want is to have a way on my local VM to pull down a complete copy of the database on integration, and push it into a waiting (empty) db. Let's call that DB "int_backup".

这不必是一个命令.乐于打击多个命令的脚本.但是,这里的关键是集成并不了解我的本地VM,因此无法访问它.因此,必须从VM方面完成任务.

This doesn't have to be one command. Happy to bash script multiple commands. But the key here is integration is unaware of my local VM and cannot access it. So the task must be done from the VM side of things.

欢迎所有建议.但是,在集成上安装软件不是可行的解决方案.

All suggestions welcome. But installing software on integration is not a likely realistic solution.

推荐答案

也许是这样(将公用密钥安装在遥控器的〜postgres/.ssh/authorized_keys 文件中):

Perhaps this way (install your public key on the remote's ~postgres/.ssh/authorized_keys file):

ssh postgres@yourremotehost 'pg_dump yourdbname | xz -0' |\
  xzcat | psql yourdbname

或者,在远程服务器的/etc/sudoers 文件中添加一个条目,以使您的用户能够无密码执行 sudo -u postgres pg_dump yourdbname ,因此您可以运行:

Alternatively, add an entry in your remote's /etc/sudoers file to enable your user with the ability to execute sudo -u postgres pg_dump yourdbname passwordlessly, so you can run:

ssh youruser@yourremotehost 'sudo -u postgres pg_dump yourdbname | xz -0' |\
  xzcat | psql yourdbname

在这两种情况下,转储和还原将同时发生,并且不会创建任何转储文件.

In both cases, the dump and the restore will occur simultaneously, and no dump file will be created.

这篇关于Postgres-将整个数据库的副本从远程服务器拉到本地开发机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆