
In this article, we explain how to restore a MongoDB logical backup performed via mongodump to a mongod instance.
MongoDB logical backups require the mongorestore tool to restore data. This article focuses on that process.
Note: Percona provides mongodb_consistent_backup, which wraps mongodump to provide cluster-wide consistency. Backups created with it can be restored using the same steps as standard mongodump backups.
Required, even for localhost. Include authentication flags if enabled.
Almost always required. Drops collections before restoring to avoid duplicate key errors.
Almost always required. Replays oplog entries for consistency. Look for oplog.bson in the dump directory.
Required. Path to the mongodump data.
Optional. Required if the backup used compression (.bson.gz files).
Optional. Controls parallelism for restoring collections. Default is 4 threads.
(Optional) Extract the backup if archived:
|
1 2 3 4 5 6 7 |
$ tar -C /opt/mongodb/backup/testbackup/20160809_1306 -xvf /opt/mongodb/backup/testbackup/20160809_1306/test1.tar test1/ test1/dump/ test1/dump/wikipedia/ test1/dump/wikipedia/pages.metadata.json.gz test1/dump/wikipedia/pages.bson.gz test1/dump/oplog.bson |
This extracts to /opt/mongodb/backup/testbackup/…/dump
Verify you are restoring the correct backup to the correct host:
Run mongorestore:
|
1 2 3 4 5 6 |
$ mongorestore --drop --host localhost --port 27017 --user secret --password secret --oplogReplay --gzip --dir /opt/mongodb/backup/testbackup/20160809_1306/test1/dump ... restoring wikipedia.pages ... replaying oplog done |
-vvv for verbose debugging if neededVerify completion:
For sharded environments:
--oplog is not supportedIf MongoDB topics interest you, Percona is hiring:
|
1 2 3 4 5 6 7 |
{ hiring: true, role: "Consultant", tech: "MongoDB", location: "USA", moreInfo: "https://www.percona.com/about-percona/careers/mongodb-consultant-usa-based" } |
Resources
RELATED POSTS