通过保管箱同步mongodb数据库 [英] Syncing a mongodb database over dropbox

查看:75
本文介绍了通过保管箱同步mongodb数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在正在开发的本地wep应用程序中使用一个名为"mydb"的mongodb数据库,并希望通过Dropbox同步数据库文件,因此我将在所有开发机上使用它.

I use a mongodb database called 'mydb' in a local wep-app I'm developing and want to sync the db files over Dropbox, so I will have it available on all my development machines.

每当我在数据库中插入一些新数据时,文件"mydb.0"和"mydb.ns"似乎都不会改变.因此,Dropbox不会同步任何内容.这里有什么想法吗?

Whenever I insert some new data in the database, the files 'mydb.0' and 'mydb.ns' don't seem to change. So Dropbox doesn't sync anything. Any ideas here?

我知道这听起来像一个可怕的主意,但是我是唯一的数据库用户,而且我从来没有一次在多台机器上运行数据库.另外,我不与其他任何人共享文件.只是要注意,我可以继续在我刚离开的另一台机器上继续工作.

I know this might sound like a horrible idea, but I'm the only database user and I never run the database on more than one machine at a time. Also I don't share the files with anyone else. It's just to take care that I can continue on another machine exactly where I left.

推荐答案

不幸的是,这听起来像一个可怕的主意.如果Mongo同时在两台计算机上运行该怎么办?这两个数据库极有可能会损坏.更好的方法是编写一个脚本,该脚本使用mongodump和mongorestore将数据库转储到Dropbox并从转储中还原它.但是,您将不得不手动运行它们.

Unfortunately this sounds like a horrible idea. What if Mongo is running on two machines at the same time? Most likely both databases will be corrupted. A better way would be to write a script that used mongodump and mongorestore to dump the database to Dropbox and restore it from the dump. You would have to run these manually though.

您看不到数据库文件有任何更改的原因可能是因为Mongo预分配了它的数据库文件,所以它们的大小永远不会改变,只是里面的内容而已.可能是Dropbox没有发现这一点. Mongo也不会立即写入磁盘.而是使用内存映射的文件,这些文件可能会在以后刷新(尽管应该仅需几秒钟,因此不是原因).

The reason you don't see any changes to the database files is probably because Mongo preallocates its database files, so their size never changes, just the contents inside. It may be that Dropbox doesn't discover this. Mongo also does not write to disk at once. Rather, it uses memory mapped files which may be flushed later (it should be a matter of seconds though so it shouldn't be the cause).

这篇关于通过保管箱同步mongodb数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆