mongoDB遷移工具mongo-migrate使用介紹

chenfeng發表於2015-12-29

功能

將一個叢集,複製集或者單機 mongoDB 中的一個集合的資料,遷移到另一個叢集,複製集或者單機 mongoDB. 如果源集合使用了分片,會在目標自動分片,並按照源集合的 chunk 進行 split 與隨機 movechunk. 如果源集合存在索引,會複製索引. 如果源使用了複製集,會使用 oplog 做增量遷移.

引數

--src "ip:host" 源地址 --srcDB "db name" 要遷移的資料庫名稱 --srcColl "collection name" 要遷移的集合名稱 --srcUserName "user name" 源 auth 使用者名稱 --srcPassWord "password" 源 auth 密碼 --dest "ip:host" 目標地址 --destDB "db name" 目標資料庫名稱 --destColl "collection name" 目標集合名稱 --destUserName "user name" 目標 auth 使用者名稱 --destPassWord "password" 目標 auth 密碼 --findAndInsertWorkerNum 10 複製資料時併發讀寫goroutine 數目

--writeAck 1 "same with w param in other driver" --writeMode "Majority" "see mongodb doc if needed" --journal true "whether use journal" --fsync false "whether wait for fsync for each write"

已知bug

  1. 複製索引時,文字索引不能正常建立

範圍遷移使用

範圍遷移為應對資料量較多時的方法,使用有許多限制,相關引數如下: --minKey 範圍最小值(包含) --maxKey 範圍最大值(不包含) --keyType "int or string" key 的型別,只支援數字與字串 這裡的範圍是進行 shardCollection 時第一個 key 的範圍 範圍遷移的一些行為:

  • 如果目標 ns 已經分片,則不進行分片 以及 預分配操作.
  • 如果指定了範圍為 int 型別的0 - 100 ,則所有非 int 型的資料不能被遷移.
  • int 型包含 int64與 float64,對應於在 mongoDB 中直接寫入{ key:1 } 與 {key:NumberLong:1}

額外引數,-- withOutKeyType string 一般用來配合範圍遷移使用,使用場景: 有集合, shardkey 的第一個 key 99% 都為數字,先透過範圍遷移: 0-100,100-200...將99% 資料遷移. 再使用非範圍遷移,並指定 --withOutKeyType "int" 將剩餘部分資料遷移.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-1966782/,如需轉載,請註明出處,否則將追究法律責任。

相關文章