1.备份
进入mongodb/bin目录
./mongodump --host 10.0.0.x1 --port 27017 --db my_db_name --collection my_collection_name --out my_bak_path --gzip > my_bak_path/dumpoutput.log 2>&1 &
查询备份帮助 ./mongodump --help
2.还原
进入mongodb/bin目录
./mongorestore --host 10.0.0.x2 --port 27018 --db my_db_name --collection my_collection_name --gzip --batchSize=100 --nsInclude 'my_collection_name.*' my_bak_path/my_collection_name/my_collection_name.bson.gz > my_collection_name/restoreoutput.log 2>&1 &
查询还原帮助 ./mongorestore --help
注: batchSize 为额外参数,防止还原时,内存占用太高。 batchSize参数是否生效在mongodb服务的log文件中可以查阅。