mongodb 資料備份,還原筆記

來源:互聯網
上載者:User

標籤:

公司資料庫遷移,所以補充了一下知識:

1 集合的匯入和匯出

 命令列協助 mongoexport --help 

 匯出

 匯出 newsServer 資料庫下  news 集合 

 mongoexport -d newsServer -c news  -o  D:\data\news.json

 同上,但只指定部分欄位(id,title)

 mongoexport -d newsServer -c news -f _id,title -o  D:\data\news.json

 如果需要使用者權限驗證的話,則需要指定使用者及密碼,-u(--user) 後接設定的使用者名稱、 -p接設定的密碼

 mongoexport -u username -p pass -d newsServer -c news -o d:\test.json

 匯入(如果需要認證的話)

 如果是json檔案的話

 mongoimport -u username -p pass  -d newsServer -c news   --file d:\test.json

 如果是csv檔案的話(指定了欄位的話,可以通過--fileds(-f) 指定 要匯入的集合的欄位)

 mongoimport -u username -p pass -d newsServer -c news --type csv --fields _id,from_user_id  --file d:\test.csv

 2 資料庫的匯入和匯出

   匯出

   匯出newsServer資料庫

   mongodump -d newsServer  -o /home/dbbackup

   如果有驗證的話,則需要指定使用者名稱、密碼

   mongodump -u username -p pass -d newsServer -o /home/dbbackup

   匯出,如果需要驗證的話

   mongorestore --port 27017  -u username  -password=pass --drop -d newsServer  /home/dbbackup/newsServer

 

mongodb 資料備份,還原筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.