備份前的檢查
> 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所在服務器地址,例如:127.0.0.1,當然也可以指定端口號:127.0.0.1:27017
-d:需要備份的數據庫實例,例如:test
-o:備份的數據存放位置,例如:c:/data/dump,當然該目錄需要提前建立,在備份完成后,系統自動在dump目錄下建立一個test目錄,這個目錄里面存放該數據庫實例的備份數據。
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
主站蜘蛛池模板:
诏安县|
邢台市|
凤阳县|
夏津县|
河津市|
长沙市|
金阳县|
德安县|
读书|
兴文县|
沙洋县|
陵水|
镇远县|
石泉县|
章丘市|
宁河县|
万盛区|
二手房|
昌江|
奉节县|
丰顺县|
丹寨县|
蓝山县|
龙川县|
响水县|
望江县|
长海县|
朝阳县|
宁河县|
常宁市|
法库县|
思南县|
柳河县|
郧西县|
城步|
新巴尔虎左旗|
招远市|
平凉市|
崇信县|
红安县|
万荣县|