[DOCS-2119] Fix mongodump --dbpath example Created: 20/Oct/13  Updated: 11/Jan/17  Resolved: 30/Oct/13

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Gianfranco Palumbo Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to DOCS-442 Add example to of using mongodump / m... Closed
Participants:
Days since reply: 10 years, 16 weeks, 1 day ago

 Description   

http://docs.mongodb.org/manual/tutorial/backup-databases-with-binary-database-dumps/#backup-restore-dbpath

The following example in "Restore Without a Running mongod" is not accurate.

The example says:

Given a set of backed up databases in the dataout directory:

  • dataout/customers,
  • dataout/products, and
  • dataout/suppliers

The following mongorestore command restores the products database. The command uses the --dbpath option to specify which database to restore:

mongorestore --host localhost --port 27107 --dbpath /dataout/products --journal

The mongorestore imports the database backup in the /dataout/products directory to the mongod instance that runs on the localhost interface. The mongorestore operation imports the backup even if the mongod is not running.

When you run mongorestore with --dbpath you're saying to mongorestore to write/restore any data from a previous mongodump into those bson files (in dbpath).

In fact --dbpath is usually the mongod's --dbpath (while it's not running).

Therefore the example command would be, similar to what it as it was before:

mongorestore --dbpath /srv/mongodb --journal dataout

or use the folder name dump to be more explicit.

See this example:

$ mongo --norc
MongoDB shell version: 2.4.6
connecting to: test
> db.test.find()
>

Stop the mongod which dbpath is in /data/db.
And restore a previous mongodump

$ find .
./dataout
./dataout/test
./dataout/test/system.indexes.bson
./dataout/test/test.bson
./dataout/test/test.metadata.json
 
$ mongorestore --dbpath /data/db --journal dataout
Sun Oct 20 20:13:57.475 [tools] journal dir=/data/db/journal
Sun Oct 20 20:13:57.475 [tools] recover : no journal files present, no recovery needed
Sun Oct 20 20:13:57.484 [tools] dataout/test/test.bson
Sun Oct 20 20:13:57.484 [tools] 	going into namespace [test.test]
Sun Oct 20 20:13:57.488 [tools] build index test.test { _id: 1 }
Sun Oct 20 20:13:57.490 [tools] build index done.  scanned 0 total records. 0.001 secs
4 objects found
Sun Oct 20 20:13:57.491 [tools] 	Creating index: { key: { _id: 1 }, ns: "test.test", name: "_id_" }
Sun Oct 20 20:13:57.491 dbexit:
Sun Oct 20 20:13:57.491 [tools] shutdown: going to close listening sockets...
Sun Oct 20 20:13:57.491 [tools] shutdown: going to flush diaglog...
Sun Oct 20 20:13:57.491 [tools] shutdown: going to close sockets...
Sun Oct 20 20:13:57.491 [tools] shutdown: waiting for fs preallocator...
Sun Oct 20 20:13:57.491 [tools] shutdown: lock for final commit...
Sun Oct 20 20:13:57.491 [tools] shutdown: final commit...
Sun Oct 20 20:13:57.494 [tools] shutdown: closing all files...
Sun Oct 20 20:13:57.494 [tools] closeAllFiles() finished
Sun Oct 20 20:13:57.494 [tools] journalCleanup...
Sun Oct 20 20:13:57.494 [tools] removeJournalFiles
Sun Oct 20 20:13:57.494 [tools] shutdown: removing fs lock...
Sun Oct 20 20:13:57.494 dbexit: really exiting now

Restart the mongod process and verify the data has been restored.

$ mongo --norc
MongoDB shell version: 2.4.6
connecting to: test
> db.test.find()
{ "_id" : ObjectId("526424772134310b5723dad0") }
{ "_id" : ObjectId("526424792134310b5723dad1"), "a" : 1 }
{ "_id" : ObjectId("5264247b2134310b5723dad2"), "a" : 2 }
{ "_id" : ObjectId("5264247d2134310b5723dad3"), "a" : 3 }

Note: if you don't shutdown the mongod process and you run the mongorestore --dbpath you'll get:

If you are running a mongod on the same path you should connect to that instead of direct data file access

Note2: if you restore a database that already exists in the dbpath (extent files exist with the same name), you'll get a warning:

warning: Restoring to test.test without dropping. Restored data will be inserted without raising errors; check your server log

This shouldn't create duplicate records.



 Comments   
Comment by auto [ 30/Oct/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-2119: fix for mongorestore example
Branch: master
https://github.com/mongodb/docs/commit/0da270c2ef09c0183bccdf00fb64d033e2dfa1ef

Comment by auto [ 30/Oct/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-2119: fix for mongorestore example
Branch: v2.4
https://github.com/mongodb/docs/commit/792c5f607cc2cabf705754bb2ad7c303a0587128

Generated at Thu Feb 08 07:42:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.