端口5432被阻止时,来自远程服务器的pg_dump postgres数据库 [英] pg_dump postgres database from remote server when port 5432 is blocked
问题描述
我正在尝试pg_dump我们DMZ中的远程服务器上的SQL数据库。有两个问题。
I'm trying to pg_dump a SQL database on a remote server in our DMZ. There are 2 problems.
1)远程服务器上没有太多空间,因此正常命令运行以本地备份数据库
pg_dump -C数据库> sqldatabase.sql.bak
由于空间问题而无法使用。
1) there is n't a lot of space left on the remote server so the normal command run to locally backup the database
pg_dump -C database > sqldatabase.sql.bak
won't work due to space issues.
2)我也无法运行其他版本的pg_dump命令,使用以下命令将数据库从远程服务器转储到本地服务器:
2) I also can't run the other version of pg_dump command to dump database from remote server to local server using:
pg_dump -C -h remotehost -U remoteuser db_name | psql localhost -U localuser db_name
,因为服务器位于我们的DMZ中,端口5432被阻止。我希望看到的是是否有可能pg_dump数据库并立即将其(ssh或其他形式)保存为文件到远程服务器。
我正在尝试的是: pg_dump -C testdb | ssh admin@ourserver.com | > /home/admin/testdb.sql.bak
as the server is in our DMZ and port 5432 is blocked. What I'm looking to see is if it is possible to pg_dump the database and immediatly save it (ssh or some other form) as a file to a remote server.
What I was trying was: pg_dump -C testdb | ssh admin@ourserver.com | > /home/admin/testdb.sql.bak
有人知道我要实现的目标吗?
Does anyone know if what i am trying to achieve is possible?
推荐答案
您可以使用ssh连接到远程服务器,执行连接pg_dump调用,然后将输出发送回stdout
You can connect with ssh to your remote server, do with the connect the pg_dump call and send the output back to stdout of local machine.
ssh user@remote_machine "pg_dump -U dbuser -h localhost -C --column-inserts" \
> backup_file_on_your_local_machine.sql
这篇关于端口5432被阻止时,来自远程服务器的pg_dump postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!