恢复被删除的集合 [root@D2-LZY245 ~]# mongorestore --db=hr --collection=dept --dir=/root/dump/hr/dept.bson 2017-08-18T11:14:54.397+0800 checking for collection data in /root/dump/hr/dept.bson 2017-08-18T11:14:54.406+0800 reading metadata for hr.dept from /root/dump/hr/dept.metadata.json 2017-08-18T11:14:54.424+0800 restoring hr.dept from /root/dump/hr/dept.bson 2017-08-18T11:14:54.486+0800 no indexes to restore 2017-08-18T11:14:54.486+0800 finished restoring hr.dept (5 documents) 2017-08-18T11:14:54.486+0800 done
删除数据库 > db.dropDatabase() { "dropped" : "hr", "ok" : 1 } > use hr switched to db hr > show collections >
恢复被删除的数据库 [root@D2-LZY245 ~]# mongorestore --db=hr --dir=/root/dump/hr 2017-08-18T11:18:38.570+0800 the --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 instead 2017-08-18T11:18:38.570+0800 building a list of collections to restore from /root/dump/hr dir 2017-08-18T11:18:38.571+0800 reading metadata for hr.emps from /root/dump/hr/emps.metadata.json 2017-08-18T11:18:38.572+0800 reading metadata for hr.emp from /root/dump/hr/emp.metadata.json 2017-08-18T11:18:38.572+0800 reading metadata for hr.inventory from /root/dump/hr/inventory.metadata.json 2017-08-18T11:18:38.572+0800 reading metadata for hr.emps_infos from /root/dump/hr/emps_infos.metadata.json 2017-08-18T11:18:38.578+0800 restoring hr.inventory from /root/dump/hr/inventory.bson 2017-08-18T11:18:38.585+0800 restoring hr.emps from /root/dump/hr/emps.bson 2017-08-18T11:18:38.591+0800 restoring hr.emp from /root/dump/hr/emp.bson 2017-08-18T11:18:38.596+0800 restoring indexes for collection hr.inventory from metadata 2017-08-18T11:18:38.596+0800 no indexes to restore 2017-08-18T11:18:38.596+0800 finished restoring hr.emp (9 documents) 2017-08-18T11:18:38.596+0800 no indexes to restore 2017-08-18T11:18:38.596+0800 finished restoring hr.emps (11 documents) 2017-08-18T11:18:38.596+0800 restoring hr.emps_infos from /root/dump/hr/emps_infos.bson 2017-08-18T11:18:38.605+0800 no indexes to restore 2017-08-18T11:18:38.605+0800 finished restoring hr.emps_infos (11 documents) 2017-08-18T11:18:38.605+0800 finished restoring hr.inventory (10 documents) 2017-08-18T11:18:38.605+0800 reading metadata for hr.t_emps_job from /root/dump/hr/t_emps_job.metadata.json 2017-08-18T11:18:38.605+0800 reading metadata for hr.shop from /root/dump/hr/shop.metadata.json 2017-08-18T11:18:38.606+0800 reading metadata for hr.dept from /root/dump/hr/dept.metadata.json 2017-08-18T11:18:38.606+0800 reading metadata for hr.t_emps_sex from /root/dump/hr/t_emps_sex.metadata.json 2017-08-18T11:18:38.610+0800 restoring hr.t_emps_job from /root/dump/hr/t_emps_job.bson 2017-08-18T11:18:38.616+0800 restoring hr.dept from /root/dump/hr/dept.bson 2017-08-18T11:18:38.638+0800 restoring hr.t_emps_sex from /root/dump/hr/t_emps_sex.bson 2017-08-18T11:18:38.639+0800 restoring hr.shop from /root/dump/hr/shop.bson 2017-08-18T11:18:38.639+0800 no indexes to restore 2017-08-18T11:18:38.639+0800 finished restoring hr.dept (5 documents) 2017-08-18T11:18:38.641+0800 no indexes to restore 2017-08-18T11:18:38.641+0800 finished restoring hr.t_emps_job (6 documents) 2017-08-18T11:18:38.641+0800 reading metadata for hr.depts from /root/dump/hr/depts.metadata.json 2017-08-18T11:18:38.651+0800 reading metadata for hr.news from /root/dump/hr/news.metadata.json 2017-08-18T11:18:38.652+0800 restoring hr.depts from /root/dump/hr/depts.bson 2017-08-18T11:18:38.657+0800 restoring hr.news from /root/dump/hr/news.bson 2017-08-18T11:18:38.660+0800 no indexes to restore 2017-08-18T11:18:38.660+0800 finished restoring hr.t_emps_sex (2 documents) 2017-08-18T11:18:38.661+0800 reading metadata for hr.loc from /root/dump/hr/loc.metadata.json 2017-08-18T11:18:38.661+0800 restoring indexes for collection hr.shop from metadata 2017-08-18T11:18:38.661+0800 no indexes to restore 2017-08-18T11:18:38.661+0800 finished restoring hr.depts (2 documents) 2017-08-18T11:18:38.661+0800 reading metadata for hr.phones from /root/dump/hr/phones.metadata.json 2017-08-18T11:18:38.661+0800 restoring indexes for collection hr.news from metadata 2017-08-18T11:18:38.666+0800 restoring hr.loc from /root/dump/hr/loc.bson 2017-08-18T11:18:38.670+0800 finished restoring hr.shop (7 documents) 2017-08-18T11:18:38.670+0800 reading metadata for hr.info from /root/dump/hr/info.metadata.json 2017-08-18T11:18:38.674+0800 finished restoring hr.news (4 documents) 2017-08-18T11:18:38.679+0800 restoring hr.phones from /root/dump/hr/phones.bson 2017-08-18T11:18:38.684+0800 no indexes to restore 2017-08-18T11:18:38.684+0800 finished restoring hr.loc (2 documents) 2017-08-18T11:18:38.687+0800 restoring hr.info from /root/dump/hr/info.bson 2017-08-18T11:18:38.687+0800 restoring indexes for collection hr.phones from metadata 2017-08-18T11:18:38.697+0800 finished restoring hr.phones (0 documents) 2017-08-18T11:18:38.697+0800 no indexes to restore 2017-08-18T11:18:38.697+0800 finished restoring hr.info (0 documents) 2017-08-18T11:18:38.697+0800 done
> show collections dept depts emp emps emps_infos info inventory loc news phones shop t_emps_job t_emps_sex