Talk about the backup mode of MongoDB

  • 2020-05-24 06:25:08
  • OfStack

Briefly 1, the backup mode of MongoDB:

1. mogodump / mongorestore

This 2 command puts mongodb data dump into BSON format, which can be restored when needed.
This also works as a small database. But if it's above sharding or a few hundred G
It's almost unusable. Because BSON and its footprint.

2. Slave Replication

It is most suitable and reliable, suitable for production environment. MongoDb supports master+ multiple slave. Therefore, it is very convenient to have an slave for backup.
However, it is important to note that if the data volume is large, if it is a new slave, and the speed is not guaranteed, 1 must increase the size of oplogSize. For a database of 300G,
It can be adjusted above 60G. This avoids synchronization to the middle of the oplogSize deficiency and other exceptions.

3. About incremental hot backup

For those who are keen on individual file backups, consider using "incremental hot" backup as a last resort.
The way to do this is to start with an slave for a while and then copy the database file to another directory as the starting point for an incremental backup.

Every time you do a backup, start an slave in this directory, use the wok and fastsync parameter, and you can sync the tar directory.

One of the disadvantages of this approach is that if the backup cycle is too long, space waste can be very large, especially in the case of frequent deletions,
Previous versions of current 1.6 had bug for the deleted space recovery mechanism. This issue should be resolved by the time version 1.6 is released.

To recycle this space, repairDatabase is needed, which is slow, so it is better to make a new db from clone1. (actually, the process of Repair is clone first and then copy back).

To sum up, the most reliable and secure way to backup is to use mongodb's own synchronous replication mechanism.
The most classic and smallest production environment is:
1 master + 2 slaves

The above is all about the backup mode of MongoDB in this article, I hope you enjoy it.


Related articles: