• 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
    
  • 相关阅读:
    网页制作--标签,表格,表单,框架
    sql数据库框架
    数据库的触发器
    数据库的复制与附加
    sql数据库随笔
    sql常用函数
    sql数据类型、约束
    sql数据库查询
    数据库增删改查
    数据库基本概念
  • 原文地址:https://www.cnblogs.com/harpz/p/15932971.html
Copyright © 2020-2023  润新知