MongoDB Backup and Recovery

Source: Internet
Author: User
Tags dba mongodump mongorestore


The logical Backup tool Mongodump and Mongorestore tools in MongoDB can be used to back up and restore operations to the current MongoDB database.

Current database structure:

MongoDB Enterprise > Show DBS
Admin 0.000GB
Dbking 0.000GB
Local 0.000GB
MongoDB Enterprise > Use dbking
Switched to DB dbking
MongoDB Enterprise > Show Collections
Col
Test

--Use the Mongodump tool to back up dbking database data:

[Email protected] dump]#/usr/local/mongodb341/bin/mongodump-h 127.0.0.1-d dbking-o/mongodb/dump/
2016-12-29t13:13:17.436+0800 writing Dbking.col to
2016-12-29t13:13:17.436+0800 writing Dbking.test to
2016-12-29t13:13:17.437+0800 Done Dumping Dbking.col (documents)
2016-12-29t13:13:17.437+0800 done Dumping Dbking.test (2 documents)
[email protected] dump]# LL
Total 4
Drwxr-xr-x 2 root root 4096 Dec 13:13 dbking
[email protected] dump]# ll dbking/
Total 16
-rw-r--r--1 root root 782 Dec 13:13 Col.bson
-rw-r--r--1 root root 494 Dec 13:13 Col.metadata.json
-rw-r--r--1 root root from Dec 13:13 Test.bson
-rw-r--r--1 root root 13:13 Test.metadata.json

--Use the Mongorestore tool to restore the backed up dbking database to the DBK library:

MongoDB Enterprise > Show DBS
Admin 0.000GB
Dbking 0.000GB
Local 0.000GB

[Email protected] dump]#/usr/local/mongodb341/bin/mongorestore-h 127.0.0.1-d dbk/mongodb/dump/dbking/
2016-12-29t13:14:55.720+0800 the--db and--collection args should only being used when restoring from a BSON file. Other uses is deprecated and would not be exist in the future; Use--nsinclude instead
2016-12-29t13:14:55.721+0800 building a list of collections to restore from/mongodb/dump/dbking dir
2016-12-29t13:14:55.721+0800 reading metadata for Dbk.col From/mongodb/dump/dbking/col.metadata.json
2016-12-29t13:14:55.722+0800 reading metadata for Dbk.test From/mongodb/dump/dbking/test.metadata.json
2016-12-29t13:14:55.748+0800 restoring Dbk.test From/mongodb/dump/dbking/test.bson
2016-12-29t13:14:55.773+0800 restoring Dbk.col From/mongodb/dump/dbking/col.bson
2016-12-29t13:14:55.774+0800 No indexes to restore
2016-12-29t13:14:55.774+0800 finished restoring dbk.test (2 documents)
2016-12-29t13:14:55.774+0800 restoring indexes for collection Dbk.col from metadata
2016-12-29t13:14:55.809+0800 finished restoring Dbk.col (documents)
2016-12-29t13:14:55.809+0800 Done

MongoDB Enterprise > Show DBS
Admin 0.000GB
DBK 0.000GB
Dbking 0.000GB
Local 0.000GB
MongoDB Enterprise > Use DBK
Switched to DB DBK
MongoDB Enterprise > Show Collections
Col
Test
MongoDB Enterprise > Db.col.find ()
{"_id": ObjectId ("586358cde423fe7088062ab2"), "name": "DBK", "Age": "" "," Job ":" Java Engineer "}
{"_id": ObjectId ("586358d7e423fe7088062ab3"), "name": "DBK", "age": +, "job": "Java Engineer"}
{"_id": ObjectId ("586358dbe423fe7088062ab4"), "name": "DBK", "age": +, "job": "Java Engineer"}
{"_id": ObjectId ("58635ec5e423fe7088062ab5"), "name": "DBK", "Age": "" "," Job ":" Java Engineer "}
{"_id": ObjectId ("58635ec5e423fe7088062ab6"), "name": "DBK", "Age": "" "," Job ":" Java Engineer "}
{"_id": ObjectId ("58635ec5e423fe7088062ab7"), "name": "DBK", "Age": "" "," Job ":" Java Engineer "}
{"_id": ObjectId ("58635ec5e423fe7088062ab8"), "name": "Nope", "Age": "", "" Job ":" Accounting "}
{"_id": ObjectId ("58635ec5e423fe7088062ab9"), "name": "King", "Age": "+", "Job": "CTO"}
{"_id": ObjectId ("58635ec5e423fe7088062aba"), "name": "Chavinking", "Age": "+", "Job": "CTO"}
{"_id": ObjectId ("58635ec5e423fe7088062abb"), "name": "Shu Yongkang", "Age": "+", "Job": "Java Senior engineer"}
{"_id": ObjectId ("58635ec6e423fe7088062abc"), "name": "Zhang Fang", "Age": "A", "Job": "Integration Engineer"}
MongoDB Enterprise > Db.test.find ()
{"_id": ObjectId ("58649abfe2e07cc67bf2ac59"), "name": "Chavin", "Age": "+", "Job": "DBA"}
{"_id": ObjectId ("58649ac5e2e07cc67bf2ac5a"), "name": "DBK", "Age": "+", "Job": "DBA"}

MongoDB Backup and Recovery

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.