1. mongodb數(shù)據(jù)庫(kù)導(dǎo)出備份語(yǔ)法:
mongodump -h dbhost -d dbname -o dbdirectory
參數(shù)說(shuō)明:
- -h: MongDB所在服務(wù)器地址,例如:
127.0.0.1,當(dāng)然也可以指定端口號(hào):127.0.0.1:27017 - -d: 需要備份的數(shù)據(jù)庫(kù)實(shí)例,例如:
test - -o: 備份的數(shù)據(jù)存放位置,例如:
/home/mongodump/,當(dāng)然該目錄需要提前建立,這個(gè)目錄里面存放該數(shù)據(jù)庫(kù)實(shí)例的備份數(shù)據(jù)。
mongodb數(shù)據(jù)庫(kù)恢復(fù)導(dǎo)入語(yǔ)法:
mongorestore -h dbhost -d dbname dbdirectory
參數(shù)或名:
- -h: MongoDB所在服務(wù)器地址
- -d: 需要恢復(fù)的數(shù)據(jù)庫(kù)實(shí)例,例如:test,當(dāng)然這個(gè)名稱也可以和備份時(shí)候的不一樣,比如test2
- --drop: 恢復(fù)的時(shí)候,先刪除當(dāng)前數(shù)據(jù),然后恢復(fù)備份的數(shù)據(jù)。就是說(shuō),恢復(fù)后,備份后添加修改的數(shù)據(jù)都會(huì)被刪除,慎用!
mongodb數(shù)據(jù)庫(kù)有用戶名密碼認(rèn)證的參考下面命令
mongodump -h localhost:27017 -d test -u test -p testpwd -o D:\dump --authenticationDatabase admin
mongorestore -h localhost:27017 -d test -c order --dir d:\dump\test\test.bson -u test -p testpwd --authenticationDatabase admin
注意:在數(shù)據(jù)庫(kù)中包含權(quán)限是需要完成備份和導(dǎo)入是需要在指令后面加上--authenticationDatabase admin