Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-2119

Fix mongodump --dbpath example

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 01112017-cleanup
    • None
    • manual
    • None

    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.

      Attachments

        Activity

          People

            sam.kleinman Sam Kleinman (Inactive)
            gianfranco Gianfranco Palumbo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 16 weeks, 1 day ago