How to dump MongoDB of my database?

Which command do I use and run?

+132
database mongodb
02 Feb 2018-11-22T00:
source share
15 answers

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

+74
Feb 02 2018-11-22T00:
source share

To reset the database for backup, you call this command on your terminal

 mongodump --db database_name --collection collection_name 

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

 mongorestore --db database_name path_to_bson_file 
+127
Apr 01 '15 at 5:18
source share

You can also use gzip to backup one collection and compress backups 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:
Back up all database collections in a date folder. Files are compressed:

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

Or for one archive:

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

Or when mongodb works inside docker:

 docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_'date "+%Y-%m-%d"'.gz 
+85
Jul 15 '13 at 13:51 on
source share

This command will dump the given database in json and bson format.

 mongodump -d <database name> -o <target directory> 
+60
Feb 13 '15 at 10:58
source share

There is a utility called: mongodump At the mongo command line, you can enter:

 >./mongodump 

The above will dump all the databases on your local host. To dump a single collection, use:

 ./mongodump --db blog --collection posts 

Look: mongodump

+14
Feb 03 '11 at 8:15
source share

You need to open the command line as an administrator in the folder where Mongo is installed (in my case: C: \ Program Files \ MongoDB \ Server \ 3.4 \ bin). If you want to dump the entire database, you can simply use:

 mongodump --db database_name 

You also have the option of dropping only certain collections or dropping all but certain collections (s).

If you want to dump only one collection (e.g. users):

 mongodump --db database_name --collection users 

If you want to reset everything except the user collection:

 mongodump --db database_name --excludeCollection=users 

You can also dump the archive file:

 mongodump --archive=test.archive --db database_name 
+10
Jun 18 '17 at 23:57
source share

The following command connects to the remote server to reset the database:

<> optional parameters use them if you need them

  • host - host name port
  • listening port name
  • username db db
  • Db ssl name
  • secure connection
  • output to the created folder with the name

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

+7
Sep 18 '17 at 7:49 on
source share

You can reset the database and restore the following command

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

for example, my database name is tracking, I have a dump in the dump folder

 mongodb -d tracking -o dump 

Dump recovery

 mongorestore -d <databasename> <dum_path> mongorestore -d tracking dump/tracking 
+7
May 14 '18 at 10:14
source share

Mongodb backup / restore timed.

Backup:

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

--db argument for database name

--out argument to the output path

Restore:

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

--drop argument to delete the database before recovery

Dates:

You can use crontab to back up time:

 sudo crontab -e 

Opens in an editor (e.g. nano)

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

backup every day at 03:03

Depending on the size of the MongoDB database, you may soon run out of disk space with lots of backups. Therefore, it is also recommended that you regularly clean old backups or compress them. For example, to delete all 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 backups older than 7 days

Good luck.

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

+7
Jan 01 '19 at 7:19
source share

cmd →

C: \ Program Files \ MongoDB \ Server \ 3.2 \ bin> mongodump.exe --db Dintest

+3
Oct 15 '17 at 4:11
source share

Below command will work to reset mongo db.

mongodump -d -o

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

C: \ MongoDB \ bin> mongodump -d -oc: \ mongodump

+1
Feb 28 '17 at 11:05
source share

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

 bin\mongodump --db=COL1 -o D:\BACK\COL1 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 !!!!! 
0
Aug 02 '16 at 9:56 on
source share

Take a mongodb backup for a specific database and delete the 7 day backup using the 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 
0
Sep 29 '16 at 5:53 on
source share

Mongo resets and restores from 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 the entire database.

0
Nov 24 '18 at 17:41
source share

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

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

-four
Mar 31 '17 at 5:30
source share



All Articles