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= --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.


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

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

Was 1603.96 real 45.24 user 43.57 sys.

Now 209.52 real 7.25 user 6.03 sys.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.