Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syncing a mongodb database over 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.

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.

like image 923
Michiel Borkent Avatar asked Apr 09 '11 19:04

Michiel Borkent


People also ask

How do I sync MongoDB?

Logical Initial Sync Process When you perform a logical initial sync, MongoDB: Clones all databases except the local database. To clone, the mongod scans every collection in each source database and inserts all data into its own copies of these collections.

Does MongoDB store data in files?

MongoDB stores data and indexes on disk in a compressed binary format.


1 Answers

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

like image 83
Theo Avatar answered Nov 08 '22 23:11

Theo