mongodb还原数据到docker上

起因

因为我本地安装了mongodb5版本,在给领导提交脚本的时候出现不兼容的问题。
领导让我装mongodb4版本,卸载太麻烦了,于是想到使用docker安装一个4版本。
下面是在windowsdocker备份还原mongodb的方法

备份还原

安装mongdb-database-tool(不安装命令无法执行)

https://www.mongodb.com/try/download/database-tools

mongdb-database-tool地址

备份命令

备份命令直接在cmd或者powershell执行

mongodump -h 127.0.0.1:27017 -d xykj_cpl -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_admin -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_analyze  -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_xykj_cpl  -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_pay   -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_theme  -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_user   -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_vip  -o "D:\dbback"
mongodump -h 127.0.0.1:27017 -d xykj_analyze  -o "D:\dbback"

还原命令

还原的时候不是在mongo终端操作,需要在其他终端,比如cmd,powershell

windows还原操作

mongorestore -h 127.0.0.1:27017 -d xykj_cpl -u root -p test123 --dir D:\dbback\xykj_cpl --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_admin -u root -p test123 --dir D:\dbback\xykj_admin --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_analyze -u root -p test123 --dir D:\dbback\xykj_analyze --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_xykj_cpl -u root -p test123 --dir D:\dbback\xykj_xykj_cpl --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_pay -u root -p test123 --dir D:\dbback\xykj_pay --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_theme -u root -p test123 --dir D:\dbback\xykj_theme --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_user -u root -p test123 --dir D:\dbback\xykj_user --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_vip -u root -p test123 --dir D:\dbback\xykj_vip --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_vip2020 -u root -p test123 --dir D:\dbback\xykj_vip2020 --authenticationDatabase admin

docker还原操作

  • 进入wsl
  • docker exec -it ContainerID bin/bash
  • 先创建备份文件夹 mkdir dbback
  • 复制备份到docker container对应的文件夹下创建的dbback目录
  • cd data/dbback/ 到备份文件目录
  • 执行下面还原命令
mongorestore -h 127.0.0.1:27017 -d xykj_xykj_cpl -u root -p test123 --dir xykj_xykj_cpl --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_cpl -u root -p test123 --dir xykj_cpl --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_admin -u root -p test123 --dir xykj_admin --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_analyze -u root -p test123 --dir xykj_analyze --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_pay -u root -p test123 --dir xykj_pay --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_theme -u root -p test123 --dir xykj_theme --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_user -u root -p test123 --dir xykj_user --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_vip -u root -p test123 --dir xykj_vip --authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d xykj_vip2020 -u root -p test123 --dir xykj_vip2020 --authenticationDatabase admin
posted @   blues小曾  阅读(161)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示