Help restoring a mongodump 3.4 backup into a different instance





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I am working on backup recovery for MongoDB 3.4. We have an instance that is running and being used. I set up a instance for doing testing of the backup and recovery process. In order to get data I did mongodump for each database and copied the files to my test server. Each backup write files to a directory that has the same name as the database. I used the gzip option to make it easier to move the files around. I am having issues trying to do the mongorestore. Can someone give me the syntax for mongorestore?



Here is the dump command



mongodump --port 27017 --authenticationDatabase admin -u my_admin_user
-p password -o /backup_dir --gzip -d test_db


(split to multiple lines for readability)



These are the directories with the contents of my_test_db



root@my_vm:~/mongodb_backup_full_data_dump > ls -l
total 20
drwxr-xr-x. 2 root root 4096 Aug 24 13:30 admin
drwxr-xr-x. 2 root root 4096 Aug 24 13:51 data1
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data2
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data3
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 my_test_db
root@my_vm:~/mongodb_backup_full_data_dump > ls -l ./my_test_db/*
-rw-r--r--. 1 root root 24263 Aug 24 14:20 ./my_test_db/journal_entries.bson.gz
-rw-r--r--. 1 root root 132 Aug 24 14:20 ./my_test_db/journal_entries.metadata.json.gz
-rw-r--r--. 1 root root 481 Aug 24 14:20 ./my_test_db/journal_users.bson.gz
-rw-r--r--. 1 root root 107 Aug 24 14:20 ./my_test_db/journal_users.metadata.json.gz
-rw-r--r--. 1 root root 14438174 Aug 24 14:20 ./my_test_db/test_collection.bson.gz
-rw-r--r--. 1 root root 104 Aug 24 14:20 ./my_test_db/test_collection.metadata.json.gz


and, this is what happens when I try to do the restore:



mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password -o /backup_dir 
--gzip -d test_db /root/mongodb_backup_full_data_dump/test_db/journal_entries.bson.gz



2017-08-25T15:24:05.487-0400 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2017-08-25T15:24:05.487-0400 checking for collection data in /root/mongodb_backup_full_data_dump/mediax
2017-08-25T15:24:05.487-0400 Failed: error scanning filesystem: file /root/mongodb_backup_full_data_dump/mediax is a directory, not a bson file









share|improve this question
















bumped to the homepage by Community 2 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/…

    – SqlWorldWide
    Aug 25 '17 at 18:05











  • I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing.

    – Gandolf989
    Aug 25 '17 at 18:44











  • mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files?

    – SqlWorldWide
    Aug 25 '17 at 18:55











  • I tried using the directory only, the error is above.

    – Gandolf989
    Aug 25 '17 at 19:26


















2















I am working on backup recovery for MongoDB 3.4. We have an instance that is running and being used. I set up a instance for doing testing of the backup and recovery process. In order to get data I did mongodump for each database and copied the files to my test server. Each backup write files to a directory that has the same name as the database. I used the gzip option to make it easier to move the files around. I am having issues trying to do the mongorestore. Can someone give me the syntax for mongorestore?



Here is the dump command



mongodump --port 27017 --authenticationDatabase admin -u my_admin_user
-p password -o /backup_dir --gzip -d test_db


(split to multiple lines for readability)



These are the directories with the contents of my_test_db



root@my_vm:~/mongodb_backup_full_data_dump > ls -l
total 20
drwxr-xr-x. 2 root root 4096 Aug 24 13:30 admin
drwxr-xr-x. 2 root root 4096 Aug 24 13:51 data1
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data2
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data3
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 my_test_db
root@my_vm:~/mongodb_backup_full_data_dump > ls -l ./my_test_db/*
-rw-r--r--. 1 root root 24263 Aug 24 14:20 ./my_test_db/journal_entries.bson.gz
-rw-r--r--. 1 root root 132 Aug 24 14:20 ./my_test_db/journal_entries.metadata.json.gz
-rw-r--r--. 1 root root 481 Aug 24 14:20 ./my_test_db/journal_users.bson.gz
-rw-r--r--. 1 root root 107 Aug 24 14:20 ./my_test_db/journal_users.metadata.json.gz
-rw-r--r--. 1 root root 14438174 Aug 24 14:20 ./my_test_db/test_collection.bson.gz
-rw-r--r--. 1 root root 104 Aug 24 14:20 ./my_test_db/test_collection.metadata.json.gz


and, this is what happens when I try to do the restore:



mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password -o /backup_dir 
--gzip -d test_db /root/mongodb_backup_full_data_dump/test_db/journal_entries.bson.gz



2017-08-25T15:24:05.487-0400 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2017-08-25T15:24:05.487-0400 checking for collection data in /root/mongodb_backup_full_data_dump/mediax
2017-08-25T15:24:05.487-0400 Failed: error scanning filesystem: file /root/mongodb_backup_full_data_dump/mediax is a directory, not a bson file









share|improve this question
















bumped to the homepage by Community 2 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/…

    – SqlWorldWide
    Aug 25 '17 at 18:05











  • I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing.

    – Gandolf989
    Aug 25 '17 at 18:44











  • mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files?

    – SqlWorldWide
    Aug 25 '17 at 18:55











  • I tried using the directory only, the error is above.

    – Gandolf989
    Aug 25 '17 at 19:26














2












2








2


1






I am working on backup recovery for MongoDB 3.4. We have an instance that is running and being used. I set up a instance for doing testing of the backup and recovery process. In order to get data I did mongodump for each database and copied the files to my test server. Each backup write files to a directory that has the same name as the database. I used the gzip option to make it easier to move the files around. I am having issues trying to do the mongorestore. Can someone give me the syntax for mongorestore?



Here is the dump command



mongodump --port 27017 --authenticationDatabase admin -u my_admin_user
-p password -o /backup_dir --gzip -d test_db


(split to multiple lines for readability)



These are the directories with the contents of my_test_db



root@my_vm:~/mongodb_backup_full_data_dump > ls -l
total 20
drwxr-xr-x. 2 root root 4096 Aug 24 13:30 admin
drwxr-xr-x. 2 root root 4096 Aug 24 13:51 data1
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data2
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data3
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 my_test_db
root@my_vm:~/mongodb_backup_full_data_dump > ls -l ./my_test_db/*
-rw-r--r--. 1 root root 24263 Aug 24 14:20 ./my_test_db/journal_entries.bson.gz
-rw-r--r--. 1 root root 132 Aug 24 14:20 ./my_test_db/journal_entries.metadata.json.gz
-rw-r--r--. 1 root root 481 Aug 24 14:20 ./my_test_db/journal_users.bson.gz
-rw-r--r--. 1 root root 107 Aug 24 14:20 ./my_test_db/journal_users.metadata.json.gz
-rw-r--r--. 1 root root 14438174 Aug 24 14:20 ./my_test_db/test_collection.bson.gz
-rw-r--r--. 1 root root 104 Aug 24 14:20 ./my_test_db/test_collection.metadata.json.gz


and, this is what happens when I try to do the restore:



mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password -o /backup_dir 
--gzip -d test_db /root/mongodb_backup_full_data_dump/test_db/journal_entries.bson.gz



2017-08-25T15:24:05.487-0400 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2017-08-25T15:24:05.487-0400 checking for collection data in /root/mongodb_backup_full_data_dump/mediax
2017-08-25T15:24:05.487-0400 Failed: error scanning filesystem: file /root/mongodb_backup_full_data_dump/mediax is a directory, not a bson file









share|improve this question
















I am working on backup recovery for MongoDB 3.4. We have an instance that is running and being used. I set up a instance for doing testing of the backup and recovery process. In order to get data I did mongodump for each database and copied the files to my test server. Each backup write files to a directory that has the same name as the database. I used the gzip option to make it easier to move the files around. I am having issues trying to do the mongorestore. Can someone give me the syntax for mongorestore?



Here is the dump command



mongodump --port 27017 --authenticationDatabase admin -u my_admin_user
-p password -o /backup_dir --gzip -d test_db


(split to multiple lines for readability)



These are the directories with the contents of my_test_db



root@my_vm:~/mongodb_backup_full_data_dump > ls -l
total 20
drwxr-xr-x. 2 root root 4096 Aug 24 13:30 admin
drwxr-xr-x. 2 root root 4096 Aug 24 13:51 data1
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data2
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 data3
drwxr-xr-x. 2 root root 4096 Aug 24 14:20 my_test_db
root@my_vm:~/mongodb_backup_full_data_dump > ls -l ./my_test_db/*
-rw-r--r--. 1 root root 24263 Aug 24 14:20 ./my_test_db/journal_entries.bson.gz
-rw-r--r--. 1 root root 132 Aug 24 14:20 ./my_test_db/journal_entries.metadata.json.gz
-rw-r--r--. 1 root root 481 Aug 24 14:20 ./my_test_db/journal_users.bson.gz
-rw-r--r--. 1 root root 107 Aug 24 14:20 ./my_test_db/journal_users.metadata.json.gz
-rw-r--r--. 1 root root 14438174 Aug 24 14:20 ./my_test_db/test_collection.bson.gz
-rw-r--r--. 1 root root 104 Aug 24 14:20 ./my_test_db/test_collection.metadata.json.gz


and, this is what happens when I try to do the restore:



mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password -o /backup_dir 
--gzip -d test_db /root/mongodb_backup_full_data_dump/test_db/journal_entries.bson.gz



2017-08-25T15:24:05.487-0400 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2017-08-25T15:24:05.487-0400 checking for collection data in /root/mongodb_backup_full_data_dump/mediax
2017-08-25T15:24:05.487-0400 Failed: error scanning filesystem: file /root/mongodb_backup_full_data_dump/mediax is a directory, not a bson file






mongodb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 20 '18 at 20:02









RDFozz

9,88731531




9,88731531










asked Aug 25 '17 at 15:36









Gandolf989Gandolf989

1,236512




1,236512





bumped to the homepage by Community 2 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 2 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/…

    – SqlWorldWide
    Aug 25 '17 at 18:05











  • I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing.

    – Gandolf989
    Aug 25 '17 at 18:44











  • mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files?

    – SqlWorldWide
    Aug 25 '17 at 18:55











  • I tried using the directory only, the error is above.

    – Gandolf989
    Aug 25 '17 at 19:26



















  • Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/…

    – SqlWorldWide
    Aug 25 '17 at 18:05











  • I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing.

    – Gandolf989
    Aug 25 '17 at 18:44











  • mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files?

    – SqlWorldWide
    Aug 25 '17 at 18:55











  • I tried using the directory only, the error is above.

    – Gandolf989
    Aug 25 '17 at 19:26

















Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/…

– SqlWorldWide
Aug 25 '17 at 18:05





Can you post what you tried and what error are you getting. There are examples here: docs.mongodb.com/manual/reference/program/mongorestore/…

– SqlWorldWide
Aug 25 '17 at 18:05













I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing.

– Gandolf989
Aug 25 '17 at 18:44





I was able to get a restore command working by specifying each bson file. One of the directories has a few dozen bson files and I am currently running the import for those. I am getting duplicate key error collection messages. I'm not sure why. I was hoping that I could run one command and get every file in the directory at once. I am still not sure that I am doing the right thing.

– Gandolf989
Aug 25 '17 at 18:44













mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files?

– SqlWorldWide
Aug 25 '17 at 18:55





mongorestore --host mongodb1.example.net --port 37017 --username user --password "pass" /opt/backup/mongodump-2011-10-24 with --gzip should work. Did you try with '--collection` switch at least for the collection where you have many files?

– SqlWorldWide
Aug 25 '17 at 18:55













I tried using the directory only, the error is above.

– Gandolf989
Aug 25 '17 at 19:26





I tried using the directory only, the error is above.

– Gandolf989
Aug 25 '17 at 19:26










2 Answers
2






active

oldest

votes


















0














Answer is



mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password --gzip /root/mongodb_backup_full_data_dump/


So, you just tell the directory (basedir) where "all" backups are. mongorestore will "restore" those files (in those sub-directories) to databases (come from directory name).



SO, if you change that "test_db" directory name (mv test_db other_test_db) to "other_test_db", it will restore those files to "other_test_db"






share|improve this answer

































    0














    Start a mongod instance for a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option.



    mongod --dbpath /data/db --replSet <replName>


    Connect a mongo shell to the mongod instance



    mongo


    Initiate the new replica set.



    rs.initiate()


    MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.



    For detailed information Please Click Here






    share|improve this answer
























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "182"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f184365%2fhelp-restoring-a-mongodump-3-4-backup-into-a-different-instance%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Answer is



      mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password --gzip /root/mongodb_backup_full_data_dump/


      So, you just tell the directory (basedir) where "all" backups are. mongorestore will "restore" those files (in those sub-directories) to databases (come from directory name).



      SO, if you change that "test_db" directory name (mv test_db other_test_db) to "other_test_db", it will restore those files to "other_test_db"






      share|improve this answer






























        0














        Answer is



        mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password --gzip /root/mongodb_backup_full_data_dump/


        So, you just tell the directory (basedir) where "all" backups are. mongorestore will "restore" those files (in those sub-directories) to databases (come from directory name).



        SO, if you change that "test_db" directory name (mv test_db other_test_db) to "other_test_db", it will restore those files to "other_test_db"






        share|improve this answer




























          0












          0








          0







          Answer is



          mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password --gzip /root/mongodb_backup_full_data_dump/


          So, you just tell the directory (basedir) where "all" backups are. mongorestore will "restore" those files (in those sub-directories) to databases (come from directory name).



          SO, if you change that "test_db" directory name (mv test_db other_test_db) to "other_test_db", it will restore those files to "other_test_db"






          share|improve this answer















          Answer is



          mongorestore --port 27017 --authenticationDatabase admin -u my_admin_user -p password --gzip /root/mongodb_backup_full_data_dump/


          So, you just tell the directory (basedir) where "all" backups are. mongorestore will "restore" those files (in those sub-directories) to databases (come from directory name).



          SO, if you change that "test_db" directory name (mv test_db other_test_db) to "other_test_db", it will restore those files to "other_test_db"







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 11 '18 at 5:01









          Md Haidar Ali Khan

          3,83772442




          3,83772442










          answered Aug 26 '17 at 8:14









          JJussiJJussi

          3,1691515




          3,1691515

























              0














              Start a mongod instance for a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option.



              mongod --dbpath /data/db --replSet <replName>


              Connect a mongo shell to the mongod instance



              mongo


              Initiate the new replica set.



              rs.initiate()


              MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.



              For detailed information Please Click Here






              share|improve this answer




























                0














                Start a mongod instance for a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option.



                mongod --dbpath /data/db --replSet <replName>


                Connect a mongo shell to the mongod instance



                mongo


                Initiate the new replica set.



                rs.initiate()


                MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.



                For detailed information Please Click Here






                share|improve this answer


























                  0












                  0








                  0







                  Start a mongod instance for a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option.



                  mongod --dbpath /data/db --replSet <replName>


                  Connect a mongo shell to the mongod instance



                  mongo


                  Initiate the new replica set.



                  rs.initiate()


                  MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.



                  For detailed information Please Click Here






                  share|improve this answer













                  Start a mongod instance for a new single-node replica set. Specify the path to the backup data files with --dbpath option and the replica set name with the --replSet option. For config server replica set (CSRS), include the --configsvr option.



                  mongod --dbpath /data/db --replSet <replName>


                  Connect a mongo shell to the mongod instance



                  mongo


                  Initiate the new replica set.



                  rs.initiate()


                  MongoDB initiates a set that consists of the current member and that uses the default replica set configuration.



                  For detailed information Please Click Here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 20 '18 at 19:17







                  user160682





































                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Database Administrators Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f184365%2fhelp-restoring-a-mongodump-3-4-backup-into-a-different-instance%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      SQL Server 17 - Attemping to backup to remote NAS but Access is denied

                      Always On Availability groups resolving state after failover - Remote harden of transaction...

                      Restoring from pg_dump with foreign key constraints