成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

MongoDB之備份與恢復

MongoDB數(shù)據(jù)備份
在Mongodb中我們使用mongodump命令來備份MongoDB數(shù)據(jù)。該命令可以導出所有數(shù)據(jù)到指定目錄中。
mongodump命令可以通過參數(shù)指定導出的數(shù)據(jù)量級轉(zhuǎn)存的服務器。
語法
mongodump命令腳本語法如下:
>mongodump -h dbhost -d dbname -o dbdirectory
  ● -h:
MongDB所在服務器地址,例如:127.0.0.1,當然也可以指定端口號:127.0.0.1:27017
  ● -d:
需要備份的數(shù)據(jù)庫實例,例如:test
  ● -o:
備份的數(shù)據(jù)存放位置,例如:c:\data\dump,當然該目錄需要提前建立,在備份完成后,系統(tǒng)自動在dump目錄下建立一個test目錄,這個目錄里面存放該數(shù)據(jù)庫實例的備份數(shù)據(jù)。

備份整個數(shù)據(jù)庫
[root@D2-LZY245 ~]# mongodump
2017-08-18T11:06:39.771+0800    writing admin.system.users to
2017-08-18T11:06:39.772+0800    done dumping admin.system.users (3 documents)
2017-08-18T11:06:39.772+0800    writing admin.system.version to
2017-08-18T11:06:39.773+0800    done dumping admin.system.version (2 documents)
2017-08-18T11:06:39.773+0800    writing hr.emps to
2017-08-18T11:06:39.773+0800    writing hr.emps_infos to
2017-08-18T11:06:39.773+0800    writing hr.inventory to
2017-08-18T11:06:39.773+0800    writing hr.emp to
2017-08-18T11:06:39.774+0800    done dumping hr.emps_infos (11 documents)
2017-08-18T11:06:39.774+0800    writing hr.shop to
2017-08-18T11:06:39.774+0800    done dumping hr.emps (11 documents)
2017-08-18T11:06:39.774+0800    writing hr.t_emps_job to
2017-08-18T11:06:39.775+0800    done dumping hr.emp (9 documents)
2017-08-18T11:06:39.775+0800    writing hr.dept to
2017-08-18T11:06:39.775+0800    done dumping hr.shop (7 documents)
2017-08-18T11:06:39.775+0800    writing hr.news to
2017-08-18T11:06:39.775+0800    done dumping hr.t_emps_job (6 documents)
2017-08-18T11:06:39.775+0800    writing hr.depts to
2017-08-18T11:06:39.775+0800    done dumping hr.news (4 documents)
2017-08-18T11:06:39.775+0800    writing hr.loc to
2017-08-18T11:06:39.776+0800    done dumping hr.dept (5 documents)
2017-08-18T11:06:39.776+0800    writing hr.t_emps_sex to
2017-08-18T11:06:39.776+0800    done dumping hr.depts (2 documents)
2017-08-18T11:06:39.776+0800    writing hr.info to
2017-08-18T11:06:39.776+0800    done dumping hr.loc (2 documents)
2017-08-18T11:06:39.776+0800    writing hr.phones to
2017-08-18T11:06:39.776+0800    done dumping hr.info (0 documents)
2017-08-18T11:06:39.776+0800    writing test.fs.chunks to
2017-08-18T11:06:39.777+0800    done dumping hr.t_emps_sex (2 documents)
2017-08-18T11:06:39.777+0800    writing test.fs.files to
2017-08-18T11:06:39.777+0800    done dumping hr.phones (0 documents)
2017-08-18T11:06:39.777+0800    done dumping test.fs.chunks (0 documents)
2017-08-18T11:06:39.777+0800    done dumping hr.inventory (10 documents)
2017-08-18T11:06:39.777+0800    done dumping test.fs.files (0 documents)

備份結(jié)果
[root@D2-LZY245 ~]# ll dump/
total 4
drwxrwxr-x 2 root root  124 Aug 18 11:06 admin
drwxrwxr-x 2 root root 4096 Aug 18 11:06 hr
drwxrwxr-x 2 root root  106 Aug 18 11:06 test

刪除集合
> use hr
switched to db hr
> db.dept.find();
{ "_id" : ObjectId("599504e70184ff511bf02be1"), "deptno" : 11, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599504e70184ff511bf02be2"), "deptno" : 12, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599504e70184ff511bf02be3"), "deptno" : 13, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599504e80184ff511bf02be4"), "deptno" : 14, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599505240184ff511bf02be5"), "deptno" : 16, "dname" : "財務部", "loc" : "北京" }
> db.dept.drop();
true
> db.dept.find();
>


MongoDB數(shù)據(jù)恢復
mongodb使用 mongorestore 命令來恢復備份的數(shù)據(jù)。
語法
mongorestore命令腳本語法如下:
>mongorestore -h <hostname><:port> -d dbname <path>
  ● --host <:port>, -h <:port>:
MongoDB所在服務器地址,默認為: localhost:27017
  ● --db , -d :
需要恢復的數(shù)據(jù)庫實例,例如:test,當然這個名稱也可以和備份時候的不一樣,比如test2
  ● --drop:
恢復的時候,先刪除當前數(shù)據(jù),然后恢復備份的數(shù)據(jù)。就是說,恢復后,備份后添加修改的數(shù)據(jù)都會被刪除,慎用哦!
  ● <path>:
mongorestore 最后的一個參數(shù),設置備份數(shù)據(jù)所在位置,例如:c:\data\dump\test。
你不能同時指定 <path> 和 --dir 選項,--dir也可以設置備份目錄。
  ● --dir:
指定備份的目錄

恢復被刪除的集合
[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

刪除數(shù)據(jù)庫
> db.dropDatabase()
{ "dropped" : "hr", "ok" : 1 }
> use hr
switched to db hr
> show collections
>

恢復被刪除的數(shù)據(jù)庫
[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

> db.dept.find()
{ "_id" : ObjectId("599504e70184ff511bf02be1"), "deptno" : 11, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599504e70184ff511bf02be2"), "deptno" : 12, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599504e70184ff511bf02be3"), "deptno" : 13, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599504e80184ff511bf02be4"), "deptno" : 14, "dname" : "財務部", "loc" : "北京" }
{ "_id" : ObjectId("599505240184ff511bf02be5"), "deptno" : 16, "dname" : "財務部", "loc" : "北京" }

網(wǎng)站標題:MongoDB之備份與恢復
文章轉(zhuǎn)載:http://jinyejixie.com/article12/iephdc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、Google、網(wǎng)站排名企業(yè)網(wǎng)站制作、建站公司、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司
眉山市| 遂昌县| 商南县| 喀喇沁旗| 南昌县| 哈密市| 海南省| 金溪县| 天峨县| 炎陵县| 新宁县| 佛教| 唐山市| 延川县| 常宁市| 东海县| 莎车县| 郓城县| 太保市| 明光市| 綦江县| 游戏| 聊城市| 札达县| 喀喇沁旗| 昂仁县| 新营市| 花莲市| 柳河县| 宜春市| 贺州市| 兴义市| 永州市| 文昌市| 高安市| 明溪县| 石首市| 沐川县| 乐都县| 始兴县| 新昌县|