mongodb数据迁移2种方式比较
生活随笔
收集整理的這篇文章主要介紹了
mongodb数据迁移2种方式比较
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
環(huán)境說(shuō)明:bbs數(shù)據(jù)采集的數(shù)據(jù)越來(lái)越多,目前是50G,每天大概以200W的數(shù)據(jù)量增長(zhǎng)。而當(dāng)前服務(wù)器1.2上面的空間不足,需要把數(shù)據(jù)遷移到空間足夠大的1.3上面去
嘗試了2種方式對(duì)數(shù)據(jù)進(jìn)行遷移,一種是rsync,直接拉取數(shù)據(jù);另一種是使用mongodump/mongorestore
1.rsync
操作步驟:
1.2:
[mongodb]
path = /data1/mongodb/data
hosts allow = 192.168.1.0/24
read only = no
write only = no
1.3:
rsync -avz root@192.168.1.2::mongodb/dbname /data/mongodb-linux-x86_64-1.8.1/data/
chown -R mongodb:mongodb /data/mongodb-linux-x86_64-1.8.1/data/
使用時(shí)間:50分鐘
到目標(biāo)服務(wù)器數(shù)據(jù):50G
優(yōu)點(diǎn):使用時(shí)間短
缺點(diǎn):需要配置rsync,數(shù)據(jù)占用的空間大(數(shù)據(jù)原封不動(dòng)的拉取過來(lái),包括碎片)
2.mongodump/mongorestore
操作步驟:
mongodump:
/data/PRG/mongodb/bin/mongodump --host 192.168.1.2:27017 -d dbname -uuername -ppasswd -o /data/mongodb-linux-x86_64-1.8.1/data/ --directoryperdb
mongorestore:
/data/mongodb-linux-x86_64-1.8.1/bin/mongorestore --dbpath /data/mongodb-linux-x86_64-1.8.1/data/ --directoryperdb /data/dbname/
chown -R mongodb:mongodb /data/mongodb-linux-x86_64-1.8.1/data/
使用時(shí)間:35(mongodump)+90(mongorestore)
到目標(biāo)服務(wù)器數(shù)據(jù):20G(需要的空間大大減小,拉取過程中相當(dāng)于做了一次碎片整理)
優(yōu)點(diǎn):遷移到新服務(wù)器的數(shù)據(jù)經(jīng)過了整理,需要空間大大減小
缺點(diǎn):需要時(shí)間長(zhǎng)
數(shù)據(jù)遷移時(shí)需要停mongo進(jìn)行操作,而2種方式各有優(yōu)缺點(diǎn),如果可以忽略操作時(shí)間內(nèi)的數(shù)據(jù)的話,那么使用第2種方式會(huì)比較好(已經(jīng)有不少例子因?yàn)樗槠瑤?lái)嚴(yán)重的后果)
嘗試了2種方式對(duì)數(shù)據(jù)進(jìn)行遷移,一種是rsync,直接拉取數(shù)據(jù);另一種是使用mongodump/mongorestore
1.rsync
操作步驟:
1.2:
[mongodb]
path = /data1/mongodb/data
hosts allow = 192.168.1.0/24
read only = no
write only = no
1.3:
rsync -avz root@192.168.1.2::mongodb/dbname /data/mongodb-linux-x86_64-1.8.1/data/
chown -R mongodb:mongodb /data/mongodb-linux-x86_64-1.8.1/data/
使用時(shí)間:50分鐘
到目標(biāo)服務(wù)器數(shù)據(jù):50G
優(yōu)點(diǎn):使用時(shí)間短
缺點(diǎn):需要配置rsync,數(shù)據(jù)占用的空間大(數(shù)據(jù)原封不動(dòng)的拉取過來(lái),包括碎片)
2.mongodump/mongorestore
操作步驟:
mongodump:
/data/PRG/mongodb/bin/mongodump --host 192.168.1.2:27017 -d dbname -uuername -ppasswd -o /data/mongodb-linux-x86_64-1.8.1/data/ --directoryperdb
mongorestore:
/data/mongodb-linux-x86_64-1.8.1/bin/mongorestore --dbpath /data/mongodb-linux-x86_64-1.8.1/data/ --directoryperdb /data/dbname/
chown -R mongodb:mongodb /data/mongodb-linux-x86_64-1.8.1/data/
使用時(shí)間:35(mongodump)+90(mongorestore)
到目標(biāo)服務(wù)器數(shù)據(jù):20G(需要的空間大大減小,拉取過程中相當(dāng)于做了一次碎片整理)
優(yōu)點(diǎn):遷移到新服務(wù)器的數(shù)據(jù)經(jīng)過了整理,需要空間大大減小
缺點(diǎn):需要時(shí)間長(zhǎng)
數(shù)據(jù)遷移時(shí)需要停mongo進(jìn)行操作,而2種方式各有優(yōu)缺點(diǎn),如果可以忽略操作時(shí)間內(nèi)的數(shù)據(jù)的話,那么使用第2種方式會(huì)比較好(已經(jīng)有不少例子因?yàn)樗槠瑤?lái)嚴(yán)重的后果)
轉(zhuǎn)載于:https://blog.51cto.com/lynnteng0/800724
超強(qiáng)干貨來(lái)襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的mongodb数据迁移2种方式比较的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android深入浅出系列之Androi
- 下一篇: virtual function的一些心