简体   繁体   中英

Restore mongodump database backup, which is the right flow?

I'm performing my first steps with MongoDB but still lost. I have read the docs here but I'm not able to find the the right steps in order to import|restore the DB. I have a .tgz file and I have uncompressed it. The output of ll command is as follow:

# ll rs-ds035698_2015-09-21T050031.000Z
total 208
drwxr-xr-x 2 1001 1001   4096 Sep 21 01:00 admin
-rw-r--r-- 1 1001 1001   1037 Sep 21 01:01 oplog.bson
drwxr-xr-x 2 1001 1001  20480 Sep 21 01:01 pdone
drwxr-xr-x 2 1001 1001  20480 Sep 21 01:01 pdone_demo
drwxr-xr-x 2 1001 1001   4096 Sep 21 01:00 pdone_demo_master
drwxr-xr-x 2 1001 1001   4096 Sep 21 01:01 pdone_master
-rw-r--r-- 1 1001 1001 150589 Sep 21 01:01 rs-ds035698_2015-09-21T050031.000Z.log

I need to restore just pdone database. How?

Maybe it will helpful to you....

$mongorestore (It will restore all databases from your dump folder)

Restore particular database from your "dump" folder :

$mongorestore --db employee  C:\Users\mongo\dump\employee (Here "employee" is new db name)

if you want to import an JSON file then follow this :

mongoimport -d students -c grades < grades.json
                     (or)    
mongoimport -d students -c grades < C:\Users\mongo\Download\grades.json

Note: here "students" is database name, "grades" is collection name.

Following command is useful for restoring mongodump BSON file. In my case it is user.bason file

sudo mongorestore -d ibfs -c log /opt/backup/mongodump-2017-02-01/ibfs/user.bson

Explaination :

sudo mongorestore -d ibfs(DATABASE_NAME) -c log(COLLECTION_NAME) /opt/backup/mongodump-2017-02-01/ibfs/user.bson(WHOLE PATH)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM