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
.
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/
Getting the OC command line interface
The steps below use the OpenShift command line interface (to run the
oc
commands).The download link for your relevant operating system can be found by going to:
OpenShift Online Console
>[Click on help icon]
>Command Line Tools
That location also contains the command required to login.
It looks something like this:
You can then run the following to display all the pods in your project:
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:(gleaned from comments here)
02)
To perform the dump, go to pod terminal in openshift console:OpenShift Online Console
>Applications
>Pods
>MongoDB-**-*****
>Terminal
and enter this:
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 forMONGODB_USER
.I got this returned in terminal when running the above command:
03)
If you want to zip the dump folder, do this from pod terminal in console:(gleaned from comments here)
04)
To download the folder, from local PC terminal, do this:Or if you want to download the zip file instead, do this:
(gleaned from official docs and blog post here)
For reference, if you wanted to do a
mongoexport
of a collection to a.json
file (as opposed to amongodump
of all databases), you can do the following from the pod terminal and then download the file usingoc rsync
as shown above:Random update (14/01/23):
Annoyingly, I cannot see what version of
mongodump
is being used when I run the following from the pod terminal:So I don't know if that will be problematic when it comes to doing a
mongorestore
and needing to ensure that themongodump
andmongorestore
versions are compatible :/.END 20/11/18 update
SSH In
Check what version of mongodump you have:
mongodump
The command below will dump *ALL* databases.
Zip Dump Folder
Exit SSH
Download via SCP
(Replace the environment variable below with the actual value).
SSH back in and delete dump files
In local command line, go to the directory where you downloaded the zip file:
Unzip Dump Folder
See what version of mongorestore you have and that everything is compatible:
At this point, I deleted all my local *corresponding* databases in RockMongo so that the restore process would create them from scratch.
mongorestore
The default host and port used is
localhost
and27017
.