linux - can not restore table which was dropped using mongorestore -


i test mongorestore utility

the following test procedure:

mongo 127.0.0.1/mytest -u alex -p alex > db.createcollection("test1") { "ok" : 1 } > db.test1.insert({id:1,name:"alex"}) > db.test1.find() { "_id" : objectid("519b3d7808b450e533c8ea5e"), "id" : 1, "name" : "alex" } > show collections; system.indexes system.users test1 testtable > exit  ps -ef|grep mongod root      3201  3180  0 16:46 pts/1    00:00:00 vi /etc/mongod.conf root      3583     1  0 17:27 ?        00:00:00 /opt/mongodb/bin/mongod -f /etc/mongod.conf root      3600  3267  0 17:28 pts/3    00:00:00 grep mongod  kill -9 3583 

do file backup using mongodump

/opt/mongodb/bin/mongodump --dbpath /data/db/ --journal --out /data/dump tue may 21 17:26:38.107 [tools] journal dir=/data/db/journal tue may 21 17:26:38.107 [tools] recover begin tue may 21 17:26:38.107 [tools] recover lsn: 33813 tue may 21 17:26:38.107 [tools] recover /data/db/journal/j._0 tue may 21 17:26:38.126 [tools] recover skipping application of section seq:0 < lsn:33813 tue may 21 17:26:38.129 [tools] recover cleaning tue may 21 17:26:38.129 [tools] removejournalfiles tue may 21 17:26:38.130 [tools] recover done tue may 21 17:26:38.204 [tools] dbs tue may 21 17:26:38.205 [tools] database: mytest             /data/dump/mytest tue may 21 17:26:38.206 [tools]         mytest.system.indexes /data/dump/mytest/system.indexes.bson tue may 21 17:26:38.207 [tools]                  4 objects tue may 21 17:26:38.207 [tools]         mytest.system.users /data/dump/mytest/system.users.bson tue may 21 17:26:38.207 [tools]                  1 objects tue may 21 17:26:38.207 [tools]         metadata mytest.system.users /data/dump/mytest/system.users.metadata.json tue may 21 17:26:38.207 [tools]         mytest.testtable /data/dump/mytest/testtable.bson tue may 21 17:26:38.208 [tools]                  3 objects tue may 21 17:26:38.208 [tools]         metadata mytest.testtable /data/dump/mytest/testtable.metadata.json tue may 21 17:26:38.208 [tools]         mytest.test1 /data/dump/mytest/test1.bson tue may 21 17:26:38.208 [tools]                  1 objects tue may 21 17:26:38.208 [tools]         metadata mytest.test1 /data/dump/mytest/test1.metadata.json tue may 21 17:26:38.208 dbexit: tue may 21 17:26:38.209 [tools] shutdown: going close listening sockets... tue may 21 17:26:38.209 [tools] shutdown: going flush diaglog... tue may 21 17:26:38.209 [tools] shutdown: going close sockets... tue may 21 17:26:38.209 [tools] shutdown: waiting fs preallocator... tue may 21 17:26:38.209 [tools] shutdown: lock final commit... tue may 21 17:26:38.209 [tools] shutdown: final commit... tue may 21 17:26:38.209 [tools] shutdown: closing files... tue may 21 17:26:38.210 [tools] closeallfiles() finished tue may 21 17:26:38.210 [tools] journalcleanup... tue may 21 17:26:38.210 [tools] removejournalfiles tue may 21 17:26:38.211 [tools] shutdown: removing fs lock... tue may 21 17:26:38.211 dbexit: exiting 

start mongod

# /opt/mongodb/bin/mongod -f /etc/mongod.conf 

drop table test1

# mongo 127.0.0.1/mytest -u alex -p alex > show collections; system.indexes system.users test1 testtable > db.test1.drop() true > show collections; system.indexes system.users testtable > exit bye 

shutdown mongod

# ps -ef|grep mongod root      3201  3180  0 16:46 pts/1    00:00:00 vi /etc/mongod.conf root      3544     1  0 17:24 ?        00:00:00 /opt/mongodb/bin/mongod -f /etc/mongod.conf root      3556  3267  0 17:24 pts/3    00:00:00 grep mongod # kill -9 3544 

try restore test1 backup

# mongorestore --dbpath /data/db --directoryperdb --journal /data/dump/ tue may 21 17:29:57.518 [tools] journal dir=/data/db/journal tue may 21 17:29:57.518 [tools] recover begin tue may 21 17:29:57.519 [tools] info no lsn file in journal/ directory tue may 21 17:29:57.519 [tools] recover lsn: 0 tue may 21 17:29:57.519 [tools] recover /data/db/journal/j._0 tue may 21 17:29:57.554 [tools] recover cleaning tue may 21 17:29:57.554 [tools] removejournalfiles tue may 21 17:29:57.555 [tools] recover done tue may 21 17:29:57.629 [tools] /data/dump/mytest/test1.bson tue may 21 17:29:57.630 [tools]         going namespace [mytest.test1] tue may 21 17:29:57.631 [tools] warning: restoring mytest.test1 without dropping. restored data inserted without raising errors; check server log 1 objects found tue may 21 17:29:57.632 [tools]         creating index: { key: { _id: 1 }, ns: "mytest.test1", name: "_id_" } tue may 21 17:29:57.633 [tools] /data/dump/mytest/system.users.bson tue may 21 17:29:57.633 [tools]         going namespace [mytest.system.users] tue may 21 17:29:57.633 [tools] warning: restoring mytest.system.users without dropping. restored data inserted without raising errors; check server log 1 objects found tue may 21 17:29:57.634 [tools]         creating index: { key: { _id: 1 }, ns: "mytest.system.users", name: "_id_" } tue may 21 17:29:57.634 [tools]         creating index: { key: { user: 1, usersource: 1 }, unique: true, ns: "mytest.system.users", name: "user_1_usersource_1" } tue may 21 17:29:57.634 [tools] /data/dump/mytest/testtable.bson tue may 21 17:29:57.634 [tools]         going namespace [mytest.testtable] tue may 21 17:29:57.634 [tools] warning: restoring mytest.testtable without dropping. restored data inserted without raising errors; check server log 3 objects found tue may 21 17:29:57.635 [tools]         creating index: { key: { _id: 1 }, ns: "mytest.testtable", name: "_id_" } tue may 21 17:29:57.635 dbexit: tue may 21 17:29:57.636 [tools] shutdown: going close listening sockets... tue may 21 17:29:57.636 [tools] shutdown: going flush diaglog... tue may 21 17:29:57.636 [tools] shutdown: going close sockets... tue may 21 17:29:57.636 [tools] shutdown: waiting fs preallocator... tue may 21 17:29:57.636 [tools] shutdown: lock final commit... tue may 21 17:29:57.636 [tools] shutdown: final commit... tue may 21 17:29:57.649 [tools] shutdown: closing files... tue may 21 17:29:57.649 [tools] closeallfiles() finished tue may 21 17:29:57.649 [tools] journalcleanup... tue may 21 17:29:57.649 [tools] removejournalfiles tue may 21 17:29:57.650 [tools] shutdown: removing fs lock... tue may 21 17:29:57.650 dbexit: exiting 

and find no test1 in mytest database

# mongo 127.0.0.1/mytest -u alex -p alex\ > show collections; system.indexes system.users testtable 

as use mongorestore --directoryperdb option, every database's files saved in discrete directories on disk.

for case, namespace of collection test1 mytest.test1. when restored dump --directoryperdb option, collection test1 restored directory /data/db/mytest, rather /data/db.

you couldn't find test1 collection if start mongod --dbpath /data/db because collection dropped dbpath. find test1 collection restored, should start mongod --dbpath /data/db/mytest.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -