這里主要介紹使用mongodump和mongorestore方式來實現(xiàn)mongodb數(shù)據(jù)庫的遷移工作
生成備份文件
- 這里所說的數(shù)據(jù)遷移主要分為mongodb下多數(shù)據(jù)庫的遷移和單數(shù)據(jù)庫遷移,如果是多數(shù)據(jù)庫的遷移涧团,建議修改mongodb啟動方法為非認(rèn)證方式(mongodb.conf中auth=false)重啟只磷,然后再執(zhí)行備份;這里主要介紹單數(shù)據(jù)庫遷移泌绣;
#在備份數(shù)據(jù)庫文件
/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é)點
scp /tmp/mongodb/test.dmp/* -r root@desIP:/tmp/mongodb/test.dmp
將備份數(shù)據(jù)恢復(fù)到新的mongodb數(shù)據(jù)庫中
- 如果恢復(fù)的是多數(shù)據(jù)庫钮追,建議這里以非認(rèn)證方式重啟mongodb數(shù)據(jù)庫,這里給出的恢復(fù)單個數(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