Reputation: 9075
I need a way to produce a snapshot for a particular mongo database and be able to recreate that exact database on another server. I'm familiar with mongodump
and mongorestore
commands, but I need a single human-readable file (or better print everything to stdout) for the entire database, which mongodump
doesn't do yet, which is known and expected and here are the details why. I have two related questions.
First, does mongodump
produce any other critical data besides collection names and indexes (when dumping a specific database) and if it does what is it? If I recall correctly, mongo might not like dumps made in different versions, which also might be a problem, is that true?
Second, if I manually extract collection names and index information, store it into a json of my own format, and then restore it on another server, will that be sufficient to create the identical database or would it be missing something?
Upvotes: 2
Views: 4742
Reputation: 65303
First, does mongodump produce any other critical data besides collection names and indexes (when dumping a specific database) and if it does what is it?
mongodump
produces a binary backup of your data, including the specific BSON types that are used for fields. Additional metadata exported includes collection options (if you've changed any from the default) and index definitions. You can see this additional information in the *.metadata.json
files created by mongodump
.
If I recall correctly, mongo might not like dumps made in different versions, which also might be a problem, is that true?
In general you should be able to replay older dumps with newer mongorestore
versions. Some older versions of mongodump
may not export all of the collection metadata you are expecting, so the general advice is to mongodump
with at least the version of the mongod
server you are running if not newer. One such example would be mongodump
prior to 2.2, which did not create the metadata.json
information so you would have to manually ensure indexes and collection option.
Second, if I manually extract collection names and index information, store it into a json of my own format, and then restore it on another server, will that be sufficient to create the identical database or would it be missing something?
Assuming you recreate all the collection & index options (and correctly apply those when creating new collections) your database will be similar on the remote server but likely not identical.
The main difference will be the type integrity for fields (although this may not be of concern for your use case). BSON supports a richer set of data types than JavaScript. For example, JavaScript has a single Number type while BSON supports int32, int64, and double.
If your backup/restore process takes this into account using something like MongoDB Extended JSON to represent additional types, you can probably make the two databases more consistent.
Upvotes: 2