国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

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

MongoDB整庫備份與還原以及單個collection備份、恢復方法

2020-03-14 13:27:16
字體:
供稿:網(wǎng)友
mongodb數(shù)據(jù)庫維護離不開必要的備份、恢復操作,而且一般不會出錯,所以我們在使用的時候大部分時候使用備份和恢復操作就可以了
 
 
mongodump.exe備份的原理是通過一次查詢獲取當前服務(wù)器快照,并將快照寫入磁盤中,因此這種方式保存的也不是實時的,因為在獲取快照后,服務(wù)器還會有數(shù)據(jù)寫入,為了保證備份的安全,同樣我們還是可以利用fsync鎖使服務(wù)器數(shù)據(jù)暫時寫入緩存中。 

 

備份前的檢查
> show dbs
MyDB 0.0625GB
admin (empty)
bruce 0.0625GB
local (empty)
test 0.0625GB
> use MyDB
switched to db MyDB
> db.users.find()
{ "_id" : ObjectId("4e290aa39a1945747b28f1ee"), "a" : 1, "b" : 1 }
{ "_id" : ObjectId("4e2cd2182a65c81f21566318"), "a" : 3, "b" : 5 }
>

整庫備份:
mongodump -h dbhost -d dbname -o dbdirectory
-h:MongDB所在服務(wù)器地址,例如:127.0.0.1,當然也可以指定端口號:127.0.0.1:27017
-d:需要備份的數(shù)據(jù)庫實例,例如:test
-o:備份的數(shù)據(jù)存放位置,例如:c:/data/dump,當然該目錄需要提前建立,在備份完成后,系統(tǒng)自動在dump目錄下建立一個test目錄,這個目錄里面存放該數(shù)據(jù)庫實例的備份數(shù)據(jù)。

mongodump的官方說明(可通過mongodump --help查看):options: --help          produce help message -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 ( /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 --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     if dbpath specified, each db is in a separate              directory --journal        enable journaling -d [ --db ] arg     database to use -c [ --collection ] arg collection to use (some commands) -o [ --out ] arg (=dump) output directory or "-" for stdout -q [ --query ] arg    json query --oplog         Use oplog for point-in-time snapshotting --repair         try to recover a crashed database --forceTableScan     force a table scan (do not use $snapshot)

整庫恢復:
mongorestore -h dbhost -d dbname –directoryperdb dbdirectory
-h:MongoDB所在服務(wù)器地址
-d:需要恢復的數(shù)據(jù)庫實例,例如:test,當然這個名稱也可以和備份時候的不一樣,比如test2
–directoryperdb:備份數(shù)據(jù)所在位置,例如:c:/data/dump/test,這里為什么要多加一個test,而不是備份時候的dump,讀者自己查看提示吧!
–drop:恢復的時候,先刪除當前數(shù)據(jù),然后恢復備份的數(shù)據(jù)。就是說,恢復后,備份后添加修改的數(shù)據(jù)都會被刪除,慎用哦!

mongorestore的官方說明(可通過mongorestore --help查看):options: --help         produce help message -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 ( /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 --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    if dbpath specified, each db is in a separate             directory --journal        enable journaling -d [ --db ] arg     database to use -c [ --collection ] arg collection to use (some commands) --objcheck       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    exclude oplog entries newer than provided timestamp             (epoch[:ordinal]) --keepIndexVersion   don't upgrade indexes to newest version --noOptionsRestore   don't restore collection options --noIndexRestore    don't restore indexes --w arg (=1)      minimum number of replicas per write

單個collection備份:
mongoexport -h dbhost -d dbname -c collectionname -f collectionKey -o dbdirectory
-h: MongoDB所在服務(wù)器地址
-d: 需要恢復的數(shù)據(jù)庫實例
-c: 需要恢復的集合
-f: 需要導出的字段(省略為所有字段)
-o: 表示導出的文件名

mongoexport的官方說明(可通過mongoexport --help查看): --help          produce help message -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 ( /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 --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     if dbpath specified, each db is in a separate              directory --journal         enable journaling -d [ --db ] arg      database to use -c [ --collection ] arg  collection to use (some commands) -f [ --fields ] arg    comma separated list of field names e.g. -f              name,age --fieldFile arg      file with fields names - 1 per line -q [ --query ] arg    query filter, as a JSON string --csv           export to csv instead of json -o [ --out ] arg     output file; if not specified, stdout is used --jsonArray        output to a json array rather than one object per              line -k [ --slaveOk ] arg (=1) use secondaries for export if available, default              true --forceTableScan     force a table scan (do not use $snapshot)

單個collection恢復:
mongoimport -d dbhost -c collectionname –type csv –headerline –file
-type: 指明要導入的文件格式
-headerline: 批明不導入第一行,因為第一行是列名
-file: 指明要導入的文件路徑

mongoimport的官方說明(可通過mongoimport --help查看): --help         produce help message -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 ( /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 --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    if dbpath specified, each db is in a separate             directory --journal        enable journaling -d [ --db ] arg     database to use -c [ --collection ] arg collection to use (some commands) -f [ --fields ] arg   comma separated list of field names e.g. -f name,age --fieldFile arg     file with fields names - 1 per line --ignoreBlanks     if given, empty fields in csv and tsv will be ignored --type arg       type of file to import. default: json (json,csv,tsv) --file arg       file to import from; if not specified stdin is used --drop         drop collection first --headerline      CSV,TSV only - use first line as headers --upsert        insert or update objects that already exist --upsertFields arg   comma-separated fields for the query part of the             upsert. You should make sure this is indexed --stopOnError      stop importing at first error rather than continuing --jsonArray       load a json array, not one item per line. Currently             limited to 16MB.

其他導入與導出操作:

1. mongoimport -d my_mongodb -c user user.dat

參數(shù)說明:

-d 指明使用的庫, 本例中為” my_mongodb”

-c 指明要導出的表, 本例中為”user”

可以看到導入數(shù)據(jù)的時候會隱式創(chuàng)建表結(jié)構(gòu)

2. mongoexport -d my_mongodb -c user -o user.dat

參數(shù)說明:

-d 指明使用的庫, 本例中為” my_mongodb”

-c 指明要導出的表, 本例中為”user”

-o 指明要導出的文件名, 本例中為”user.dat”

從上面可以看到導出的方式使用的是JSON 的樣式.


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
中文字幕av中文字幕| 最近中文字幕大全中文字幕免费| www.色婷婷| 久久五月精品| 成年人在线观看| 天堂资源在线中文| 国产精品免费91| 四虎国产精品永久地址998| 操操操综合网| 国产视频资源| 九色精品视频在线观看| 国产一级免费| √8天堂资源地址中文在线| jizz亚洲大全| 国产超碰97| 国产免费专区| 日本在线视频www鲁啊鲁| √天堂中文在线| 免费高清视频日韩| 一本大道香蕉久久| 国产亚av手机在线观看| а天堂8中文最新版在线官网| 国产精选一区二区三区不卡催乳| 永久免费不卡在线观看黄网站| 国产美女性感在线观看懂色av| 亚洲日本伊人| 尤物在线视频观看| 国产美女福利在线| 国产在线视频精品视频免费看| 中文国产字幕在线观看| 尤物免费看在线视频| 福利视频网站导航| 国产有码在线| 国产美女极品在线| 成av人免费青青久| 毛片网站在线观看| 亚洲成人av高清| 午夜在线观看91| eeuss影院在线| 亚洲色婷婷综合开心网| 在线中文字幕视频观看| 在线观看午夜av| 2018中文字幕在线| 精品国内一区二区三区免费视频| 国产精品186在线观看在线播放| 午夜国产视频| 国产一区电影| 国产黄在线播放| 精品久久亚洲一级α| 91在线视频免费看| 羞羞视频在线观看免费| 麻豆精品永久免费视频| 国产专区在线播放| 国产精品99爱免费视频| 91高清国产| 噜噜噜噜噜在线视频| 国产毛片在线| 国产欧美一区二区三区小说| 国产午夜在线视频| 伊人伊人av电影| 国产永久免费高清在线观看视频| 最近中文字幕大全中文字幕免费| 国产羞羞视频在线观看| 国产对白国语对白| 免费观看v片在线观看| 国产精品偷乱一区二区三区| 91九色在线看| 国产美女极品在线| 亚洲综合激情六月婷婷在线观看| 超碰免费在线| 2020国产在线视频| 狠狠狠狠狠狠操| 国产激情视频在线| 国产免费永久在线观看| 国产精品视频一区二区久久 | 久久国产情侣| 国产精品久久久精品a级小说| av天天在线| 国产精品久久久久白浆| 蜜桃av在线免费观看| av一级在线| 国产成人精品久久一区二区小说| 日本三级视频网站| 国产黄色免费| 国产亚洲精品拍拍拍拍拍| 青青草视频免费在线观看| 午夜在线小视频| 超碰在线97国产| 四虎国产精品永久在线| 精品国产二区三区| 7777在线| 国产欧美一区二区三区小说| 久草网在线视频| 免费a级在线播放| 人人在线视频| 四虎成人免费| www.毛片| 久草网在线视频| 黄色av网站在线免费观看| av在线第一页| www免费在线观看| 在线观看的av| www.av在线| 丁香视频五月| 中文字幕在线第一页| 国产日本韩国在线播放| 国产三级在线观看| 国产精品久久久精品a级小说| 国产极品美女到高潮| 国产超碰精品在线观看| 国产黄色一级电影| 亚洲永久免费网站| 女人色在线免费视频| 久久国产情侣| 国产黄在线观看| 亚洲精品视频区| 日本三级在线视频| 午夜av电影| 国产精品白浆视频免费观看| 91九色在线看| 欧美在线中文| 国产精品国产国产aⅴ| 97影院秋霞午夜在线观看| 四虎在线免费视频| 国产一二三区在线视频| 在线中文av| 国产你懂的在线观看| 精品国产高清a毛片无毒不卡| 免费网站看黄yyy222| 国产女主播在线观看| av在线播放网| 国产麻豆视频| 日本电影在线观看| 国产jizz| 国产视频你懂的| 蜜桃av网站| 亚洲欧美国产另类首页| 国产一级免费看| 非洲黑人最猛性xxxx交| 在线天堂视频| 97一区二区三区| 1区2区视频| 日本中文字幕在线观看| free性亚洲| www在线视频| 日本片在线看| 精品久久九九| 精品国产免费观看一区| 国产精品入口麻豆免费| 99热在线免费播放| 国产九色porn网址| 麻豆国产在线播放| v天堂福利视频在线观看| 影音av资源站| 亚洲精品少妇久久久久久| 99在线免费观看| 亚洲字幕成人中文在线观看| 91在线视频免费看| 樱花草在线观看www| 国产xxx在线| 精品无人乱码| 97高清视频| av文字幕在线观看| 四虎成人免费| 国产在线视频福利| 中文字幕av中文字幕| 国产精品探花在线| 国产黄色片在线播放| 国产精品麻豆一区二区三区| 国产福利片在线| 日本亚洲精品| 国产一级激情| eeuss影院www在线观看| 欧美日韩视频精品二区| 国产69精品久久久久孕妇国产69久久| 麻豆网站在线| 五月天亚洲激情| 精品国语对白精品自拍视| 四虎成年永久免费网站| 尤物视频在线免费观看| 国产成人天天5g影院| 亚洲v片在线观看| 国产污视频在线| 亚洲一区免费在线| 国产精品一区二区三区高清在线| 国产小视频免费在线网址| 992tv在线观看在线播放| 四虎国产精品永久| 国产特级毛片| 久草一本av| 亚洲社区在线| 午夜不卡视频| www免费在线观看| 国产精品久久久久白浆| 日本高清中文字幕在线| 国产天堂在线观看| 日本h视频在线观看| 国产精品国产三级国产试看| 好男人社区在线视频| 在线国产1区|