-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 3.4.1, 3.7.1, 3.4.13
-
Component/s: mongorestore
-
None
-
Environment:Ubuntu x86_64 xenial
-
1
-
2,043
mongorestore --drop with bad metadata file, drops but does not restore
Steps to reproduce:
- In mongo shell, create a test db
# mongo testdb > for (i = 0; i < 1000; i++) db.testcoll.insertOne({ num: i, hello: 'world' });
- Observe document count
> db.testcoll.count(); 1000
- Exit the shell and backup that db with mongodump
# mongodump -v --db testdb --out=.
- Deliberately b0rk the metadata file
# echo "foo" > testdb/testcoll.metadata.json
- Attempt to restore that backup
# mongorestore --drop -v --db testdb ./testdb/testcoll.bson
- Observe that it "drops before restoring" then fails to read the metadata and aborts
dropping collection testdb.testcoll before restoring Failed: testdb.testcoll: error parsing metadata from testdb/testcoll.metadata.json: invalid character 'o' in literal false (expecting 'a')
- Observe that the collection has been dropped but not restored
# mongo testdb > db.testcoll.count(); 0
Basically I screwed up part of a script that takes regular backups on one server and restores selected collections on another server. I had copied the BSON over the metadata. I later found out that mongorestore had gone ahead and dropped the collections in preparation, despite being unable to restore them.
Confirmed on the version running on our servers (3.4.1), my laptop (3.4.13) and the latest nightly.