I just did this myself (as a RockMongo export and import was corrupted) so just posting here.
Note this was for MongoDB verison 2.4.9 with corresponding versions of mongodump and mongorestore.
Read the documentation relevant to your versions first, backup, make sure the solution below is relevant to your scenario etc.
http://docs.mongodb.org/v2.4/reference/program/mongodump/
http://docs.mongodb.org/v2.4/reference/program/mongorestore/
BEGIN 20/11/18 update
I just had to revisit these steps again, the following may be helpful to others:
01) To view all MongoDB environment variables, from local computer run:
oc exec mongodb-XX-XXXXX env
(gleaned from comments here)
02) To perform the dump, go to pod terminal in openshift console and enter this:
mongodump --host MONGODB_SERVICE_HOST:MONGODB_SERVICE_PORT --username admin --password "MONGODB_ADMIN_PASSWORD"
replacing the variable names with the actual values displayed from running the previous command.
I had to use the username admin rather than the environment variable value for MONGODB_USER.
03) If you want to zip the dump folder, do this from pod terminal in console:
tar czf my_dump.tar.gz dump
(gleaned from comments here)
04) To download the folder, from local PC terminal, do this:
oc rsync mongodb-20-XXXXX:/opt/app-root/src/dump /c/Users/Your-Directory
(gleaned from official docs and blog post here)
END 20/11/18 update
SSH In
rhc ssh [app-name]
cd app-root/repo/
Check what version of mongodump you have:
mongodump --version
mongodump version 2.4.9
mongodump
The command below will dump *ALL* databases.
mongodump --host $OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT --username $OPENSHIFT_MONGODB_DB_USERNAME --password $OPENSHIFT_MONGODB_DB_PASSWORD
Zip Dump Folder
zip -r dump.zip dump
Exit SSH
exit
Download via SCP
(Replace the environment variable below with the actual value).
scp [email protected]:~/app-root/repo/dump.zip /var/www/html
SSH back in and delete dump files
rhc ssh [app-name]
cd app-root/repo/
rm -r dump
rm -r dump.zip
In local command line, go to the directory where you downloaded the zip file:
cd /var/www/html
Unzip Dump Folder
unzip dump.zip -d dump
See what version of mongorestore you have and that everything is compatible:
mongorestore --version
mongorestore version 2.4.9
At this point, I deleted all my local *corresponding* databases in RockMongo so that the restore process would create them from scratch.
mongorestore
mongorestore dump
The default host and port used is localhost and 27017.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With