Syncing a mongodb database over dropbox

混江龙づ霸主 提交于 2019-11-30 05:00:00

问题


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.

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.


回答1:


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.

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).



来源:https://stackoverflow.com/questions/5607146/syncing-a-mongodb-database-over-dropbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!