mongodb数据库的备份和还原

-

数据库导出备份语法:

mongodump -h -dbhost -d dnname -o dbdirectory
参数说明:
    -h:MongoDB 所在服务器地址,例如127.0.0.1 ,当然也可以指定端口号:127.0.0.1:27017
    -d:需要备份的数据库实例,例如test
    -o:备份的数据存放位置,例如:/home/mongodump/,当然该目录需要提前建立,这个目录里面存放该数据库实例的内粉数据

假如要把itying数据库备份 到D:mongodbdata 目录下

mongodump -h 127.0.0.1 -d itying -o D:mongodbdata

导入语法:

mongorestore -h dbhost -d dbname dbdirectory
参数说明:
    -h:MongoDB所在服务器地址
    -d:需要恢复的数据库实例,例如itying
    --drop:恢复的时候,先删除当前数据库在导入数据,慎用

例如:

mongorestore -h 127.0.0.1 -d itying D:mongodbdata
有用户名认证的参考下面命令
mongodump -h localhost:27017 -d itying -u ityingadmin -p 123456 -o D:mongodbdata

mongorestore
-h localhost:27017 -d itying -c user --dir D:mongodbdata

-

原文地址:https://www.cnblogs.com/fqh123/p/15208295.html