Speed up mongodump+mongorestore

5,438

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.

Share:
5,438

Related videos on Youtube

warvariuc
Author by

warvariuc

An engineer who cares about what he does and how he does it.

Updated on September 18, 2022

Comments

  • warvariuc
    warvariuc over 1 year

    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.

  • libby
    libby over 3 years
    My loads sped up tenfold from this. Thank you.