hc6538 发表于 2018-10-24 11:20:25

MongoDB基本操作、备份还原及用户管理

#备份本地school数据库  > # mkdir /backup
  # mongodump -d school -o /backup/
  2018-07-14T03:36:44.427-0400    writing school.info to
  2018-07-14T03:36:44.429-0400    done dumping school.info (99 documents)
  #恢复本地school数据库至数据库abc中
  > # mongorestore -d abc --dir=/backup/school
  2018-07-14T03:37:40.174-0400    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
  2018-07-14T03:37:40.174-0400    building a list of collections to restore from /backup/school dir
  2018-07-14T03:37:40.175-0400    reading metadata for abc.info from /backup/school/info.metadata.json
  2018-07-14T03:37:40.187-0400    restoring abc.info from /backup/school/info.bson
  2018-07-14T03:37:40.208-0400    no indexes to restore
  2018-07-14T03:37:40.208-0400    finished restoring abc.info (99 documents)
  2018-07-14T03:37:40.209-0400    done
  #导出本机school数据库info集合
  > # mongoexport -d school -c info -o /backup/info.json
  2018-07-14T03:44:41.610-0400    connected to: localhost
  2018-07-14T03:44:41.613-0400    exported 99 records
  #导入备份数据至本机school数据库user集合
  > # mongoimport -d school -c user --file /backup/info.json
  2018-07-14T03:45:09.300-0400    connected to: localhost
  2018-07-14T03:45:09.330-0400    imported 99 documents
  #导出本机school数据库user1集合id=10的数据
  > # mongoexport -d school -c user -q '{"id":{"$lt":10}}' -o /backup/top10.json
  2018-07-14T03:51:23.968-0400    connected to: localhost
  2018-07-14T03:51:23.969-0400    exported 9 records

页: [1]
查看完整版本: MongoDB基本操作、备份还原及用户管理