Mongodump can be used for database or table-level backup of MongoDB. The following is an example:
Back up the my_mongodb database [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 7508756 bsondump
Drwxr-XR-x 3 Root 4096 04-10 23:54 dump
-Rwxr-XR-x 1 Root 2978016 Mongo
At this time, a dump directory will be created under the current directory to store the backed up files. You can also specify the directory where the backup is stored,
[Root @ localhost bin] #./mongodump-D my_mongodb-O my_mongodb_dump
Connected to: 127.0.0.1
Database: my_mongodb to my_mongodb_dump/my_mongodb
My_mongodb.system.indexes
My_mongodb_dump/my_mongodb/system. Indexes. bson
1 objects
My_mongodb.user to my_mongodb_dump/my_mongodb/user. bson
2 objects
[Root @ localhost bin] #
Data Recovery
[Root @ localhost bin] #./mongorestore-D my_mongodb my_mongodb_dump /*
Connected to: 127.0.0.1
Wed Apr 11 00:03:03 my_mongodb_dump/my_mongodb/user. bson
Wed Apr 11 00:03:03 going into namespace [my_mongodb.user]
Wed Apr 11 00:03:03 2 objects found
Wed Apr 11 00:03:03 my_mongodb_dump/my_mongo/ system. Indexes. bson
Wed Apr 11 00:03:03 going into namespace [my_mongodb.system.indexes]
Wed Apr 11 00:03:03 {name: "_ id _", NS: "my_mongodb.user", key: {_ ID: 1}, V: 0}
Wed Apr 11 00:03:03 1 objects found
[Root @ localhost bin] #