Uploaded image for project: 'MongoDB ETL Tools'
  1. MongoDB ETL Tools
  2. TOOLS-2346

mongodump --archive to stdout corrupts archive when prompting for password

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 4.0.11
    • Fix Version/s: 4.3 Desired
    • Component/s: mongodump
    • Labels:
      None

      Description

      mongodump will corrupt the archive if you allow it to prompt for a password for the user doing the backup and you are archiving to stdout. It seems to insert an extraneous \n at the beginning of the archive and mongorestore cannot read it.

      This only happens when using --archive to stdout, specifying a file works, and specifying a password on the commandline via --password instead of entering one when prompted also works.

      You can reproduce using the official 4.0.11 mongodb docker image:

       

       

      # Run image and create a user to perform backups
      $ docker run -d --name mongo mongo:4.0.11-xenial
      $ docker exec mongo --eval 'db.getSiblingDB("admin").createUser({user: "backup", pwd: "password", roles: [{role: "root", db: "admin"}]})'
       
      # Backup to stdout while prompting for password, creates corrupt archive
       
      $ docker exec -it mongo bash -c 'mongodump --username backup --authenticationDatabase admin --archive > /tmp/dump'
      Enter password:
      2019-08-05T14:49:58.472+0000 writing admin.system.users to archive on stdout
      2019-08-05T14:49:58.489+0000 done dumping admin.system.users (1 document)
      2019-08-05T14:49:58.489+0000 writing admin.system.version to archive on stdout
      2019-08-05T14:49:58.505+0000 done dumping admin.system.version (2 documents)
      $ docker exec -it mongo mongorestore --username backup --password password --authenticationDatabase admin --drop --archive=/tmp/dump
      2019-08-05T14:47:47.702+0000 Failed: stream or file does not appear to be a mongodump archive
       
      # Backup to specified archive file, works
       
      $ docker exec -it mongo bash -c 'mongodump --username backup --authenticationDatabase admin --archive=/tmp/dump'
      Enter password:
      2019-08-05T14:49:04.249+0000 writing admin.system.users to archive '/tmp/dump'
      2019-08-05T14:49:04.268+0000 done dumping admin.system.users (1 document)
      2019-08-05T14:49:04.268+0000 writing admin.system.version to archive '/tmp/dump'
      2019-08-05T14:49:04.284+0000 done dumping admin.system.version (2 documents)
      $ docker exec -it mongo mongorestore --username backup --password password --authenticationDatabase admin --drop --archive=/tmp/dump
      2019-08-05T14:49:12.522+0000 preparing collections to restore from
      2019-08-05T14:49:12.549+0000 restoring users from archive '/tmp/dump'
      2019-08-05T14:49:12.623+0000 done
      # Backup to stdout specifying password on cmdline, works
       
      $ docker exec -it mongo bash -c 'mongodump --username backup --authenticationDatabase admin --password password --archive > /tmp/dump'
       
      2019-08-05T14:50:36.180+0000 writing admin.system.users to archive on stdout
      2019-08-05T14:50:36.198+0000 done dumping admin.system.users (1 document)
      2019-08-05T14:50:36.198+0000 writing admin.system.version to archive on stdout
      2019-08-05T14:50:36.213+0000 done dumping admin.system.version (2 documents)
      $ docker exec -it mongo mongorestore --username backup --password password --authenticationDatabase admin --drop --archive=/tmp/dump
      2019-08-05T14:50:45.845+0000 preparing collections to restore from
      2019-08-05T14:50:45.867+0000 restoring users from archive '/tmp/dump'
      2019-08-05T14:50:45.939+0000 done
      

       

        Attachments

          Activity

            People

            • Assignee:
              tim.fogarty Tim Fogarty
              Reporter:
              rectalogic Andrew Wason
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: