Option 1:
mongodump and mongorestore. These are two tools that are in the bin directory of the Mongodb installation. You could write a script to automate the dump on one side, and Restore on the other. There is an article (in English) about the backup with these tools here. Bank service (mongod) needs to be active on both machines in this case.
Example of mongodump:
- Linux:
mongodump -h localhost --gzip -o /Backups/MongoDB/dados
- Windows:
mongodump /h localhost /gzip /o C:\Backups\MongoDB\dados
The above command backs up all databases of a Mongodb server running on the local computer, at the default port (27017). Compact this backup and put the data in the /Backups/Mongodb/data directory. There are several options of the command, worth looking at the documentation. A simple mongodump
already runs the backup of a database running on the local machine, placing the files in a "dump" directory within the current directory.
Examples of mongorestore:
- Linux:
mongorestore -h localhost --gzip --dir /Backups/MongoDB/dados
- Windows:
mongorestore /h localhost /gzip /dir C:\Backups\MongoDB\dados
The command restores to a server running on localhost by unzipping the result (-gzip) present in the /Backups/Mongodb/data directory. I am considering that you used the above examples to generate the backup/dump. If you use the option to generate the backup in a file, for example, you should use the --Archive option.
Option 2
Copying data files from one installation to another is also a viable option. It is even one of the recommended methods as backup in documentation mongodb.
I do not recommend
Use the mongoexport and mongoimport because they work with output/input text files. So you lose information:
- You are converting BSON to JSON, JSON does not have information as rich as data types.
- The indexes you created in the Collections are not taken in the process. You need to recreate them when you import.
Your idea is to synchronize the banks, automagically leave them with the same data? Or backing up one computer and taking it to the other is enough?
– Jorge C. Bernhard Tautz
@Jorgec.Bernhardtautz without automatic - only backup even! ;)
– Daniel