日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
MongoDB備份和恢復(fù)
本節(jié)我們來介紹一下 MongoDB 中如何對數(shù)據(jù)進行備份與恢復(fù)。

數(shù)據(jù)備份

在 MongoDB 中我們可以使用 mongodump 命令來對 MongoDB 進行數(shù)據(jù)備份,該命令可以導(dǎo)出所有數(shù)據(jù)到指定目錄中,也可以通過參數(shù)將導(dǎo)出數(shù)據(jù)轉(zhuǎn)存的服務(wù)器。其語法格式如下:

mongodump -h dbhost -d dbname -o dbdirectory

參數(shù)說明如下:

  • -h:MongDB 所在服務(wù)器的地址,例如: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è)在電腦本地(127.0.0.1)的 27017 端口運行 MongoDB 服務(wù),然后打開命令提示符(CMD)窗口并進入 MongoDB 安裝目錄下的 bin 目錄,最后輸入
mongodump 命令,運行結(jié)果如下:

C:\Users\79330>D:

D:\>cd install/MongoDB/bin

D:\install\Mongodb\bin>mongodump
2021-02-25T11:22:39.468+0800    writing admin.system.version to
2021-02-25T11:22:39.516+0800    done dumping admin.system.version (1 document)
2021-02-25T11:22:39.516+0800    writing bianchengbang.course to
2021-02-25T11:22:39.517+0800    done dumping bianchengbang.course (3 documents)

mongodump 命令將連接到運行于
127.0.0.1:27017 的 MongoDB 服務(wù)器上,并將服務(wù)器中的所有數(shù)據(jù)備份到 MongoDB 安裝目錄下的 /bin/dump/ 目錄下。

下表中列舉了可以與
mongodump 命令一起使用的參數(shù)列表:

語法 描述 實例
mongodump --host HOST_NAME --port PORT_NUMBER 該命令將備份所有 MongoDB 數(shù)據(jù) mongodump --host runoob.com --port 27017
mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY 該命令將僅備份指定路徑上的指定數(shù)據(jù)庫 mongodump --dbpath /data/db/ --out /data/backup/
mongodump --collection COLLECTION --db DB_NAME 該命令將備份指定數(shù)據(jù)庫的集合 mongodump --collection mycol --db test

恢復(fù)數(shù)據(jù)

要想還原備份的數(shù)據(jù),您可以使用 MongoDB 的
mongorestore 命令,此命令會從備份目錄還原所有數(shù)據(jù),語法格式如下:

mongorestore

【示例】下面通過一個簡單的示例演示一下
mongorestore 命令的使用:

D:\install\Mongodb\bin>mongorestore
2021-02-25T13:26:27.757+0800    using default 'dump' directory
2021-02-25T13:26:27.775+0800    preparing collections to restore from
2021-02-25T13:26:27.776+0800    reading metadata for bianchengbang.course from dump\bianchengbang\course.metadata.json
2021-02-25T13:26:27.791+0800    restoring bianchengbang.course from dump\bianchengbang\course.bson
2021-02-25T13:26:27.800+0800    restoring indexes for collection bianchengbang.course from metadata
2021-02-25T13:26:27.813+0800    finished restoring bianchengbang.course (3 documents)
2021-02-25T13:26:27.814+0800    done


本文標(biāo)題:MongoDB備份和恢復(fù)
轉(zhuǎn)載注明:http://www.5511xx.com/article/dhhsioj.html