這里主要介紹使用mongodump和mongorestore方式來(lái)實(shí)現(xiàn)mongodb數(shù)據(jù)庫(kù)的遷移工作
生成備份文件
- 這里所說(shuō)的數(shù)據(jù)遷移主要分為mongodb下多數(shù)據(jù)庫(kù)的遷移和單數(shù)據(jù)庫(kù)遷移,如果是多數(shù)據(jù)庫(kù)的遷移,建議修改mongodb啟動(dòng)方法為非認(rèn)證方式(mongodb.conf中auth=false)重啟,然后再執(zhí)行備份;這里主要介紹單數(shù)據(jù)庫(kù)遷移;
#在備份數(shù)據(jù)庫(kù)文件
/usr/local/mongodb/mongodb-3.4.2/bin/mongodump -h ip:port -u testUser -p testPwd -d testDB -o /tmp/mongodb/test.dmp
#將備份文件導(dǎo)入到需要遷移到的服務(wù)器節(jié)點(diǎn)
scp /tmp/mongodb/test.dmp/* -r root@desIP:/tmp/mongodb/test.dmp
將備份數(shù)據(jù)恢復(fù)到新的mongodb數(shù)據(jù)庫(kù)中
- 如果恢復(fù)的是多數(shù)據(jù)庫(kù),建議這里以非認(rèn)證方式重啟mongodb數(shù)據(jù)庫(kù),這里給出的恢復(fù)單個(gè)數(shù)據(jù)的demo
#恢復(fù)備份數(shù)據(jù)
/usr/local/mongodb/mongodb-3.4.2/bin/mongorestore -u testUser -p testPwd -d testDB /tmp/mongodb/test.dmp/testDB