大网数据广告活动
服务器运维问答

Speed up mongodump+mongorestore

· 52CE 我爱测

I have created a script to copy a MongoDB database to my machine. I am creating an SSH tunnel ( ssh -L ... ) then I connect to the tunnelled port with mongodump then I pipe its output to mongorestore : mongodump --host=127.0.0.1:…

问题原文

原帖链接 · warvariuc · CC BY-SA 3.0

I have created a script to copy a MongoDB database to my machine. I am creating an SSH tunnel (ssh -L ...) then I connect to the tunnelled port with mongodump then I pipe its output to mongorestore:

mongodump --host=127.0.0.1:##### --db=***** --archive | mongorestore --host={mongo_dest} --drop --archive

I would like to speed up the copying. --gzip doesn't make sense to be used in this case -- because the same machine and memory are used by mongodump and mongorestore. The data comes uncompressed via the SSH socket.

Is there a way to run mongodump on the SSHed machine and pipe its output to a process on my machine?

Of course I could dump the database, archive, copy over SSH and restore it. But I don't want taking temporary space.

已采纳解答

原帖链接 · warvariuc · CC BY-SA 3.0

Don't know why I didn't think of it:

ssh *** ". /etc/profile; mongodump --host=127.0.0.1:27017 --db=**** --archive --gzip" | mongorestore --host=127.0.0.1:27017 --drop --archive --gzip

Was 1603.96 real 45.24 user 43.57 sys.

Now 209.52 real 7.25 user 6.03 sys.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。