標籤:
測試環境:windows
一. 匯出資料
F:\DbSoft\soft\master\bin>mongoexport /h 127.0.0.1 /port 50000 /d testdb /c tb1
--type=csv /f _id,name,age /o F:\DbSoft\mongodb\export_file\abc.dat
2015-12-02T15:01:06.787+0800 connected to: 127.0.0.1:50000
2015-12-02T15:01:10.371+0800 exported 110002 records
F:\DbSoft\soft\master\bin>mongoexport /h 127.0.0.1 /port 50000 /d testdb /c tb1
--type=json /f _id,name,age /o F:\DbSoft\mongodb\export_file\abcd.dat
2015-12-02T15:02:01.096+0800 connected to: 127.0.0.1:50000
2015-12-02T15:02:05.959+0800 exported 110002 records
匯入檔案:參數關鍵字不能用-,只能用/.
json格式
F:\DbSoft\soft\master\bin>mongoimport /h 127.0.0.1 /port 50000 /d testdb /c tb2
F:\DbSoft\mongodb\export_file\abcd.dat
2015-12-02T15:09:40.749+0800 connected to: 127.0.0.1:50000
2015-12-02T15:09:43.700+0800 [##......................] testdb.tb2 946.1 KB
/7.7 MB (12.0%)
2015-12-02T15:09:46.681+0800 [########................] testdb.tb2 2.7 MB/7
.7 MB (35.1%)
2015-12-02T15:09:49.681+0800 [###############.........] testdb.tb2 4.8 MB/7
.7 MB (62.9%)
2015-12-02T15:09:52.720+0800 [##################......] testdb.tb2 6.1 MB/7
.7 MB (79.1%)
2015-12-02T15:09:55.577+0800 imported 110002 documents
Csv格式
F:\DbSoft\soft\master\bin>mongoimport /host 127.0.0.1:50000 /d testdb /c tb3 /ty
pe csv /headerline /file F:\DbSoft\mongodb\export_file\abc.dat
2015-12-02T15:27:00.252+0800 connected to: 127.0.0.1:50000
2015-12-02T15:27:03.230+0800 [######..................] testdb.tb3 1.4 MB/5
.3 MB (26.3%)
2015-12-02T15:27:06.261+0800 [############............] testdb.tb3 2.8 MB/5
.3 MB (53.9%)
2015-12-02T15:27:09.242+0800 [##################......] testdb.tb3 4.1 MB/5
.3 MB (78.2%)
2015-12-02T15:27:12.226+0800 [########################] testdb.tb3 5.3 MB/5
.3 MB (100.0%)
2015-12-02T15:27:12.945+0800 imported 110002 documents
備份檔案
F:\DbSoft\soft\master\bin>mongodump /host 127.0.0.1:50000 /d testdb /o F:\DbSof
t\mongodb\export_file\dump1.dat
2015-12-02T15:34:48.542+0800 writing testdb.tb1 to F:\DbSoft\mongodb\export_f
ile\dump1.dat\testdb\tb1.bson
2015-12-02T15:34:48.594+0800 writing testdb.tb2 to F:\DbSoft\mongodb\export_f
ile\dump1.dat\testdb\tb2.bson
2015-12-02T15:34:48.708+0800 writing testdb.ta1 to F:\DbSoft\mongodb\export_f
ile\dump1.dat\testdb\ta1.bson
2015-12-02T15:34:48.710+0800 writing testdb.tb3 to F:\DbSoft\mongodb\export_f
ile\dump1.dat\testdb\tb3.bson
2015-12-02T15:34:51.602+0800 [####....................] testdb.tb1 20778/11
0002 (18.9%)
2015-12-02T15:34:51.650+0800 [########................] testdb.tb2 37789/11
0002 (34.4%)
2015-12-02T15:34:51.664+0800 [############............] testdb.tb3 55181/11
0002 (50.2%)
2015-12-02T15:34:51.678+0800 [........................] testdb.ta1 101/10
0001 (0.1%)
2015-12-02T15:34:51.679+0800
2015-12-02T15:34:52.454+0800 writing testdb.tb3 metadata to F:\DbSoft\mongodb
\export_file\dump1.dat\testdb\tb3.metadata.json
2015-12-02T15:34:52.601+0800 done dumping testdb.tb3 (110002 documents)
2015-12-02T15:34:52.875+0800 writing testdb.system.indexes to F:\DbSoft\mongo
db\export_file\dump1.dat\testdb\system.indexes.bson
2015-12-02T15:34:53.177+0800 writing testdb.tb2 metadata to F:\DbSoft\mongodb
\export_file\dump1.dat\testdb\tb2.metadata.json
2015-12-02T15:34:53.197+0800 writing testdb.tb1 metadata to F:\DbSoft\mongodb
\export_file\dump1.dat\testdb\tb1.metadata.json
2015-12-02T15:34:53.202+0800 done dumping testdb.tb2 (110002 documents)
2015-12-02T15:34:54.265+0800 done dumping testdb.tb1 (110002 documents)
2015-12-02T15:34:54.543+0800 [........................] testdb.ta1 101/1000
01 (0.1%)
2015-12-02T15:34:55.819+0800 writing testdb.ta1 metadata to F:\DbSoft\mongodb
\export_file\dump1.dat\testdb\ta1.metadata.json
2015-12-02T15:34:55.820+0800 done dumping testdb.ta1 (100001 documents)
F:\DbSoft\soft\master\bin>mongodump /host 127.0.0.1:50000 /d testdb /c tb3 /o F
:\DbSoft\mongodb\export_file\dump2.dat
2015-12-02T15:44:49.780+0800 writing testdb.tb3 to F:\DbSoft\mongodb\export_f
ile\dump2.dat\testdb\tb3.bson
2015-12-02T15:44:50.767+0800 writing testdb.tb3 metadata to F:\DbSoft\mongodb
\export_file\dump2.dat\testdb\tb3.metadata.json
2015-12-02T15:44:50.770+0800 done dumping testdb.tb3 (110002 documents)
總結:
1.資料備份可以採用多種格式檔案,支援csv,json等格式。
2.支援dump方式
MongoDB資料備份與恢複