av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

MongoDB備份和恢復

本節(jié)我們來介紹一下 MongoDB 中如何對數(shù)據(jù)進行備份與恢復。

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

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

mongodump -h dbhost -d dbname -o dbdirectory

參數(shù)說明如下:

  • -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ù)。

【示例】假設在電腦本地(127.0.0.1)的 27017 端口運行 MongoDB 服務,然后打開命令提示符(CMD)窗口并進入 MongoDB 安裝目錄下的 bin 目錄,最后輸入
mongodump 命令,運行結果如下:

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 服務器上,并將服務器中的所有數(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

恢復數(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


分享名稱:MongoDB備份和恢復
分享網(wǎng)址:http://uogjgqi.cn/article/dhhsioj.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流