How do I create a MongoDB dump of my database?












113















What command do I use and run?










share|improve this question

























  • Just a single mongodump without any flags and you get dump folder

    – Ivan Aracki
    Jun 26 '18 at 14:56


















113















What command do I use and run?










share|improve this question

























  • Just a single mongodump without any flags and you get dump folder

    – Ivan Aracki
    Jun 26 '18 at 14:56
















113












113








113


33






What command do I use and run?










share|improve this question
















What command do I use and run?







mongodb database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 22 '17 at 17:57









Community

11




11










asked Feb 2 '11 at 22:52









TIMEXTIMEX

69.4k274648955




69.4k274648955













  • Just a single mongodump without any flags and you get dump folder

    – Ivan Aracki
    Jun 26 '18 at 14:56





















  • Just a single mongodump without any flags and you get dump folder

    – Ivan Aracki
    Jun 26 '18 at 14:56



















Just a single mongodump without any flags and you get dump folder

– Ivan Aracki
Jun 26 '18 at 14:56







Just a single mongodump without any flags and you get dump folder

– Ivan Aracki
Jun 26 '18 at 14:56














15 Answers
15






active

oldest

votes


















66














Use mongodump:



$ ./mongodump --host prod.example.com
connected to: prod.example.com
all dbs
DATABASE: log to dump/log
log.errors to dump/log/errors.bson
713 objects
log.analytics to dump/log/analytics.bson
234810 objects
DATABASE: blog to dump/blog
blog.posts to dump/log/blog.posts.bson
59 objects
DATABASE: admin to dump/admin


Source: http://www.mongodb.org/display/DOCS/Import+Export+Tools






share|improve this answer



















  • 3





    To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

    – Donal Lafferty
    Aug 27 '15 at 8:52











  • At mongodb server at which place the database will be stored?

    – space earth
    Jun 15 '17 at 10:09



















103














To dump your database for backup you call this command on your terminal



mongodump --db database_name --collection collection_name


To import your backup file to mongodb you can use the following command on your terminal



mongorestore --db database_name path_to_bson_file





share|improve this answer


























  • What is the significance of metadata.json for restoring?

    – Nabin
    May 8 '18 at 14:21



















61














You can also use gzip for taking backup of one collection and compressing the backup on the fly:



mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz


or with a date in the file name:



mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz


Update:

Backup all collections of a database in a date folder. The files are gziped:



mongodump --db somedb --gzip --out /backups/`date +"%Y-%m-%d"`


Or for a single archive:



mongodump --db somedb --gzip --archive > dump_`date "+%Y-%m-%d"`.gz


Or when mongodb is running inside docker:



docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz





share|improve this answer


























  • This looks very nice, but how do you import this gzip file ?

    – fahim ayat
    Jul 14 '14 at 10:30











  • You need to 'gunzip' them, and then use mongorestore

    – Meny Issakov
    Aug 6 '14 at 10:22






  • 1





    says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

    – amitchhajer
    Jun 10 '15 at 6:54






  • 2





    typo : "-db" => "--db"

    – Vivien
    Oct 1 '15 at 8:33






  • 7





    In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

    – Boop
    May 30 '16 at 13:48





















50














This command will make a dump of given database in json and bson format.



mongodump -d <database name> -o <target directory>





share|improve this answer
























  • Only this worked for me

    – Jamie Hutber
    Nov 30 '16 at 0:27



















12














There is a utility called : mongodump
On the mongo command line you can type :



>./mongodump


The above will create a dump of all the databases on your localhost. To make dump of a single collection use:



./mongodump --db blog --collection posts


Have a look at : mongodump






share|improve this answer































    11














    You need to open command prompt as an administrator in a folder where your Mongo is installed (in my case: C:Program FilesMongoDBServer3.4bin).
    If you want to dump your whole database, you can just use:



    mongodump --db database_name


    You also have posibilities to dump only certain collection(s), or to dump all but certain collection(s).



    If you want to dump only one collection (for example users):



    mongodump  --db database_name --collection users


    If you want to dump all but users collection:



    mongodump  --db database_name --excludeCollection=users


    It is also possible to output the dump to an archive file:



    mongodump --archive=test.archive --db database_name





    share|improve this answer

































      7














      Following command connect to the remote server to dump a database:



      <> optional params use them if you need them




      • host - host name port

      • listening port username

      • username of db db

      • db name ssl

      • secure connection out


      • output to a created folder with a name



        mongodump --host --port --username --db --ssl --password --out _date+"%Y-%m-%d"








      share|improve this answer


























      • For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

        – Anurag_BEHS
        Jul 9 '18 at 19:44





















      6














      You can dump your database and restore with bellow command



      mongodb  -d <Your_db_name> -o <path of your folder>


      for example my database name is tracking i have dump in dump folder



      mongodb  -d tracking -o dump


      Restoring dump



      mongorestore -d <databasename> <dum_path>

      mongorestore -d tracking dump/tracking





      share|improve this answer

































        3














        cmd -->



        C:Program FilesMongoDBServer3.2bin>mongodump.exe --db Dintest






        share|improve this answer



















        • 1





          Easy and quickest option

          – Ignacio Ara
          Jul 30 '18 at 16:26













        • Thanks a lot Arnav, really appreciated.

          – HassanSh__3571619
          Feb 18 at 20:33



















        1














        Below command will work to take dump of mongo db .




        mongodump -d -o




        On Windows : try this one where c:mongodump is dump file location ,
        It will create metadata in json, and backup in bson format




        C:MongoDBbin>mongodump -d -o c:mongodump







        share|improve this answer































          1














          Backup/Restore Mongodb with timing.



          Backup:



          sudo mongodump --db db_name --out /path_of_your_backup/`date +"%m-%d-%y"`


          --db argument for databse name



          --out argument for path of output



          Restore:



          sudo mongorestore --db db_name --drop /path_of_your_backup/01-01-19/db_name/


          --drop argument for drop databse before restore



          Timing:



          You can use crontab for timing backup:



          sudo crontab -e


          It opens with editor(e.g. nano)



          3 3 * * * mongodump --out /path_of_your_backup/`date +"%m-%d-%y"`


          backup every day at 03:03 AM




          Depending on your MongoDB database sizes you may soon run out of disk
          space with too many backups. That's why it's also recommended to clean
          the old backups regularly or to compress them. For example, to delete
          all the backups older than 7 days you can use the following bash
          command:




          3 1 * * * find /path_of_your_backup/ -mtime +7 -exec rm -rf {} ;


          delete all the backups older than 7 days



          Good Luck.



          ref:
          https://www.digitalocean.com/community/tutorials/how-to-back-up-restore-and-migrate-a-mongodb-database-on-ubuntu-14-04






          share|improve this answer

































            0














            Or you can make backup script on Windows, remember to add Winrar to %PATH%



            binmongodump --db=COL1 -o D:BACKCOL1
            rar.exe a -ep1 -r COL1.rar COL1
            rename COL1.rar "COL1_%date:~10,4%_%date:~7,2%_%date:~4,2%_%time:~0,2%_%time:~3,2%.rar"

            #rmdir /s /q COL1 -> don;t run this on your mongodb/ dir !!!!!





            share|improve this answer

































              0














              Mongo dump and restore with uri to local



              mongodump --uri "mongodb://USERNAME:PASSWORD@IP_OR_URL:PORT/DB_NAME" --collection COLLECTION_NAME -o LOCAL_URL



              If you do not specify --colletion COLLECTION_NAME, it will dump entire DB.






              share|improve this answer

































                0














                take mongodb backup for particular db and delete 7 days old backup using bin sh command :-



                #!/bin/bash

                MONGO_DATABASE="nexgtv_16"
                APP_NAME="test"
                MONGO_HOST="127.0.0.1"
                MONGO_PORT="27017"
                TIMESTAMP=`date +%F-%H%M`
                MONGODUMP_PATH="/usr/bin/mongodump"
                BACKUPS_DIR="/home/mongodbbackups/backups/$APP_NAME"
                BACKUP_NAME="$APP_NAME-$TIMESTAMP"
                $MONGODUMP_PATH -d $MONGO_DATABASE
                mkdir -p $BACKUPS_DIR
                mv dump $BACKUP_NAME
                tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
                rm -rf $BACKUP_NAME
                find /home/mongodbbackups/backups/test/ -mindepth 1 -mtime +7 -delete





                share|improve this answer

































                  -4














                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder



                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder.gz






                  share|improve this answer


























                  • Please add an explanation around what these commands do.

                    – Steve
                    Mar 31 '17 at 5:51











                  • 1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                    – Anjankumar H N
                    Mar 31 '17 at 6:07













                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  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: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  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%2fstackoverflow.com%2fquestions%2f4880874%2fhow-do-i-create-a-mongodb-dump-of-my-database%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  15 Answers
                  15






                  active

                  oldest

                  votes








                  15 Answers
                  15






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  66














                  Use mongodump:



                  $ ./mongodump --host prod.example.com
                  connected to: prod.example.com
                  all dbs
                  DATABASE: log to dump/log
                  log.errors to dump/log/errors.bson
                  713 objects
                  log.analytics to dump/log/analytics.bson
                  234810 objects
                  DATABASE: blog to dump/blog
                  blog.posts to dump/log/blog.posts.bson
                  59 objects
                  DATABASE: admin to dump/admin


                  Source: http://www.mongodb.org/display/DOCS/Import+Export+Tools






                  share|improve this answer



















                  • 3





                    To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

                    – Donal Lafferty
                    Aug 27 '15 at 8:52











                  • At mongodb server at which place the database will be stored?

                    – space earth
                    Jun 15 '17 at 10:09
















                  66














                  Use mongodump:



                  $ ./mongodump --host prod.example.com
                  connected to: prod.example.com
                  all dbs
                  DATABASE: log to dump/log
                  log.errors to dump/log/errors.bson
                  713 objects
                  log.analytics to dump/log/analytics.bson
                  234810 objects
                  DATABASE: blog to dump/blog
                  blog.posts to dump/log/blog.posts.bson
                  59 objects
                  DATABASE: admin to dump/admin


                  Source: http://www.mongodb.org/display/DOCS/Import+Export+Tools






                  share|improve this answer



















                  • 3





                    To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

                    – Donal Lafferty
                    Aug 27 '15 at 8:52











                  • At mongodb server at which place the database will be stored?

                    – space earth
                    Jun 15 '17 at 10:09














                  66












                  66








                  66







                  Use mongodump:



                  $ ./mongodump --host prod.example.com
                  connected to: prod.example.com
                  all dbs
                  DATABASE: log to dump/log
                  log.errors to dump/log/errors.bson
                  713 objects
                  log.analytics to dump/log/analytics.bson
                  234810 objects
                  DATABASE: blog to dump/blog
                  blog.posts to dump/log/blog.posts.bson
                  59 objects
                  DATABASE: admin to dump/admin


                  Source: http://www.mongodb.org/display/DOCS/Import+Export+Tools






                  share|improve this answer













                  Use mongodump:



                  $ ./mongodump --host prod.example.com
                  connected to: prod.example.com
                  all dbs
                  DATABASE: log to dump/log
                  log.errors to dump/log/errors.bson
                  713 objects
                  log.analytics to dump/log/analytics.bson
                  234810 objects
                  DATABASE: blog to dump/blog
                  blog.posts to dump/log/blog.posts.bson
                  59 objects
                  DATABASE: admin to dump/admin


                  Source: http://www.mongodb.org/display/DOCS/Import+Export+Tools







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 2 '11 at 22:54









                  earldouglasearldouglas

                  10.8k43246




                  10.8k43246








                  • 3





                    To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

                    – Donal Lafferty
                    Aug 27 '15 at 8:52











                  • At mongodb server at which place the database will be stored?

                    – space earth
                    Jun 15 '17 at 10:09














                  • 3





                    To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

                    – Donal Lafferty
                    Aug 27 '15 at 8:52











                  • At mongodb server at which place the database will be stored?

                    – space earth
                    Jun 15 '17 at 10:09








                  3




                  3





                  To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

                  – Donal Lafferty
                  Aug 27 '15 at 8:52





                  To put the results in a single compressed file, see unix.stackexchange.com/questions/93139/…

                  – Donal Lafferty
                  Aug 27 '15 at 8:52













                  At mongodb server at which place the database will be stored?

                  – space earth
                  Jun 15 '17 at 10:09





                  At mongodb server at which place the database will be stored?

                  – space earth
                  Jun 15 '17 at 10:09













                  103














                  To dump your database for backup you call this command on your terminal



                  mongodump --db database_name --collection collection_name


                  To import your backup file to mongodb you can use the following command on your terminal



                  mongorestore --db database_name path_to_bson_file





                  share|improve this answer


























                  • What is the significance of metadata.json for restoring?

                    – Nabin
                    May 8 '18 at 14:21
















                  103














                  To dump your database for backup you call this command on your terminal



                  mongodump --db database_name --collection collection_name


                  To import your backup file to mongodb you can use the following command on your terminal



                  mongorestore --db database_name path_to_bson_file





                  share|improve this answer


























                  • What is the significance of metadata.json for restoring?

                    – Nabin
                    May 8 '18 at 14:21














                  103












                  103








                  103







                  To dump your database for backup you call this command on your terminal



                  mongodump --db database_name --collection collection_name


                  To import your backup file to mongodb you can use the following command on your terminal



                  mongorestore --db database_name path_to_bson_file





                  share|improve this answer















                  To dump your database for backup you call this command on your terminal



                  mongodump --db database_name --collection collection_name


                  To import your backup file to mongodb you can use the following command on your terminal



                  mongorestore --db database_name path_to_bson_file






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 27 '15 at 11:36









                  Sameer Shaikh

                  3,84111130




                  3,84111130










                  answered Apr 1 '15 at 5:18









                  saimadhu.polamurisaimadhu.polamuri

                  2,38311518




                  2,38311518













                  • What is the significance of metadata.json for restoring?

                    – Nabin
                    May 8 '18 at 14:21



















                  • What is the significance of metadata.json for restoring?

                    – Nabin
                    May 8 '18 at 14:21

















                  What is the significance of metadata.json for restoring?

                  – Nabin
                  May 8 '18 at 14:21





                  What is the significance of metadata.json for restoring?

                  – Nabin
                  May 8 '18 at 14:21











                  61














                  You can also use gzip for taking backup of one collection and compressing the backup on the fly:



                  mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz


                  or with a date in the file name:



                  mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz


                  Update:

                  Backup all collections of a database in a date folder. The files are gziped:



                  mongodump --db somedb --gzip --out /backups/`date +"%Y-%m-%d"`


                  Or for a single archive:



                  mongodump --db somedb --gzip --archive > dump_`date "+%Y-%m-%d"`.gz


                  Or when mongodb is running inside docker:



                  docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz





                  share|improve this answer


























                  • This looks very nice, but how do you import this gzip file ?

                    – fahim ayat
                    Jul 14 '14 at 10:30











                  • You need to 'gunzip' them, and then use mongorestore

                    – Meny Issakov
                    Aug 6 '14 at 10:22






                  • 1





                    says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

                    – amitchhajer
                    Jun 10 '15 at 6:54






                  • 2





                    typo : "-db" => "--db"

                    – Vivien
                    Oct 1 '15 at 8:33






                  • 7





                    In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

                    – Boop
                    May 30 '16 at 13:48


















                  61














                  You can also use gzip for taking backup of one collection and compressing the backup on the fly:



                  mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz


                  or with a date in the file name:



                  mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz


                  Update:

                  Backup all collections of a database in a date folder. The files are gziped:



                  mongodump --db somedb --gzip --out /backups/`date +"%Y-%m-%d"`


                  Or for a single archive:



                  mongodump --db somedb --gzip --archive > dump_`date "+%Y-%m-%d"`.gz


                  Or when mongodb is running inside docker:



                  docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz





                  share|improve this answer


























                  • This looks very nice, but how do you import this gzip file ?

                    – fahim ayat
                    Jul 14 '14 at 10:30











                  • You need to 'gunzip' them, and then use mongorestore

                    – Meny Issakov
                    Aug 6 '14 at 10:22






                  • 1





                    says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

                    – amitchhajer
                    Jun 10 '15 at 6:54






                  • 2





                    typo : "-db" => "--db"

                    – Vivien
                    Oct 1 '15 at 8:33






                  • 7





                    In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

                    – Boop
                    May 30 '16 at 13:48
















                  61












                  61








                  61







                  You can also use gzip for taking backup of one collection and compressing the backup on the fly:



                  mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz


                  or with a date in the file name:



                  mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz


                  Update:

                  Backup all collections of a database in a date folder. The files are gziped:



                  mongodump --db somedb --gzip --out /backups/`date +"%Y-%m-%d"`


                  Or for a single archive:



                  mongodump --db somedb --gzip --archive > dump_`date "+%Y-%m-%d"`.gz


                  Or when mongodb is running inside docker:



                  docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz





                  share|improve this answer















                  You can also use gzip for taking backup of one collection and compressing the backup on the fly:



                  mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz


                  or with a date in the file name:



                  mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz


                  Update:

                  Backup all collections of a database in a date folder. The files are gziped:



                  mongodump --db somedb --gzip --out /backups/`date +"%Y-%m-%d"`


                  Or for a single archive:



                  mongodump --db somedb --gzip --archive > dump_`date "+%Y-%m-%d"`.gz


                  Or when mongodb is running inside docker:



                  docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 30 at 22:05

























                  answered Jul 15 '13 at 13:51









                  r03r03

                  2,29712242




                  2,29712242













                  • This looks very nice, but how do you import this gzip file ?

                    – fahim ayat
                    Jul 14 '14 at 10:30











                  • You need to 'gunzip' them, and then use mongorestore

                    – Meny Issakov
                    Aug 6 '14 at 10:22






                  • 1





                    says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

                    – amitchhajer
                    Jun 10 '15 at 6:54






                  • 2





                    typo : "-db" => "--db"

                    – Vivien
                    Oct 1 '15 at 8:33






                  • 7





                    In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

                    – Boop
                    May 30 '16 at 13:48





















                  • This looks very nice, but how do you import this gzip file ?

                    – fahim ayat
                    Jul 14 '14 at 10:30











                  • You need to 'gunzip' them, and then use mongorestore

                    – Meny Issakov
                    Aug 6 '14 at 10:22






                  • 1





                    says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

                    – amitchhajer
                    Jun 10 '15 at 6:54






                  • 2





                    typo : "-db" => "--db"

                    – Vivien
                    Oct 1 '15 at 8:33






                  • 7





                    In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

                    – Boop
                    May 30 '16 at 13:48



















                  This looks very nice, but how do you import this gzip file ?

                  – fahim ayat
                  Jul 14 '14 at 10:30





                  This looks very nice, but how do you import this gzip file ?

                  – fahim ayat
                  Jul 14 '14 at 10:30













                  You need to 'gunzip' them, and then use mongorestore

                  – Meny Issakov
                  Aug 6 '14 at 10:22





                  You need to 'gunzip' them, and then use mongorestore

                  – Meny Issakov
                  Aug 6 '14 at 10:22




                  1




                  1





                  says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

                  – amitchhajer
                  Jun 10 '15 at 6:54





                  says: ERROR: don't know what to do with file! Gunizpped and tried `mongorestore --db db_name 'gunzipped file'

                  – amitchhajer
                  Jun 10 '15 at 6:54




                  2




                  2





                  typo : "-db" => "--db"

                  – Vivien
                  Oct 1 '15 at 8:33





                  typo : "-db" => "--db"

                  – Vivien
                  Oct 1 '15 at 8:33




                  7




                  7





                  In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

                  – Boop
                  May 30 '16 at 13:48







                  In version 3.2 of mongodump or higher you can use the --gzip option to do that: mongodump_manpage and same option for mongorestore

                  – Boop
                  May 30 '16 at 13:48













                  50














                  This command will make a dump of given database in json and bson format.



                  mongodump -d <database name> -o <target directory>





                  share|improve this answer
























                  • Only this worked for me

                    – Jamie Hutber
                    Nov 30 '16 at 0:27
















                  50














                  This command will make a dump of given database in json and bson format.



                  mongodump -d <database name> -o <target directory>





                  share|improve this answer
























                  • Only this worked for me

                    – Jamie Hutber
                    Nov 30 '16 at 0:27














                  50












                  50








                  50







                  This command will make a dump of given database in json and bson format.



                  mongodump -d <database name> -o <target directory>





                  share|improve this answer













                  This command will make a dump of given database in json and bson format.



                  mongodump -d <database name> -o <target directory>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 13 '15 at 10:58









                  jatinjatin

                  2,0371622




                  2,0371622













                  • Only this worked for me

                    – Jamie Hutber
                    Nov 30 '16 at 0:27



















                  • Only this worked for me

                    – Jamie Hutber
                    Nov 30 '16 at 0:27

















                  Only this worked for me

                  – Jamie Hutber
                  Nov 30 '16 at 0:27





                  Only this worked for me

                  – Jamie Hutber
                  Nov 30 '16 at 0:27











                  12














                  There is a utility called : mongodump
                  On the mongo command line you can type :



                  >./mongodump


                  The above will create a dump of all the databases on your localhost. To make dump of a single collection use:



                  ./mongodump --db blog --collection posts


                  Have a look at : mongodump






                  share|improve this answer




























                    12














                    There is a utility called : mongodump
                    On the mongo command line you can type :



                    >./mongodump


                    The above will create a dump of all the databases on your localhost. To make dump of a single collection use:



                    ./mongodump --db blog --collection posts


                    Have a look at : mongodump






                    share|improve this answer


























                      12












                      12








                      12







                      There is a utility called : mongodump
                      On the mongo command line you can type :



                      >./mongodump


                      The above will create a dump of all the databases on your localhost. To make dump of a single collection use:



                      ./mongodump --db blog --collection posts


                      Have a look at : mongodump






                      share|improve this answer













                      There is a utility called : mongodump
                      On the mongo command line you can type :



                      >./mongodump


                      The above will create a dump of all the databases on your localhost. To make dump of a single collection use:



                      ./mongodump --db blog --collection posts


                      Have a look at : mongodump







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 3 '11 at 8:15









                      aditya_gauraditya_gaur

                      1,65452643




                      1,65452643























                          11














                          You need to open command prompt as an administrator in a folder where your Mongo is installed (in my case: C:Program FilesMongoDBServer3.4bin).
                          If you want to dump your whole database, you can just use:



                          mongodump --db database_name


                          You also have posibilities to dump only certain collection(s), or to dump all but certain collection(s).



                          If you want to dump only one collection (for example users):



                          mongodump  --db database_name --collection users


                          If you want to dump all but users collection:



                          mongodump  --db database_name --excludeCollection=users


                          It is also possible to output the dump to an archive file:



                          mongodump --archive=test.archive --db database_name





                          share|improve this answer






























                            11














                            You need to open command prompt as an administrator in a folder where your Mongo is installed (in my case: C:Program FilesMongoDBServer3.4bin).
                            If you want to dump your whole database, you can just use:



                            mongodump --db database_name


                            You also have posibilities to dump only certain collection(s), or to dump all but certain collection(s).



                            If you want to dump only one collection (for example users):



                            mongodump  --db database_name --collection users


                            If you want to dump all but users collection:



                            mongodump  --db database_name --excludeCollection=users


                            It is also possible to output the dump to an archive file:



                            mongodump --archive=test.archive --db database_name





                            share|improve this answer




























                              11












                              11








                              11







                              You need to open command prompt as an administrator in a folder where your Mongo is installed (in my case: C:Program FilesMongoDBServer3.4bin).
                              If you want to dump your whole database, you can just use:



                              mongodump --db database_name


                              You also have posibilities to dump only certain collection(s), or to dump all but certain collection(s).



                              If you want to dump only one collection (for example users):



                              mongodump  --db database_name --collection users


                              If you want to dump all but users collection:



                              mongodump  --db database_name --excludeCollection=users


                              It is also possible to output the dump to an archive file:



                              mongodump --archive=test.archive --db database_name





                              share|improve this answer















                              You need to open command prompt as an administrator in a folder where your Mongo is installed (in my case: C:Program FilesMongoDBServer3.4bin).
                              If you want to dump your whole database, you can just use:



                              mongodump --db database_name


                              You also have posibilities to dump only certain collection(s), or to dump all but certain collection(s).



                              If you want to dump only one collection (for example users):



                              mongodump  --db database_name --collection users


                              If you want to dump all but users collection:



                              mongodump  --db database_name --excludeCollection=users


                              It is also possible to output the dump to an archive file:



                              mongodump --archive=test.archive --db database_name






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jun 19 '17 at 1:01

























                              answered Jun 18 '17 at 23:57









                              JeryJery

                              11114




                              11114























                                  7














                                  Following command connect to the remote server to dump a database:



                                  <> optional params use them if you need them




                                  • host - host name port

                                  • listening port username

                                  • username of db db

                                  • db name ssl

                                  • secure connection out


                                  • output to a created folder with a name



                                    mongodump --host --port --username --db --ssl --password --out _date+"%Y-%m-%d"








                                  share|improve this answer


























                                  • For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

                                    – Anurag_BEHS
                                    Jul 9 '18 at 19:44


















                                  7














                                  Following command connect to the remote server to dump a database:



                                  <> optional params use them if you need them




                                  • host - host name port

                                  • listening port username

                                  • username of db db

                                  • db name ssl

                                  • secure connection out


                                  • output to a created folder with a name



                                    mongodump --host --port --username --db --ssl --password --out _date+"%Y-%m-%d"








                                  share|improve this answer


























                                  • For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

                                    – Anurag_BEHS
                                    Jul 9 '18 at 19:44
















                                  7












                                  7








                                  7







                                  Following command connect to the remote server to dump a database:



                                  <> optional params use them if you need them




                                  • host - host name port

                                  • listening port username

                                  • username of db db

                                  • db name ssl

                                  • secure connection out


                                  • output to a created folder with a name



                                    mongodump --host --port --username --db --ssl --password --out _date+"%Y-%m-%d"








                                  share|improve this answer















                                  Following command connect to the remote server to dump a database:



                                  <> optional params use them if you need them




                                  • host - host name port

                                  • listening port username

                                  • username of db db

                                  • db name ssl

                                  • secure connection out


                                  • output to a created folder with a name



                                    mongodump --host --port --username --db --ssl --password --out _date+"%Y-%m-%d"









                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Jul 30 '18 at 19:53









                                  Ignacio Ara

                                  1,58711027




                                  1,58711027










                                  answered Sep 18 '17 at 7:49









                                  Michael HorojanskiMichael Horojanski

                                  1,6821727




                                  1,6821727













                                  • For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

                                    – Anurag_BEHS
                                    Jul 9 '18 at 19:44





















                                  • For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

                                    – Anurag_BEHS
                                    Jul 9 '18 at 19:44



















                                  For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

                                  – Anurag_BEHS
                                  Jul 9 '18 at 19:44







                                  For those who are getting this error after running above suggested query- error parsing command line options: unknown option "ssl". Try to run above query after removing --ssl . it worked for me.Thanks.

                                  – Anurag_BEHS
                                  Jul 9 '18 at 19:44













                                  6














                                  You can dump your database and restore with bellow command



                                  mongodb  -d <Your_db_name> -o <path of your folder>


                                  for example my database name is tracking i have dump in dump folder



                                  mongodb  -d tracking -o dump


                                  Restoring dump



                                  mongorestore -d <databasename> <dum_path>

                                  mongorestore -d tracking dump/tracking





                                  share|improve this answer






























                                    6














                                    You can dump your database and restore with bellow command



                                    mongodb  -d <Your_db_name> -o <path of your folder>


                                    for example my database name is tracking i have dump in dump folder



                                    mongodb  -d tracking -o dump


                                    Restoring dump



                                    mongorestore -d <databasename> <dum_path>

                                    mongorestore -d tracking dump/tracking





                                    share|improve this answer




























                                      6












                                      6








                                      6







                                      You can dump your database and restore with bellow command



                                      mongodb  -d <Your_db_name> -o <path of your folder>


                                      for example my database name is tracking i have dump in dump folder



                                      mongodb  -d tracking -o dump


                                      Restoring dump



                                      mongorestore -d <databasename> <dum_path>

                                      mongorestore -d tracking dump/tracking





                                      share|improve this answer















                                      You can dump your database and restore with bellow command



                                      mongodb  -d <Your_db_name> -o <path of your folder>


                                      for example my database name is tracking i have dump in dump folder



                                      mongodb  -d tracking -o dump


                                      Restoring dump



                                      mongorestore -d <databasename> <dum_path>

                                      mongorestore -d tracking dump/tracking






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited May 25 '18 at 7:58

























                                      answered May 14 '18 at 10:14









                                      Nanhe KumarNanhe Kumar

                                      9,27934945




                                      9,27934945























                                          3














                                          cmd -->



                                          C:Program FilesMongoDBServer3.2bin>mongodump.exe --db Dintest






                                          share|improve this answer



















                                          • 1





                                            Easy and quickest option

                                            – Ignacio Ara
                                            Jul 30 '18 at 16:26













                                          • Thanks a lot Arnav, really appreciated.

                                            – HassanSh__3571619
                                            Feb 18 at 20:33
















                                          3














                                          cmd -->



                                          C:Program FilesMongoDBServer3.2bin>mongodump.exe --db Dintest






                                          share|improve this answer



















                                          • 1





                                            Easy and quickest option

                                            – Ignacio Ara
                                            Jul 30 '18 at 16:26













                                          • Thanks a lot Arnav, really appreciated.

                                            – HassanSh__3571619
                                            Feb 18 at 20:33














                                          3












                                          3








                                          3







                                          cmd -->



                                          C:Program FilesMongoDBServer3.2bin>mongodump.exe --db Dintest






                                          share|improve this answer













                                          cmd -->



                                          C:Program FilesMongoDBServer3.2bin>mongodump.exe --db Dintest







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Oct 15 '17 at 4:11









                                          arnavarnav

                                          1,5211417




                                          1,5211417








                                          • 1





                                            Easy and quickest option

                                            – Ignacio Ara
                                            Jul 30 '18 at 16:26













                                          • Thanks a lot Arnav, really appreciated.

                                            – HassanSh__3571619
                                            Feb 18 at 20:33














                                          • 1





                                            Easy and quickest option

                                            – Ignacio Ara
                                            Jul 30 '18 at 16:26













                                          • Thanks a lot Arnav, really appreciated.

                                            – HassanSh__3571619
                                            Feb 18 at 20:33








                                          1




                                          1





                                          Easy and quickest option

                                          – Ignacio Ara
                                          Jul 30 '18 at 16:26







                                          Easy and quickest option

                                          – Ignacio Ara
                                          Jul 30 '18 at 16:26















                                          Thanks a lot Arnav, really appreciated.

                                          – HassanSh__3571619
                                          Feb 18 at 20:33





                                          Thanks a lot Arnav, really appreciated.

                                          – HassanSh__3571619
                                          Feb 18 at 20:33











                                          1














                                          Below command will work to take dump of mongo db .




                                          mongodump -d -o




                                          On Windows : try this one where c:mongodump is dump file location ,
                                          It will create metadata in json, and backup in bson format




                                          C:MongoDBbin>mongodump -d -o c:mongodump







                                          share|improve this answer




























                                            1














                                            Below command will work to take dump of mongo db .




                                            mongodump -d -o




                                            On Windows : try this one where c:mongodump is dump file location ,
                                            It will create metadata in json, and backup in bson format




                                            C:MongoDBbin>mongodump -d -o c:mongodump







                                            share|improve this answer


























                                              1












                                              1








                                              1







                                              Below command will work to take dump of mongo db .




                                              mongodump -d -o




                                              On Windows : try this one where c:mongodump is dump file location ,
                                              It will create metadata in json, and backup in bson format




                                              C:MongoDBbin>mongodump -d -o c:mongodump







                                              share|improve this answer













                                              Below command will work to take dump of mongo db .




                                              mongodump -d -o




                                              On Windows : try this one where c:mongodump is dump file location ,
                                              It will create metadata in json, and backup in bson format




                                              C:MongoDBbin>mongodump -d -o c:mongodump








                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Feb 28 '17 at 11:05









                                              Bhasker The NavigatorBhasker The Navigator

                                              394




                                              394























                                                  1














                                                  Backup/Restore Mongodb with timing.



                                                  Backup:



                                                  sudo mongodump --db db_name --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                  --db argument for databse name



                                                  --out argument for path of output



                                                  Restore:



                                                  sudo mongorestore --db db_name --drop /path_of_your_backup/01-01-19/db_name/


                                                  --drop argument for drop databse before restore



                                                  Timing:



                                                  You can use crontab for timing backup:



                                                  sudo crontab -e


                                                  It opens with editor(e.g. nano)



                                                  3 3 * * * mongodump --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                  backup every day at 03:03 AM




                                                  Depending on your MongoDB database sizes you may soon run out of disk
                                                  space with too many backups. That's why it's also recommended to clean
                                                  the old backups regularly or to compress them. For example, to delete
                                                  all the backups older than 7 days you can use the following bash
                                                  command:




                                                  3 1 * * * find /path_of_your_backup/ -mtime +7 -exec rm -rf {} ;


                                                  delete all the backups older than 7 days



                                                  Good Luck.



                                                  ref:
                                                  https://www.digitalocean.com/community/tutorials/how-to-back-up-restore-and-migrate-a-mongodb-database-on-ubuntu-14-04






                                                  share|improve this answer






























                                                    1














                                                    Backup/Restore Mongodb with timing.



                                                    Backup:



                                                    sudo mongodump --db db_name --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                    --db argument for databse name



                                                    --out argument for path of output



                                                    Restore:



                                                    sudo mongorestore --db db_name --drop /path_of_your_backup/01-01-19/db_name/


                                                    --drop argument for drop databse before restore



                                                    Timing:



                                                    You can use crontab for timing backup:



                                                    sudo crontab -e


                                                    It opens with editor(e.g. nano)



                                                    3 3 * * * mongodump --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                    backup every day at 03:03 AM




                                                    Depending on your MongoDB database sizes you may soon run out of disk
                                                    space with too many backups. That's why it's also recommended to clean
                                                    the old backups regularly or to compress them. For example, to delete
                                                    all the backups older than 7 days you can use the following bash
                                                    command:




                                                    3 1 * * * find /path_of_your_backup/ -mtime +7 -exec rm -rf {} ;


                                                    delete all the backups older than 7 days



                                                    Good Luck.



                                                    ref:
                                                    https://www.digitalocean.com/community/tutorials/how-to-back-up-restore-and-migrate-a-mongodb-database-on-ubuntu-14-04






                                                    share|improve this answer




























                                                      1












                                                      1








                                                      1







                                                      Backup/Restore Mongodb with timing.



                                                      Backup:



                                                      sudo mongodump --db db_name --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                      --db argument for databse name



                                                      --out argument for path of output



                                                      Restore:



                                                      sudo mongorestore --db db_name --drop /path_of_your_backup/01-01-19/db_name/


                                                      --drop argument for drop databse before restore



                                                      Timing:



                                                      You can use crontab for timing backup:



                                                      sudo crontab -e


                                                      It opens with editor(e.g. nano)



                                                      3 3 * * * mongodump --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                      backup every day at 03:03 AM




                                                      Depending on your MongoDB database sizes you may soon run out of disk
                                                      space with too many backups. That's why it's also recommended to clean
                                                      the old backups regularly or to compress them. For example, to delete
                                                      all the backups older than 7 days you can use the following bash
                                                      command:




                                                      3 1 * * * find /path_of_your_backup/ -mtime +7 -exec rm -rf {} ;


                                                      delete all the backups older than 7 days



                                                      Good Luck.



                                                      ref:
                                                      https://www.digitalocean.com/community/tutorials/how-to-back-up-restore-and-migrate-a-mongodb-database-on-ubuntu-14-04






                                                      share|improve this answer















                                                      Backup/Restore Mongodb with timing.



                                                      Backup:



                                                      sudo mongodump --db db_name --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                      --db argument for databse name



                                                      --out argument for path of output



                                                      Restore:



                                                      sudo mongorestore --db db_name --drop /path_of_your_backup/01-01-19/db_name/


                                                      --drop argument for drop databse before restore



                                                      Timing:



                                                      You can use crontab for timing backup:



                                                      sudo crontab -e


                                                      It opens with editor(e.g. nano)



                                                      3 3 * * * mongodump --out /path_of_your_backup/`date +"%m-%d-%y"`


                                                      backup every day at 03:03 AM




                                                      Depending on your MongoDB database sizes you may soon run out of disk
                                                      space with too many backups. That's why it's also recommended to clean
                                                      the old backups regularly or to compress them. For example, to delete
                                                      all the backups older than 7 days you can use the following bash
                                                      command:




                                                      3 1 * * * find /path_of_your_backup/ -mtime +7 -exec rm -rf {} ;


                                                      delete all the backups older than 7 days



                                                      Good Luck.



                                                      ref:
                                                      https://www.digitalocean.com/community/tutorials/how-to-back-up-restore-and-migrate-a-mongodb-database-on-ubuntu-14-04







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Jan 2 at 6:56

























                                                      answered Jan 1 at 7:19









                                                      ShahRokhShahRokh

                                                      8141123




                                                      8141123























                                                          0














                                                          Or you can make backup script on Windows, remember to add Winrar to %PATH%



                                                          binmongodump --db=COL1 -o D:BACKCOL1
                                                          rar.exe a -ep1 -r COL1.rar COL1
                                                          rename COL1.rar "COL1_%date:~10,4%_%date:~7,2%_%date:~4,2%_%time:~0,2%_%time:~3,2%.rar"

                                                          #rmdir /s /q COL1 -> don;t run this on your mongodb/ dir !!!!!





                                                          share|improve this answer






























                                                            0














                                                            Or you can make backup script on Windows, remember to add Winrar to %PATH%



                                                            binmongodump --db=COL1 -o D:BACKCOL1
                                                            rar.exe a -ep1 -r COL1.rar COL1
                                                            rename COL1.rar "COL1_%date:~10,4%_%date:~7,2%_%date:~4,2%_%time:~0,2%_%time:~3,2%.rar"

                                                            #rmdir /s /q COL1 -> don;t run this on your mongodb/ dir !!!!!





                                                            share|improve this answer




























                                                              0












                                                              0








                                                              0







                                                              Or you can make backup script on Windows, remember to add Winrar to %PATH%



                                                              binmongodump --db=COL1 -o D:BACKCOL1
                                                              rar.exe a -ep1 -r COL1.rar COL1
                                                              rename COL1.rar "COL1_%date:~10,4%_%date:~7,2%_%date:~4,2%_%time:~0,2%_%time:~3,2%.rar"

                                                              #rmdir /s /q COL1 -> don;t run this on your mongodb/ dir !!!!!





                                                              share|improve this answer















                                                              Or you can make backup script on Windows, remember to add Winrar to %PATH%



                                                              binmongodump --db=COL1 -o D:BACKCOL1
                                                              rar.exe a -ep1 -r COL1.rar COL1
                                                              rename COL1.rar "COL1_%date:~10,4%_%date:~7,2%_%date:~4,2%_%time:~0,2%_%time:~3,2%.rar"

                                                              #rmdir /s /q COL1 -> don;t run this on your mongodb/ dir !!!!!






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Aug 2 '16 at 10:07

























                                                              answered Aug 2 '16 at 9:56









                                                              user956584user956584

                                                              3,54423143




                                                              3,54423143























                                                                  0














                                                                  Mongo dump and restore with uri to local



                                                                  mongodump --uri "mongodb://USERNAME:PASSWORD@IP_OR_URL:PORT/DB_NAME" --collection COLLECTION_NAME -o LOCAL_URL



                                                                  If you do not specify --colletion COLLECTION_NAME, it will dump entire DB.






                                                                  share|improve this answer






























                                                                    0














                                                                    Mongo dump and restore with uri to local



                                                                    mongodump --uri "mongodb://USERNAME:PASSWORD@IP_OR_URL:PORT/DB_NAME" --collection COLLECTION_NAME -o LOCAL_URL



                                                                    If you do not specify --colletion COLLECTION_NAME, it will dump entire DB.






                                                                    share|improve this answer




























                                                                      0












                                                                      0








                                                                      0







                                                                      Mongo dump and restore with uri to local



                                                                      mongodump --uri "mongodb://USERNAME:PASSWORD@IP_OR_URL:PORT/DB_NAME" --collection COLLECTION_NAME -o LOCAL_URL



                                                                      If you do not specify --colletion COLLECTION_NAME, it will dump entire DB.






                                                                      share|improve this answer















                                                                      Mongo dump and restore with uri to local



                                                                      mongodump --uri "mongodb://USERNAME:PASSWORD@IP_OR_URL:PORT/DB_NAME" --collection COLLECTION_NAME -o LOCAL_URL



                                                                      If you do not specify --colletion COLLECTION_NAME, it will dump entire DB.







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Nov 30 '18 at 12:32

























                                                                      answered Nov 24 '18 at 17:41









                                                                      smartworld-dmsmartworld-dm

                                                                      6410




                                                                      6410























                                                                          0














                                                                          take mongodb backup for particular db and delete 7 days old backup using bin sh command :-



                                                                          #!/bin/bash

                                                                          MONGO_DATABASE="nexgtv_16"
                                                                          APP_NAME="test"
                                                                          MONGO_HOST="127.0.0.1"
                                                                          MONGO_PORT="27017"
                                                                          TIMESTAMP=`date +%F-%H%M`
                                                                          MONGODUMP_PATH="/usr/bin/mongodump"
                                                                          BACKUPS_DIR="/home/mongodbbackups/backups/$APP_NAME"
                                                                          BACKUP_NAME="$APP_NAME-$TIMESTAMP"
                                                                          $MONGODUMP_PATH -d $MONGO_DATABASE
                                                                          mkdir -p $BACKUPS_DIR
                                                                          mv dump $BACKUP_NAME
                                                                          tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
                                                                          rm -rf $BACKUP_NAME
                                                                          find /home/mongodbbackups/backups/test/ -mindepth 1 -mtime +7 -delete





                                                                          share|improve this answer






























                                                                            0














                                                                            take mongodb backup for particular db and delete 7 days old backup using bin sh command :-



                                                                            #!/bin/bash

                                                                            MONGO_DATABASE="nexgtv_16"
                                                                            APP_NAME="test"
                                                                            MONGO_HOST="127.0.0.1"
                                                                            MONGO_PORT="27017"
                                                                            TIMESTAMP=`date +%F-%H%M`
                                                                            MONGODUMP_PATH="/usr/bin/mongodump"
                                                                            BACKUPS_DIR="/home/mongodbbackups/backups/$APP_NAME"
                                                                            BACKUP_NAME="$APP_NAME-$TIMESTAMP"
                                                                            $MONGODUMP_PATH -d $MONGO_DATABASE
                                                                            mkdir -p $BACKUPS_DIR
                                                                            mv dump $BACKUP_NAME
                                                                            tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
                                                                            rm -rf $BACKUP_NAME
                                                                            find /home/mongodbbackups/backups/test/ -mindepth 1 -mtime +7 -delete





                                                                            share|improve this answer




























                                                                              0












                                                                              0








                                                                              0







                                                                              take mongodb backup for particular db and delete 7 days old backup using bin sh command :-



                                                                              #!/bin/bash

                                                                              MONGO_DATABASE="nexgtv_16"
                                                                              APP_NAME="test"
                                                                              MONGO_HOST="127.0.0.1"
                                                                              MONGO_PORT="27017"
                                                                              TIMESTAMP=`date +%F-%H%M`
                                                                              MONGODUMP_PATH="/usr/bin/mongodump"
                                                                              BACKUPS_DIR="/home/mongodbbackups/backups/$APP_NAME"
                                                                              BACKUP_NAME="$APP_NAME-$TIMESTAMP"
                                                                              $MONGODUMP_PATH -d $MONGO_DATABASE
                                                                              mkdir -p $BACKUPS_DIR
                                                                              mv dump $BACKUP_NAME
                                                                              tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
                                                                              rm -rf $BACKUP_NAME
                                                                              find /home/mongodbbackups/backups/test/ -mindepth 1 -mtime +7 -delete





                                                                              share|improve this answer















                                                                              take mongodb backup for particular db and delete 7 days old backup using bin sh command :-



                                                                              #!/bin/bash

                                                                              MONGO_DATABASE="nexgtv_16"
                                                                              APP_NAME="test"
                                                                              MONGO_HOST="127.0.0.1"
                                                                              MONGO_PORT="27017"
                                                                              TIMESTAMP=`date +%F-%H%M`
                                                                              MONGODUMP_PATH="/usr/bin/mongodump"
                                                                              BACKUPS_DIR="/home/mongodbbackups/backups/$APP_NAME"
                                                                              BACKUP_NAME="$APP_NAME-$TIMESTAMP"
                                                                              $MONGODUMP_PATH -d $MONGO_DATABASE
                                                                              mkdir -p $BACKUPS_DIR
                                                                              mv dump $BACKUP_NAME
                                                                              tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
                                                                              rm -rf $BACKUP_NAME
                                                                              find /home/mongodbbackups/backups/test/ -mindepth 1 -mtime +7 -delete






                                                                              share|improve this answer














                                                                              share|improve this answer



                                                                              share|improve this answer








                                                                              edited Jan 1 at 7:26









                                                                              adiga

                                                                              9,51962342




                                                                              9,51962342










                                                                              answered Sep 29 '16 at 5:53









                                                                              manoj tiwarimanoj tiwari

                                                                              294




                                                                              294























                                                                                  -4














                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder



                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder.gz






                                                                                  share|improve this answer


























                                                                                  • Please add an explanation around what these commands do.

                                                                                    – Steve
                                                                                    Mar 31 '17 at 5:51











                                                                                  • 1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                                                                                    – Anjankumar H N
                                                                                    Mar 31 '17 at 6:07


















                                                                                  -4














                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder



                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder.gz






                                                                                  share|improve this answer


























                                                                                  • Please add an explanation around what these commands do.

                                                                                    – Steve
                                                                                    Mar 31 '17 at 5:51











                                                                                  • 1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                                                                                    – Anjankumar H N
                                                                                    Mar 31 '17 at 6:07
















                                                                                  -4












                                                                                  -4








                                                                                  -4







                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder



                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder.gz






                                                                                  share|improve this answer















                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder



                                                                                  mongodump -h hostname -u dbusername -p dbpassword --db dbname --port portnumber --out /path/folder.gz







                                                                                  share|improve this answer














                                                                                  share|improve this answer



                                                                                  share|improve this answer








                                                                                  edited Mar 31 '17 at 6:05

























                                                                                  answered Mar 31 '17 at 5:30









                                                                                  Anjankumar H NAnjankumar H N

                                                                                  518




                                                                                  518













                                                                                  • Please add an explanation around what these commands do.

                                                                                    – Steve
                                                                                    Mar 31 '17 at 5:51











                                                                                  • 1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                                                                                    – Anjankumar H N
                                                                                    Mar 31 '17 at 6:07





















                                                                                  • Please add an explanation around what these commands do.

                                                                                    – Steve
                                                                                    Mar 31 '17 at 5:51











                                                                                  • 1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                                                                                    – Anjankumar H N
                                                                                    Mar 31 '17 at 6:07



















                                                                                  Please add an explanation around what these commands do.

                                                                                  – Steve
                                                                                  Mar 31 '17 at 5:51





                                                                                  Please add an explanation around what these commands do.

                                                                                  – Steve
                                                                                  Mar 31 '17 at 5:51













                                                                                  1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                                                                                  – Anjankumar H N
                                                                                  Mar 31 '17 at 6:07







                                                                                  1. mongodump - is a command to create a mongo dump along with we need input about specicification. 2. -h represents your mongodb hostname. 3. -u represents your mongodb username. 4. -p represents passsword. 5. --db represents the databasename tha we need to take dump. 6. --port represents the port your mongo is running. 7. --out represents the destination of your dump with name.

                                                                                  – Anjankumar H N
                                                                                  Mar 31 '17 at 6:07




















                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  Thanks for contributing an answer to Stack Overflow!


                                                                                  • 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%2fstackoverflow.com%2fquestions%2f4880874%2fhow-do-i-create-a-mongodb-dump-of-my-database%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

                                                                                  Monofisismo

                                                                                  Angular Downloading a file using contenturl with Basic Authentication

                                                                                  Olmecas