How to sync two on-prem MongoDB clusters

Hello,

We have 2 MongoDB 4.0 clusters. I’ve been looking for live migrations options. I tried mongomirror, but it turned out that it was meant to work with Atlas clusters, then found out mongosync, but unfortunately, it’s compatible with MongoDB 6. So I’m curious, what do you recommend for data syncing between two non-Atlas clusters? I like to do a live migration and will highly appreciate your ideas on this.

Thanks!

Hi @Ercin_Demir

First I would note that MongoDB 4.0 series is out of support by now, so you might want to consider upgrading to a supported version. At the moment, series 4.2 is the oldest supported release series. Unsupported versions will not receive bugfixes or improvements.

Since the mongosync route is not available for you, you may be able to roll your own solution using perhaps change streams. You need to implement a method that can read the change stream from the source cluster and apply it to the destination cluster. However you’ll need to debug and maintain this connector, which could be an issue in the long term.

Alternatively, if you can spare some time and effort, I think the best method is to use mongomirror to migrate to Atlas, upgrade your Atlas deployment to the latest series (6.0) using automation, then you can dump the migrated data into your own MongoDB 6.0 deployment. With this, you’re basically: 1) upgraded to the latest supported MongoDB version, and 2) now you can use mongosync. It’s up to you if you want to keep your data in Atlas if that’s more convenient for you, but you can always dump & restore them anywhere you wish.

Best regards
Kevin

1 Like

Hi @kevinadi,

Thank you for taking the time to reply on the post. Both of the clusters are not Atlas clusters. We are going to migrate from our self-host MongoDB to our K8s MongoDB managed by Kubernetes Operator model. Since the data is quite large and we don’t want to compromise of losing any data, we want to do a live migration/syncing data. I believe your alternative solution was mainly for Atlas clusters. Did you get have any experience on live migrations on MongoDB 4?

I also found out a migration tool called mongopush. I tried that but it didn’t complete properly. Any tools ideas are also welcome.

P.S: Upgrading from 4.0 to 6 is not a quick solution as it needs more tests on the side application before going to production.

I’m looking forward to your opinion on this. Thanks very much in advance!

Hi @Ercin_Demir

While you can do a backup/restore to a new cluster (see Backup and Restore with MongoDB Tools), doing it with a large dataset live is a different thing altogether.

I don’t have experience with managing such a move, but if I’m in your shoes, I would perhaps look into the possibility of extending the replica set into the new deployment (e.g. adding the new deployment using rs.add(<nodes in the new deployment>) one by one), then once everything is in sync, remove the nodes from the old deployment (e.g. rs.remove(<nodes in the old deployment>)). This is off-the-top-of-my-head idea, so please take this with a grain of salt and do a thorough testing :slight_smile:

Hope you’ll find a workable solution.

Best regards
Kevin