• Mongodb备份和还原


    MongoDB数据库备份还原可以使用自带的mongodump和mongorestore命令,

    命令行中用到的一些选项代表的含义,如下:
    -h  数据库访问地址

    --port  数据库端口

    -u  用户名

    -p  密码

    --authenticationDatabase  账号认证库(一般账号属于哪个库就是用哪个库认证)

    -d  数据库

    -c  集合(表)

    -o  备份输出目录

    --备份单个表

    /usr/local/mongodb/bin/mongodump -h 192.168.10.17 --port 37017 -u root -p password --authenticationDatabase admin -d testdb -c person -o myTest20190114

    --备份单个库

    /usr/local/mongodb/bin/mongodump -h 192.168.10.17 --port 37017 -u root -p password --authenticationDatabase admin -d testdb -o myTest20190114

    --恢复单个表

    /usr/local/mongodb/bin/mongorestore -h 192.168.10.17 --port 37017 -u root -p password --authenticationDatabase admin -d test2019 -c person myTest20190114/test/person.bson

    --恢复单个库

    /usr/local/mongodb/bin/mongorestore -h 192.168.10.17 --port 37017 -u root -p password  --authenticationDatabase admin -d test201901 backup20190114/test/

    --备份所有库

    /usr/local/mongodb/bin/mongodump -h 192.168.10.17 --port 37017 -u root -p password --authenticationDatabase admin -o myTest20190114

    --恢复所有库

    /usr/local/mongodb/bin/mongorestore -h 192.168.10.17 --port 37017 -u root -p password  --authenticationDatabase admin backup20190114/

    如果是副本集,则副本集备份还原全库稍微有些不同,
    --备份所有库推荐使用添加--oplog参数的命令,这样的备份是基于某一时间点的快照,只能用于备份全部库时才可用,单库和单表不适用:

    /usr/local/mongodb/bin/mongodump -h 192.168.10.17 --port 37017 -u root -p password --authenticationDatabase admin --oplog -o myTest20190114

    --同时,恢复时也要加上--oplogReplay参数,具体命令如下(下面是恢复单库的命令):

    乌龟虽然跑的慢但是比兔子长寿啊
  • 相关阅读:
    python之路3-元组、列表、字典、集合
    python之路2-字符串操作
    Python之路1-变量、数据类型、循环语法
    config模块
    os模块
    logging模块
    控制台报错定位问题所在
    time模块
    random模块
    列表生成
  • 原文地址:https://www.cnblogs.com/nieqibest/p/10342083.html
Copyright © 2020-2023  润新知