Ssh – Speed up mongodump+mongorestore

mongodbsocketsshssh-tunnel

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.

Best Answer

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.