MongoDB 数据库备份和恢复说明
2021/9/28 2:13:29
本文主要是介绍MongoDB 数据库备份和恢复说明,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
mongodump
常用选项说明:
--db 指定要备份的数据库,如果不指定,则备份所有数据库 --collection 指定要备份的集合,如果不指定,则备份所有集合 --gzip 压缩输出,文件后缀为.gz --archive 将输出写入指定的归档文件,如果不指定,则写入到stdout --oplog 创建一个名为oplog.bson的文件,作为mongodump输出的一部分。位于输出目录顶层的oplog.bson文件包含在mongodump操作期间发生的oplog条目。此文件提供mongod实例状态的时间点快照。要还原到特定的时间点备份,请将通过此选项创建的输出与mongorestore --oplogReplay结合使用。在更新过程中对数据库所做的更改可能会影响备份的输出。当对mongos实例运行mongodump以转储分片群集的全部内容时,--oplog无效。但是,您可以使用--oplog转储单个分片。--oplog仅适用于维护oplog的节点,这包括副本集的所有成员。--oplog不会转储oplog集合。要将mongodump与--oplog一起使用,必须创建副本集成员的完整转储。如果使用--db和--collection选项来限制要转储的数据,则带有--oplog的mongodump会失败。 --excludeCollection 指定不备份的集合 --excludeCollectionsWithPrefix 指定不备份的集合匹配前缀 --out 指定mongodump将为转储的数据库写入BSON文件的目录。默认情况下,mongodump将输出文件保存在当前工作目录中名为dump的目录中。 -j 指定并行转储的集合数量(默认为 4)
- 备份单个库
mongodump --host=localhost --port=27017 --username=admin --password=password --authenticationDatabase=admin --archive=testdb.gz --gzip --db=testdb
- 备份所有库
mongodump --host=localhost --port=27017 --username=admin --password=password --authenticationDatabase=admin --archive=alldb.gz --gzip
mongorestore
常用选项说明:
--drop 导入数据前,先删除每一个集合 --oplogReplay 重播 oplog 以进行时间点恢复 --noIndexRestore 不恢复索引 --nsInclude 指定要恢复的名称空间匹配 -j 指定要并行恢复的集合数(默认为 4)
- 恢复单个库
mongorestore --username=admin --password=password --authenticationDatabase=admin --noIndexRestore --drop --gzip --archive=testdb.gz mongorestore --username=admin --password=password --authenticationDatabase=admin --noIndexRestore --drop --gzip --archive=alldb.gz --nsInclude="test.*"
- 恢复所有库
mongorestore --username=admin --password=password --authenticationDatabase=admin --noIndexRestore --drop --gzip --archive=alldb.gz
这篇关于MongoDB 数据库备份和恢复说明的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb
- 2024-03-14clickhouse-go