RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
解决mongodb数据库备份不完整的方法

小编给大家分享一下解决MongoDB数据库备份不完整的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

十载的柳州网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整柳州建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“柳州网站设计”,“柳州网站推广”以来,每个客户项目都认真落实执行。

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

mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档写入磁盘。

所以一般使用此方法对数据库进行备份时数据是不完整的。

mongodump用法:

C:\Users\Administrator>D:\tool\mongo\bin\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 ( /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
  --authenticationDatabase arg          user source (defaults to dbname)
  --authenticationMechanism arg (=MONGODB-CR)
                                        authentication mechanism
  --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                      each db is in a separate directly
                                        (relevant only if dbpath specified)
  --journal                             enable journaling (relevant only if
                                        dbpath specified)
  -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:指明导出数据的过滤条件

备份的命令:

mongodump -h dbhost -d dbname -o dbdirectory

如果mongodb设置了登录验证,则不能备份成功,报错如下:

assertion: 18 { code: 18, ok: 0.0, errmsg: "auth fails" }

则需要登录,命令如下:

C:\Users\Administrator>D:\tool\mongo\bin\mongodump -username root -password 12345
6 -d test -o d:\tool\mongo\backup

若要备份全部数据库文件可以使用下面的命令进行备份:

C:\Users\Administrator>D:\tool\mongo\bin\mongodump -u root -p 12345

或使用rsync直接拉去数据。

看完了这篇文章,相信你对解决mongodb数据库备份不完整的方法有了一定的了解,想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


网页题目:解决mongodb数据库备份不完整的方法
URL地址:http://sczitong.cn/article/jsodoc.html