备份

mongodump --host=mongodb.example.net --port=27017 --username=user --password="pass" --authenticationDatabase=test --db=test --collection=myCollection --oplog --out=/opt/backup/test-2013-10-24
  • --host:默认 localhost:27017 ,指定连贯主机
  • --port:默认 27017 ,指定连贯端口
  • --username:指定进行身份验证的用户名
  • --password:指定进行身份验证的明码
  • --authenticationDatabase:指定进行身份验证的数据库,如果未指定,则假如为导出的数据库
  • --db:指定要备份的数据库,默认为所有数据库
  • --collection:指定要备份的汇合,默认为所有汇合
  • --oplog:创立一个 oplog.bson 文件作为备份的内容,蕴含 mongodump 备份操作期间产生的操作日志。--oplog 不能与 --db 和 --collection 一起应用,必须创立残缺的转储才能够应用。
  • --out:默认当前目录下的 dump 目录,指定备份保留的目录。应用"-"代替门路能够发送到规范输入。--out 不能与 --archive 一起应用。

还原

mongorestore --host=mongodb1.example.net --port=3017 --username=user --password="pass" --authenticationDatabase=test_bak --oplogReplay --drop /opt/backup/test-2013-10-24/
  • --host:默认 localhost:27017 ,指定连贯主机
  • --port:默认 27017 ,指定连贯端口
  • --username:指定进行身份验证的用户名
  • --password:指定进行身份验证的明码
  • --authenticationDatabase:指定进行身份验证的数据库
  • --oplogReplay:复原数据库转储后,从bson文件从新执行oplog内容。--oplogReplay 不能与 --db --collection --nsInclude --nsExclude 一起应用,必须还原残缺的转储才能够应用。
  • --drop:还原汇合之前,从指标数据库中删除汇合。