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.