centos下mongodb3.2數據庫的備份與恢復初步

數據庫的備份

mongodump -h dbhost -d dbname -o dbdirectory

  • -h MongDB所在服務器地址,在本地操作時服務器默認地址是127.0.0.1。
    這裏寫圖片描述

  • -d 需要備份的數據庫實例。

  • -o 備份的數據存放位置,在該位置下會成與你實例爲名的文件夾,在文件夾下有collection 的bson和json文件。
    這裏寫圖片描述

完成後可以輸入mongodump查看
這裏寫圖片描述

數據庫的恢復

mongorestore -h dbhost -d dbname –dir dbdirectory

  • -h mongodb所在服務器

  • -d 所需要備份的數據庫實例

  • -dir 數據庫備份的位置

  • – drop 先刪除當前數據庫的數據,然後恢復備份的數據

完成後輸入mongorestore查看恢復信息
這裏寫圖片描述

恢復的幾點注意

  • mongorestore can create a new database or add data to an existing database. However, mongorestore performs inserts only and does not perform updates. That is, if restoring documents to an existing database and collection and existing documents have the same value _id field as the to-be-restored documents, mongorestore will not overwrite those documents.(mongorestore可以創建一個新的數據庫或數據添加到現有的數據庫。然而,mongorestore只執行插入和不執行更新。也就是說,如果恢復文件到現有的數據庫,並收集和現有的文件具有相同的值_id字段作爲要被恢復的文件,mongorestore不會覆蓋那些文件。)

  • mongorestore recreates indexes recorded by mongodump.(mongorestore會創建mongodump錄索引。)

  • The data format used by mongodump from version 2.2 or later is incompatible with earlier versions of mongod. Do not use recent versions of mongodump to back up older data stores.(從2.2版本使用mongodump或更高版本的數據格式是與早期版本的mongod不兼容。不要使用mongodump的最新版本的備份舊的數據存儲。)

  • mongorestore does not restore the system.profile collection data; however, if the backup data includes system.profile collection data and the collection does not exist in the target database, mongorestore creates the collection but does not insert any data into the collection.(mongorestore不會恢復system.profile收集數據;然而,如果備份數據包括system.profile集合數據和集合未在目標數據庫中存在,mongorestore創建集合,但不將任何數據插入到集合中。)
    -

參考:
MongoDB 備份(mongodump)與恢復(mongorerstore)
mongorestore

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章