Mongodb Backup and Recovery

Source: Internet
Author: User

One, backup data

[Email protected] ~]# mongodump-h localhost-d admin-o/home/qiuyuetao/2017-08-10t16:07:51.188+0800writing Admin.system.users to 2017-08-10t16:07:51.188+0800done dumping admin.system.users (3 documents) 2017-08-10t16:0 7:51.189+0800writing admin.system.version to 2017-08-10t16:07:51.190+0800done dumping admin.system.version (2 Documents) 2017-08-10t16:07:51.190+0800writing Admin. Firstcollection to 2017-08-10t16:07:51.190+0800writing Admin. Student to 2017-08-10t16:07:51.191+0800done dumping admin. Student (0 documents) 2017-08-10t16:07:51.191+0800done dumping Admin. Firstcollection (1 document)

Second, view the database and clear the data

> Show dbsadmin 0.000GBlocal 0.000GBmongodb 0.000gb> use adminswitched to DB admin> db.getcollectionnames ( # #查看admin库下有哪些表 ["Firstcollection", "Student", "System.users", "system.version"]> db. Firstcollection.find () #查看表数据 {"_id": ObjectId ("598c0c7f866edf4d34ddfe8e"), "name": "Jack", "Age": $ #清空表数据 > DB. Firstcollection.remove ({name: "Jack"}) Writeresult ({"nremoved": 1}) > > DB. Firstcollection.find () > ># #已经清空数据 > > Exitbye[[email protected] ~]# [[email protected] ~]#

Iii. Recovery of data

[[email protected] ~]# mongorestore -h localhost:27017 -d admin /home/ Qiuyuetao/admin2017-08-10t16:13:34.157+0800the --db and --collection args should  only be used when restoring from a BSON file. Other  Uses are deprecated and will not exist in the future; use  --nsinclude instead2017-08-10t16:13:34.158+0800building a list of collections  to restore from /home/qiuyuetao/admin dir2017-08-10T16:13:34.197+0800reading  Metadata for admin. firstcollection from /home/qiuyuetao/admin/firstcollection.metadata.json2017-08-10t16:13:34.197+ 0800restoring admin. Firstcollection from /home/qiuyuetao/admin/firstcollection.bson2017-08-10t16:13:34.199+0800reading  metadata for admin. Student from /home/qiuyuetao/admin/studenT.metadata.json2017-08-10t16:13:34.207+0800restoring admin. Student from /home/qiuyuetao/admin/student.bson2017-08-10t16:13:34.353+0800no indexes to  restore2017-08-10t16:13:34.353+0800finished restoring admin. firstcollection  (1 document) 2017-08-10t16:13:34.353+0800no indexes to  Restore2017-08-10t16:13:34.353+0800finished restoring admin. student  (0 documents) 2017-08-10t16:13:34.353+0800restoring users from /home/qiuyuetao /admin/system.users.bson2017-08-10t16:13:34.787+0800done  # #恢复完成 [[email protected] ~]# mongo  Login Verification mongodb shell version v3.4.6connecting to: mongodb:// 127.0.0.1:27017mongodb server version: 3.4.6server has startup warnings:  2017-07-24t14:29:11.787+0800 i storage  [initandlisten] 2017-07-24t14:29:11.787+0800  I STORAGE  [initandlisten] ** warning: using the xfs filesystem is strongly recommended with  the wiredtiger storage engine2017-07-24t14:29:11.787+0800 i storage  [ initandlisten] **          see http:// dochub.mongodb.org/core/prodnotes-filesystem2017-07-24t14:29:12.460+0800 i control  [ initandlisten] 2017-07-24t14:29:12.460+0800 i control  [initandlisten] **  warning: access control is not enabled for the database.2017-07-24t14 :29:12.460+0800 i control  [initandlisten] **           read and write access to data and configuration  is unrestricted.2017-07-24T14:29:12.460+0800 I CONTROL  [initandlisten]  2017-07-24t14:29:12.460+0800 i contrOl  [initandlisten] 2017-07-24t14:29:12.461+0800 i control  [initandlisten]  ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is  ' always '. 2017-07-24t14 :29:12.461+0800 i control  [initandlisten] **         We suggest setting it to  ' Never ' 2017-07-24t14:29:12.461+0800 i  control  [initandlisten] 2017-07-24t14:29:12.461+0800 i control  [ initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/defrag is  ' always '. 2017-07-24t14:29:12.461+0800 i control  [initandlisten] **         We suggest setting it to  ' Never ' 2017-07-24t14:29:12.461+0800  I CONTROL  [initandlisten] 2017-07-24T14:29:12.461+0800 I CONTROL   [initandlisten] ** wArning: soft rlimits too low. rlimits set to 1024 processes,  65535 files. number of processes should be at least 32767.5  : 0.5 times number of files.2017-07-24t14:29:12.461+0800 i control   [initandlisten] > use adminswitched to db admin> db. Firstcollection.find ()   # #查看表的内容, restored {  "_id"  : objectid ("598c0c7f866edf4d34ddfe8e"),   "name"  :  "Jack",  "Age"  : 22 }

At this point, MongoDB backup and recovery testing completed, there are questions message.

This article is from the "funny Brother Notes" blog, be sure to keep this source http://qiuyt.blog.51cto.com/1229789/1955172

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.