Ubuntu 备份、恢复及迁移MongoDB数据库

Posted by 姚飞亮 on 2019-01-17

Ubuntu 备份、恢复及迁移MongoDB数据库

备份MongoDB数据库 mongodump

1
sudo mkdir /var/backups/mongobackups
1
2
mongodump -h 127.0.0.1 --port 27017  -d test -u test -p Yao123 -o /var/backups/mongobackups
其中-h 是数据库地址,127.0.0.1 -d 是数据库名字 context -o 存储的地址 如果省略就在当前目录下保存 -u 是用户名 -p 是密码

参数说明:

1
2
3
4
5
6
7
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件

恢复及迁移MongoDB数据库 mongorestore

1
mongorestore  /var/backups/mongobackups/test
1
2
3
4
5
6
7
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要备份的文件名
-q:指明备份数据的过滤条件


Ω