Im wondering how can I create a mongodump/mongorestore without backing up, restoring the indexes?
and how to incrementally restore a mongo db without restoring the indexes?
In MongoDB, mongorestore utility is used to restore the backup data. It restores the binary backup created by mongodump utility(i.e., BSON data dumps). It can restore either an entire database backup or a subset of the backup. It also restores the indexes which are created for any collection inside that database.
mongodump excludes the content of the local database in its output. mongodump output only captures the documents in the database and does not include index data. mongorestore or mongod must then rebuild the indexes after restoring data.
To restore a single database or a collection (or specific documents) from a snapshot, you can use the Queryable Backup to export a single database or collection to restore to the target deployment.
The mongodump
utility creates a binary export of data from MongoDB and saves index definitions and collection options in a metadata.json
associated with each database dumped. The index details do not take any significant space in your backup, and will normally be used by mongorestore
to re-ensure indexes after each data for each collection is imported from a dump.
If you want to avoid creating any new secondary indexes after the restore completes, mongorestore
has a --noIndexRestore
option.
Note: The default _id
index is required, and always created.
incrementally restore a mongo db without restoring the indexes?
The option for --noIndexRestore
applies whether or not you are restoring into an existing database. If you mongorestore
into an existing database with indexes using the --noIndexRestore
option, no new index definitions will be added but existing indexes will still be updated as data is inserted.
Incremental backup & restore is really a separate question unless you have a simplistic use case: inserting new documents from successive dumps.
As at MongoDB 2.6, the mongorestore
utility only inserts documents (i.e. there is no option for updates/upserts). You can use mongorestore
to insert multiple dumps into an existing collection, but any documents causing duplicate key exceptions (eg. _id
) will be skipped.
I would normally expect that an incremental backup & restore implies taking a delta of changes (all inserts/updates/deletions since a prior backup) and being able to re-apply those to an older copy of the same data. To achieve an incremental backup, you need a history of changes to data, which in MongoDB's case would be provided by the replica set operation log (oplog).
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