0

I am taking backup of MongoDB filesystem backup(including config files). We are not using sharding in our cluster, having 3node replicaset in place.

Primary Cluster: X_host1, X_host2, X_host3 Secondary Cluster: Y_host1, Y_host2, Y_host3

Taking filesystem backup from X_host1 and restoring it to Y_Host1,2,3 (restoring to diff hostname)

So, how re-configure MongoDB to follow new hostnames? I see the replication nodes are configured into the DB (not any editable config files). Is this the right approach to migrate data from replicated mongodb cluster?

  • Is this the right approach to migrate MongoDB cluster to new hostnames?
  • Is there any way to re-configure new hostnames.
  • AFAIK, after I restore filesystem to new nodes
    • Data is from old nodes, having info about old replica nodes.(X_hosts)
    • How to point it to Y_hosts
Anto
  • 3,128
  • 1
  • 20
  • 20

1 Answers1

1

Follow Restore a Replica Set from MongoDB Backups

In principle do this:

  • Restore the backup on new host (just one)
  • Start the MongoDB as stand-alone, connect to it and drop the local database: db.getSiblingDB('local').dropDatabase()
  • Initiate the ReplicaSet: rs.initiate()
  • Add all members to the ReplicaSet. An initial sync is triggered.

If your database is large, initial sync can take a long time to complete. For large databases, it might be preferable to copy the database files onto each host. For details have a look at linked tutorial.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • Thanks for the detailed steps. Facing some issue with our setup (dockerized mongod). Unable to change the startup commands as mongod is started as part of docker and is like below `1034 1 0 7 09:22 ? 00:00:01 mongod -f /etc/mongod.conf --bind_ip_all` So kiling PID1 will exit from container. Anything specific I should be following for dockerized ones? – Anto Nov 18 '22 at 09:25
  • Modify the `/etc/mongod.conf` file accordingly, see [Configuration File Settings and Command-Line Options Mapping](https://www.mongodb.com/docs/v6.0/reference/configuration-file-settings-command-line-options-mapping/) – Wernfried Domscheit Nov 18 '22 at 10:04
  • Tried different suggestions. ` > use local switched to db local > db.dropDatabase() { "ok" : 0, "errmsg" : "not authorized on local to execute command { dropDatabase: 1.0, writeConcern: { w: \"majority\", wtimeout: 200000.0 }, lsid: { id: UUID(\"2454s22c-bf13f6ea\") }, $db: \"local\" }", "code" : 13, "codeName" : "Unauthorized" } > exit bye Error saving history file: FileOpenFailed Unable to open() file /.dbshell: Permission denied ` Also tried reconfiguring mongodb rs. rs.reconfig() : Tried using this to reconfigure it with new Hostnames. But Failed. – Anto Nov 23 '22 at 12:59
  • "not authorized" is quite clear, I would say. Use a user with appropriate permissions. Or start mongod without authorization. – Wernfried Domscheit Nov 23 '22 at 16:22