MongoDB Learning Journey 14: MongoDB Data backup and recovery

Source: Internet
Author: User
Tags mongodb mongodump

Backup

[Root@localhost bin]#./mongodump-d my_mongodb 
connected to:127.0.0.1  
database:my_mongodb     to     dump/ My_mongodb          
my_mongodb.system.indexes to Dump/my_mongodb/system.indexes.bson                  
1 objects          
My_mongodb.user To Dump/my_mongodb/user.bson                  
2 objects 
[root@localhost bin]# ll 
Total 67648  
-rwxr-xr-x 1 root root 7508756 2011-04-06 bsondump 
drwxr-xr-x 3 root root    4096 04-10 23:54 Dump 

At this point, a dump directory is created in the current directory to hold the backed up files and, of course, to specify the directory where the backup resides.

Root@localhost bin]#./mongodump-d my_mongodb-o my_mongodb_dump connected to:127.0.0.1  
database:my_mongodb< C2/>to     my_mongodb_dump/my_mongodb        
 my_mongodb.system.indexes  to  my_mongodb_dump/my_mongodb/ System.indexes.bson                  
1 Objects          
my_mongodb.user to My_mongodb_dump/my_mongodb/user.bson           
2 objects 

In this example, the backup file exists in the My_mongodb_dump directory under the current directory

Recovery

Since the backup has just been done, let's first talk about the library My_mongodb deleted

> Use My_mongodb  
switched to db My_mongodb 
> Db.dropdatabase () 
{"Dropped": "My_mongodb", "OK": 1} 
> Show dbs  
admin   (empty) 
local   (empty) 
test    (empty) 
>   

Next, we perform data recovery

[Root@localhost bin]#./mongorestore-d my_mongodb my_mongodb_dump/connected to:127.0.0.1  
Wed Apr one 00:03:03 m Y_mongodb_dump/my_mongodb/user.bson 
Wed Apr 00:03:03      going into namespace [My_mongodb.user] 
Wed Apr 11 00:03:03      2 objects found  
Wed Apr one 00:03:03 my_mongodb_dump/my_mongodb/system.indexes.bson 
Wed Apr 11 00:03:03      going into namespace [my_mongodb.system.indexes] 
Wed Apr one 00:03:03 {name: "_id_", NS: "My_mongodb.use R ", key: {_id:1}, v:0} 
Wed Apr 00:03:03      1 objects found 
[root@localhost bin]#

After the validation of the database back, in fact, to restore the database, it is not necessary to delete the My_mongodb library, as long as the description of the-drop parameter, you can restore the table and then insert data into the table.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.