Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why mongodump does not backup indexes?

Tags:

mongodb

While reading the mongodump documentation, I came across this information. "mongodump only captures the documents in the database in its backup data and does not include index data. mongorestore or mongod must then rebuild the indexes after restoring data."

Considering that indexes are also critical piece of the database puzzle and they form required to be rebuilt, why doesn't mongodump have an option of taking the backups with indexes?

I get that there are two advantages of not backing up indexes as a default option: 1. We save time which would otherwise be required for backup and restore of indexes. 2. We save space required for storing the backups.

But why not have it as an option at all?

like image 700
Hemant Shinde Avatar asked Apr 26 '16 03:04

Hemant Shinde


People also ask

Does Mongodump preserve indexes?

Yes, mongodump does export the indexes created on the collection, and the indexes are restored with mongorestore along with the data.

What is the difference between Mongodump and Mongoexport?

mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.

How recover data from Mongodump?

Basic mongorestore syntax The basic way to restore a database is to use the mongorestore command to specify the backup directory (dump directory) without any options. This option is suitable for databases located in the localhost (127.0. 0.1) using the port 27017.

Where is Mongodump stored?

The mongodump command will overwrite the existing files within the given backup folder. The default location for backups is the dump/ folder. When the WiredTiger storage engine is used in a MongoDB instance, the output will be uncompressed data.


1 Answers

mongodump creates a binary export of data from a MongoDB database (in BSON format). The index definitions are backed up in <dbname>.metadata.json files, so mongorestore can recreate the original data & indexes.

There are two main reasons that the actual indexes cannot be backed up with mongodump:

  • Indexes point to locations in the data files. The data files do not exist if you are only exporting the documents in the data files (rather than taking a full file copy of the data files).

  • The format of indexes on disk is storage-engine specific, whereas mongodump is intended to be storage-engine independent.

If you want a full backup of data & indexes, you need to backup by copying the underlying data files (typically by using filesystem or EBS snapshots). This is a more common option for larger deployments, as mongodump requires reading all data into the mongod process (which will evict some of your working set if your database is larger than memory).

like image 97
Stennie Avatar answered Nov 16 '22 03:11

Stennie