Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-1951

verify backup metadata before dropping tables during restore

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.4.1, 3.7.1, 3.4.13
    • Component/s: mongorestore
    • Labels:
      None
    • Environment:
      Ubuntu x86_64 xenial

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            DaveFF David Knoll
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: