Restore a MongoDB Logical Backup

$ mongorestore --drop --host localhost --port 27017 --user secret --password secret --oplogReplay --gzip --dir /opt/mongodb/backup/testbackup/20160809_1306/test1/dump
2016-08-09T14:23:04.057+0200    building a list of dbs and collections to restore from /opt/mongodb/backup/testbackup/20160809_1306/test1/dump dir
2016-08-09T14:23:04.065+0200    reading metadata for wikipedia.pages from /opt/mongodb/backup/testbackup/20160809_1306/test1/dump/wikipedia/pages.metadata.json.gz
2016-08-09T14:23:04.067+0200    restoring wikipedia.pages from /opt/mongodb/backup/testbackup/20160809_1306/test1/dump/wikipedia/pages.bson.gz
2016-08-09T14:23:07.058+0200    [#######.................]  wikipedia.pages  63.9 MB/199.0 MB  (32.1%)
2016-08-09T14:23:10.058+0200    [###############.........]  wikipedia.pages  127.7 MB/199.0 MB  (64.1%)
2016-08-09T14:23:13.060+0200    [###################.....]  wikipedia.pages  160.4 MB/199.0 MB  (80.6%)
2016-08-09T14:23:16.059+0200    [#######################.]  wikipedia.pages  191.5 MB/199.0 MB  (96.2%)
2016-08-09T14:23:19.071+0200    [########################]  wikipedia.pages  223.5 MB/199.0 MB  (112.3%)
2016-08-09T14:23:22.062+0200    [########################]  wikipedia.pages  255.6 MB/199.0 MB  (128.4%)
2016-08-09T14:23:25.067+0200    [########################]  wikipedia.pages  271.4 MB/199.0 MB  (136.4%)
...
...
2016-08-09T14:24:19.058+0200    [########################]  wikipedia.pages  526.9 MB/199.0 MB  (264.7%)
2016-08-09T14:24:22.058+0200    [########################]  wikipedia.pages  558.9 MB/199.0 MB  (280.8%)
2016-08-09T14:24:23.521+0200    [########################]  wikipedia.pages  560.6 MB/199.0 MB  (281.6%)
2016-08-09T14:24:23.522+0200    restoring indexes for collection wikipedia.pages from metadata
2016-08-09T14:24:23.528+0200    finished restoring wikipedia.pages (32725 documents)
2016-08-09T14:24:23.528+0200    replaying oplog
2016-08-09T14:24:23.597+0200    done

-host/-port (and -user/-password)

Required, even if you're using the default host/port (localhost:27017). If authorization is enabled, add -user/-password flags also.

-drop

This is almost always required. This causes mongodump to drop the collection that is being restored before restoring it. Without this flag, the documents from the backup are inserted one at a time and if they already exist the restore fails.

-oplogReplay

This is almost always required. Replays the oplog that was dumped by mongodump. It is best to include this flag on replset-based backups unless there is a specific reason not to. You can tell if the backup was from a replset by looking for the file oplog.bson at the base of the dump directory.

-dir

Required. The path to the mongodump data.

-gzip

Optional. For mongodump >= 3.2, enables inline compression on the restore. This is required if mongodump used the -gzip flag (look for *.bson.gz files if you're not sure if the collection files have no .gz suffix, don't use -gzip).

-numParallelCollections=<number>

Optional. For mongodump >= 3.2 only, sets the number of collections to insert in parallel. By default, four threads are used, and if you have a large server and you want to restore faster (more resource usage, though), you could increase this number. Note that each thread uncompresses bson if the -gzip flag is used, so consider this when raising this number.

If you encounter problems with mongorestore, carefully read the error message or rerun with several -v flags, e.g.: -vvv. Once you have an error, attempt to troubleshoot the cause.    

Popular posts from this blog

Shrink you container size up to 95%.

alma linux: dnf Module yaml error: Unexpected key in data