1.数据备份(数据库)

使用mongodump进行mongo数据库备份:
命令:mongodump --host localhost -u root -p root -d vlog -o /root/dump --authenticationDatabase admin
参数解释:
–host: 服务器名称或IP:PORT
-u: 用户名
-p: 密码
-d: 数据库dbname
-o:导出文件的存放路径
–authenticationDatabase admin: 添加–authenticationDatabase admin 参数制定认证数据库
解决报错:Failed: can’t create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism “SCRAM-SHA-1”: (AuthenticationFailed) Authentication failed.
在这里插入图片描述

2.数据恢复(数据库)

命令:mongorestore -h localhost -u root -p root123 --db admin dump/test_jia/ --authenticationDatabase admin
-h: 服务器名称或IP:PORT
-u: 用户名
-p: 密码
–db: 数据库dbname,需要恢复的数据库名称
dump/test_jia/:恢复文件的存储路径
–authenticationDatabase admin: 添加–authenticationDatabase admin 参数制定认证数据库
报错场景:
1.-u root -p root123 --authenticationDatabase admin三个参数都未设置时报错:
Failed: error getting auth version of server: (Unauthorized) command getParameter requires authentication
2.-u root -p root123或–authenticationDatabase admin未设置时报错:
error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism “SCRAM-SHA-1”: (AuthenticationFailed) Authentication failed.
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐