mongo备份恢复

本文介绍了MongoDB中几种常见的备份与恢复方法,包括使用mongoexport与mongoimport进行数据导出导入,使用mongodump与mongorestore进行数据库的完全备份与恢复,以及Percona Server for MongoDB支持的在线热备份技术createBackup命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.mongoexport 与mongoimport 

export

mongoexport --host "localhost:27017" --username="user" --password="xxxx" --authenticationDatabase=testdb --db=testdb --collection=testc --out /back/testc.josn

import

mongoimport --host "localhost:27017" --username="user" --password="xxxx" --authenticationDatabase=testdb --db=testdb_v3 --collection=testc --file /back/testc.josn

 

2.mongodump与mongostore

mongodump -h "localhost:port" --username="user" --password="pwd" --authenticationDatabase=authdb -d dbname -o /root/back

restory
mongorestore -h "localhost:port" --username="user" --password="pwd" --authenticationDatabase=authdb -d dbname --dir /root/back/fission_balance/

 

3.hot backup   -- Percona Server for MongoDB支持,社区版本不支持

Percona Server for MongoDB includes an integrated open-source hot backup system for the default WiredTiger and
alternative MongoRocks storage engine. It creates a physical data backup on a running server without notable performance
and operating degradation.
To take a hot backup of the database in your current dbpath, run the createBackup command as administrator
on the admin database and specify the backup directory.

1 > use admin
2 switched to db admin
3 > db.runCommand({createBackup: 1, backupDir: "/my/backup/data/path"})
4 { "ok" : 1 }
View Code

If the backup was successful, you should receive an { "ok" : 1 } object. If there was an error, you will receive
a failing ok status with the error message, for example:

1 > db.runCommand({createBackup: 1, backupDir: ""})
2 { "ok" : 0, "errmsg" : "Destination path must be absolute" }
View Code

备份恢复相关参考博客

MongoDB在线热备神器-createBackup

从炉石传说数据库故障谈谈MongoDB的数据库备份和恢复手段

Mongodump的archive(归档)模式原理解析

转载于:https://www.cnblogs.com/geek-ace/p/7692999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值