How to dump remote dokku-mongodb and restore local instance

I have a side project using dokku, it works well. But then I want to dump the production data to local in order to test some cases. I thought it should be as simple as dump and restore, but I was wrong. It took me a while, I think write it down might help someone else or future me.

1 Dump the database on the server

1
dokku mongo:export mongo_service_name > data.dump.gz

2 Download to your local machine

1
scp root@222.222.222.222:data.dump.gz ~/

3 Restore

1
mongorestore --host localhost:27017 --gzip --archive=data.dump.gz --db mongo_service_name

The tricky part is the name after --db, should match the database name in your dump file.

4 End

That’s all. Hope it helps.

Thanks for reading!

Follow me (albertgao) on twitter, if you want to hear more about my interesting ideas.