国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MongoDB > 正文

Windows或Linux系統(tǒng)中備份和恢復(fù)MongoDB數(shù)據(jù)的教程

2020-03-14 13:10:03
字體:
供稿:網(wǎng)友

windows下面mongodb數(shù)據(jù)庫備份和恢復(fù)

我可以講數(shù)據(jù)備份到c:/data/dump目錄下面,首先創(chuàng)建這個路徑。然后進入到mongodb的bin目錄下面

我的是:

C:/Program Files/mongodb/bin

備份腳本是:

//備份mongodump -h 127.0.0.1:27017 -d test -o c:/data/dump

恢復(fù)腳本是:

//恢復(fù) mongorestore -h 127.0.0.1:27017 -d test --directoryperdb c:/data/dump/test

解釋一下用到的命令

  • -h:MongoDB所在服務(wù)器地址
  • -d:需要恢復(fù)的數(shù)據(jù)庫實例,例如:test,當(dāng)然這個名稱也可以和備份時候的不一樣,比如test2
  • -o:備份的數(shù)據(jù)存放位置,例如:c:/data/dump,當(dāng)然該目錄需要提前建立,在備份完成后,系統(tǒng)自動在dump目錄下建立一個test目錄,這個目錄里面存放該數(shù)據(jù)庫實例的備份數(shù)據(jù)。
  • --directoryperdb:備份數(shù)據(jù)所在位置,例如:c:/data/dump/test,這里為什么要多加一個test,而不是備份時候的dump,讀者自己查看提示吧!
  • --drop:恢復(fù)的時候,先刪除當(dāng)前數(shù)據(jù),然后恢復(fù)備份的數(shù)據(jù)。就是說,恢復(fù)后,備份后添加修改的數(shù)據(jù)都會被刪除,慎用哦!

原始解釋:

 -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

linux下面mongodb數(shù)據(jù)庫備份和恢復(fù)

linux下面我們可以創(chuàng)建一個自動備份腳本,可以設(shè)置定時任務(wù),也可以手動備份。我是手動備份的。

首先創(chuàng)建一個sh命令,我是放在home下面的。

vim /home/mongoBeiFen.sh

輸入如下內(nèi)容:

#!/bin/bashshijie=`date +%Y%m%d%H`backmongodbFile=mongodb$shijie.tar.gzcd /home/mongoDbback//usr/local/mongo/bin/mongodump -h 127.0.0.1 --port 27017 -u mongo -p 123456 -d my_mongodb -o my_mongodb_dump/tar czf $backmongodbFile my_mongodb_dump/rm my_mongodb_dump -rf 

解釋:

存放備份的文件夾是/home/mongoDbback/

-u是數(shù)據(jù)庫名用戶名 -p是密碼 -d是數(shù)據(jù)庫名 具體和window差不多,大家可以看下上面windows的解釋。

備份的時候只要運行一下

./mongoBeiFen.sh  

就可以了。

數(shù)據(jù)庫恢復(fù):

/usr/local/mongo/bin/mongorestore -d my_mongodb my_mongodb_dump/my_mongodb/* 

指向每個文件

 

復(fù)制代碼 代碼如下:

/usr/local/mongo/bin/mongorestore -h 127.0.0.1 --port 27017 -- drop --directoryperdb  my_mongodb_dump/my_mongodb

 

 

 

指向一個目錄
有問題的話可以嘗試window的寫法:

 

復(fù)制代碼 代碼如下:

 

/usr/local/mongo/bin/mongorestore -h 127.0.0.1:27017 -d test --drop  --directoryperdb  my_mongodb_dump/my_mongodb

 



注:相關(guān)教程知識閱讀請移步到MongoDB頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 本溪| 枝江市| 元谋县| 晋州市| 宜州市| 即墨市| 万全县| 新闻| 济南市| 高尔夫| 商南县| 东乌珠穆沁旗| 山西省| 连江县| 富平县| 寿宁县| 万全县| 梓潼县| 农安县| 志丹县| 泊头市| 荆门市| 开远市| 乌恰县| 虞城县| 定结县| 天镇县| 贵南县| 鸡泽县| 马山县| 陆川县| 陆丰市| 红原县| 贺州市| 长岭县| 新密市| 哈尔滨市| 宝应县| 神农架林区| 遵义市| 车致|