为编程爱好者分享易语言教程源码的资源网
好用的代理IP,游戏必备 ____广告位招租____ 服务器99/年 ____广告位招租____ ____广告位招租____ 挂机,建站服务器
好用的代理IP,游戏必备 ____广告位招租____ 服务器低至38/年 ____广告位招租____ ____广告位招租____ 挂机,建站服务器

网站首页 > 数据库 > MongoDB 正文

mongodb的数据如何备份

三叶资源网 2020-09-07 09:59:35 MongoDB 743 ℃ 0 评论

Mongodb自带了mongodump和mongorestore这两个工具来实现对数据的备份和恢复。

mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档写入磁盘。但是存在的问题时使用mongodump产生的备份不一定是数据库的实时快照,如果我们在备份时对数据库进行了写入操作,则备份出来的文件可能不完全和Mongodb实时数据相等。

mongodump 进行热备份

mongodump工具使用说明:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

$ mongodump --help

Export MongoDB data to BSON files.

  

options:

  --help                   produce help message

  -v [ --verbose ]         be more verbose (include multiple times for more 

                           verbosity e.g. -vvvvv)

  --version                print the program's version and exit

  -h [ --host ] arg        mongo host to connect to ( <set name>/s1,s2 for 

                           sets)

  --port arg               server port. Can also use --host hostname:port

  --ipv6                   enable IPv6 support (disabled by default)

  -u [ --username ] arg    username

  -p [ --password ] arg    password

  --dbpath arg             directly access mongod database files in the given 

                           path, instead of connecting to a mongod  server - 

                           needs to lock the data directory, so cannot be used 

                           if a mongod is currently accessing the same path

  --directoryperdb         if dbpath specified, each db is in a separate 

                           directory

  --journal                enable journaling

  -d [ --db ] arg          database to use

  -c [ --collection ] arg  collection to use (some commands)

  -o [ --out ] arg (=dump) output directory or "-" for stdout

  -q [ --query ] arg       json query

  --oplog                  Use oplog for point-in-time snapshotting

  --repair                 try to recover a crashed database

  --forceTableScan         force a table scan (do not use $snapshot)

参数说明:

-h:指明数据库宿主机的IP

-u:指明数据库的用户名

-p:指明数据库的密码

-d:指明数据库的名字

-c:指明collection的名字(不指定,则所有的集合)

-o:指明到要导出的文件名

-q:指明导出数据的过滤条件

-u:用户名

-p:密码

例如:

1

$ mongodump -h 127.0.0.1:27021 -u 用户名 -p 密码 -d 数据库名 -o 备份文件夹名或者路径

实例:

1

2

3

4

5

6

7

$ mongodump -h 127.0.0.1:27021 -u xx -p xx -d kk -o bak

2018-12-20T09:58:51.473+0800    writing kk.xxxx to 

2018-12-20T09:58:51.473+0800    writing kk.x2 to 

2018-12-20T09:58:51.473+0800    writing kk.x3 to 

2018-12-20T09:58:51.548+0800    done dumping kk.xxxx (1 document)

2018-12-20T09:58:51.550+0800    done dumping kk.x2 (29 documents)

2018-12-20T09:58:51.550+0800    done dumping kk.x3 (34 documents)


Tags:

来源:三叶资源网,欢迎分享,公众号:iisanye,(三叶资源网⑤群:21414575

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

百度站内搜索
关注微信公众号
三叶资源网⑤群:三叶资源网⑤群

网站分类
随机tag
客户端文字游戏账号管理系统TCP挂机心跳通用架构http异步服务总结应用微博降权圆形进度条多进程流量监控聊天工具迅雷Aplayer引擎枚举文件QQ手游授权登录文本型取电脑硬件信息折线图源码新浪PHP服务端API创建窗口略缩图APP登录
最新评论