Linux系統(tǒng)中怎么備份和恢復(fù)MongoDB數(shù)據(jù)-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)Linux系統(tǒng)中怎么備份和恢復(fù)MongoDB數(shù)據(jù),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供成都網(wǎng)站建設(shè)、成都網(wǎng)站制作服務(wù)體系,各種行業(yè)企業(yè)客戶(hù)提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。創(chuàng)新互聯(lián)建站將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。

版本:mongodb3.2.6

備份格式:

/data/mongodb/bin/mongodump -h IP --port 端口號(hào) -u 用戶(hù) -p 密碼-d 數(shù)據(jù)庫(kù)名-o 存儲(chǔ)路徑

恢復(fù)格式:

/mnt/mongodb/bin/mongorestore -h IP --port 端口號(hào) -u 用戶(hù)名-p密碼  -d 數(shù)據(jù)庫(kù)名 備份的文件夾名/*

注意,如果mongodb開(kāi)啟了認(rèn)證登錄,那么需要加參數(shù)--authenticationDatabase=admin,

因?yàn)楣P者使用的mongodb開(kāi)啟了認(rèn)證登錄,因此在備份和恢復(fù)中都使用了該參數(shù)。

查看過(guò)相關(guān)資料,說(shuō)是開(kāi)啟了認(rèn)證(auth=true)會(huì)導(dǎo)致數(shù)據(jù)庫(kù)變慢,筆者暫時(shí)未遇到過(guò),推測(cè)應(yīng)該是在一定數(shù)據(jù)量的情況才會(huì)出現(xiàn)。畢竟要過(guò)濾下嘛。如果服務(wù)器是在公網(wǎng),建議還是要開(kāi)啟認(rèn)證的,如果實(shí)在內(nèi)網(wǎng),不用認(rèn)證也行,但是要保證服務(wù)器安全哦,比如指定IP才可連接mongodb數(shù)據(jù)庫(kù)

如果是在本地導(dǎo)入導(dǎo)出,端口也沒(méi)有更改的情況下,-h和--port參數(shù)就不用加了。

還有一個(gè),使用導(dǎo)入導(dǎo)出的用戶(hù)名需要有數(shù)據(jù)庫(kù)管理權(quán)限哦。

解釋一下用到的命令

1. -h:MongoDB所在服務(wù)器地址

2. -d:需要恢復(fù)的數(shù)據(jù)庫(kù)實(shí)例,例如:test,當(dāng)然這個(gè)名稱(chēng)也可以和備份時(shí)候的不一樣,比如test2

3. -o:備份的數(shù)據(jù)存放位置,例如:/data/dump,當(dāng)然該目錄需要提前建立,在備份完成后,系統(tǒng)自動(dòng)在dump目錄下建立一個(gè)test目錄,這個(gè)目錄里面存放該數(shù)據(jù)庫(kù)實(shí)例的備份數(shù)據(jù)。

4. --directoryperdb:備份數(shù)據(jù)所在位置,例如:/data/dump/test,這里為什么要多加一個(gè)test,而不是備份時(shí)候的dump,讀者自己查看提示吧!

5. --drop:恢復(fù)的時(shí)候,先刪除當(dāng)前數(shù)據(jù),然后恢復(fù)備份的數(shù)據(jù)。就是說(shuō),恢復(fù)后,備份后添加修改的數(shù)據(jù)都會(huì)被刪除,慎用哦!

原始解釋?zhuān)?/p>

?

-v [ --verbose ]          be more verbose (include multiple  times

                   for more verbosity e.g. -vvvvv)

--version              print the program's version and  exit

-h [ --host ] arg          mongo host to connect to ( <set

                   name>/s1,s2 for sets)

--port arg             server port. Can also use --host

                   hostname:port

--ipv6               enable IPv6 support (disabled by

                   default)

-u [ --username ] arg        username

-p [ --password ] arg        password

--authenticationDatabase arg    user source (defaults to dbname)

--authenticationMechanism arg  (=MONGODB-CR)

                   authentication mechanism

--dbpath arg            directly access mongod database  files

                   in the given path, instead of

                   connecting to a mongod server -  needs

                   to lock the data directory, so  cannot

                   be used if a mongod is currently

                   accessing the same path

--directoryperdb          each db is in a separate directly

                   (relevant only if dbpath specified)

--journal              enable journaling (relevant only  if

                   dbpath specified)

-d [ --db ] arg           database to use

-c [ --collection ] arg       collection to use (some commands)

--objcheck             validate object before inserting

                   (default)

--noobjcheck            don't validate object before  inserting

--filter arg            filter to apply before inserting

--drop               drop each collection before import

--oplogReplay            replay oplog for point-in-time  restore

--oplogLimit arg          include oplog entries before the

                   provided Timestamp  (seconds[:ordinal])

                   during the oplog replay; the  ordinal

                   value is optional

--keepIndexVersion         don't upgrade indexes to newest  version

--noOptionsRestore         don't restore collection options

--noIndexRestore          don't restore indexes

--w arg (=0)            minimum number of replicas per  write

實(shí)戰(zhàn)操作:

mongodb數(shù)據(jù)庫(kù)的備份:

/data/mongodb/bin/mongodump -u root -p 123456 -d test -o/data/mongodb_$(date +%F) --authenticationDatabase=admin

mongodb數(shù)據(jù)庫(kù)的恢復(fù),筆者的恢復(fù)文件夾路徑為/mnt/mongodb20160905/:

參考如下代碼:

[root@host1 bin]# /mnt/mongodb/bin/mongorestore -uroot –p123456 -d test /mnt/mongodb20160905/ --authenticationDatabase=admin

如果導(dǎo)入有報(bào)錯(cuò):可以在文件夾后面加*試試:

[root@host1 bin]# /mnt/mongodb/bin/mongorestore -uroot –p123456 -d test /mnt/mongodb20160905/* --authenticationDatabase=admin

看完上述內(nèi)容,你們對(duì)Linux系統(tǒng)中怎么備份和恢復(fù)MongoDB數(shù)據(jù)有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

名稱(chēng)欄目:Linux系統(tǒng)中怎么備份和恢復(fù)MongoDB數(shù)據(jù)-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://www.muchs.cn/article18/dpchdp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈企業(yè)網(wǎng)站制作、用戶(hù)體驗(yàn)網(wǎng)站改版、云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)