mongodb 备份和恢复
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,mongodb提供了两个命令用来备份(mongodump)和恢复(mongorestore)数据,数据dump出来的格式是BSON的1.mongodump 备份用法:bin/mongodump [op
千家信息网最后更新 2025年11月07日mongodb 备份和恢复mongodb提供了两个命令用来备份(mongodump)和恢复(mongorestore)数据,数据dump出来的格式是BSON的
1.mongodump 备份
用法:bin/mongodump [options]
举例:将本机6666端口的数据库备份到本机的/data/6666目录下
bin/mongodump --port 6666 --directoryperdb -o /data/6666
connected to: 127.0.0.1:6666
all dbs
DATABASE: test to /data/6666/test
test.system.indexes to /data/6666/test/system.indexes.bson
1 objects
test.ints to /data/6666/test/ints.bson
4 objects
DATABASE: admin to /data/6666/admin
2.mongorestore 恢复
用法:bin/mongorestore [options] [directory or filename to restore from]
举例:将数据库test删除,然后从备份目录恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
> use test
switched to db test
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
admin (empty)
local 4.201171875GB
使用mongorestore恢复
bin/mongorestore -host 127.0.0.1:6666 --directoryperdb /data/6666/
connected to: 127.0.0.1:6666
Wed Jul 6 16:37:33 /data/6666/test/ints.bson
Wed Jul 6 16:37:33 going into namespace [test.ints]
Wed Jul 6 16:37:33 4 objects found
Wed Jul 6 16:37:33 /data/6666/test/system.indexes.bson
Wed Jul 6 16:37:33 going into namespace [test.system.indexes]
Wed Jul 6 16:37:33 { name: "_id_", ns: "test.ints", key: { _id: 1 }, v: 0 }
Wed Jul 6 16:37:33 1 objects found
查看数据库是否恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
mongorestore有个参数--drop,使用此参数,会先将集合里的数据都删除了再恢复
就是说,如果你备份完数据后有新增数据,那么使用--drop,新增的数据会不见
不使用此参数,恢复备份的时候新增的数据依然存在
1.mongodump 备份
用法:bin/mongodump [options]
举例:将本机6666端口的数据库备份到本机的/data/6666目录下
bin/mongodump --port 6666 --directoryperdb -o /data/6666
connected to: 127.0.0.1:6666
all dbs
DATABASE: test to /data/6666/test
test.system.indexes to /data/6666/test/system.indexes.bson
1 objects
test.ints to /data/6666/test/ints.bson
4 objects
DATABASE: admin to /data/6666/admin
2.mongorestore 恢复
用法:bin/mongorestore [options] [directory or filename to restore from]
举例:将数据库test删除,然后从备份目录恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
> use test
switched to db test
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
admin (empty)
local 4.201171875GB
使用mongorestore恢复
bin/mongorestore -host 127.0.0.1:6666 --directoryperdb /data/6666/
connected to: 127.0.0.1:6666
Wed Jul 6 16:37:33 /data/6666/test/ints.bson
Wed Jul 6 16:37:33 going into namespace [test.ints]
Wed Jul 6 16:37:33 4 objects found
Wed Jul 6 16:37:33 /data/6666/test/system.indexes.bson
Wed Jul 6 16:37:33 going into namespace [test.system.indexes]
Wed Jul 6 16:37:33 { name: "_id_", ns: "test.ints", key: { _id: 1 }, v: 0 }
Wed Jul 6 16:37:33 1 objects found
查看数据库是否恢复
> show dbs
admin (empty)
local 4.201171875GB
test 0.203125GB
mongorestore有个参数--drop,使用此参数,会先将集合里的数据都删除了再恢复
就是说,如果你备份完数据后有新增数据,那么使用--drop,新增的数据会不见
不使用此参数,恢复备份的时候新增的数据依然存在
数据
备份
参数
数据库
目录
本机
两个
命令
就是
就是说
时候
格式
端口
先将
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
奉贤区高科技网络技术标准
计算机应用网络技术自考
还原数据库报没有访问
网吧服务器更新游戏快吗
服务器安全性能说明
数据库技术 论文答辩问题
继续播放网络安全手抄报
河南电商软件开发机构
如何做好网络安全保护工作
江岸区电商网络安全维护资费
试谈计算机网络安全问题
网络安全工作领导发言稿
e会计怎么改账套初始数据库
非凡网络安全吗
网络安全管理追责
有关火灾和网络安全
看见网络技术
军人网络安全自查自纠
软件开发行业做账科目定义
小学网络安全公益宣传
迷你世界云服务器名字
数据库建表怎么添加外键
爷爷奶奶网络安全宣传
ai服务器市场发展前景调研报告
国外关于网络安全的书
网络安全法谁负责统筹协调
批量修改oracle数据库
4级数据库怎么考
软件开发需要考什么专业
通信网络安全与管理