Search code examples
mongodbamazon-web-servicesamazon-ec2amazon-ebs

Import Mongo database from snapshot volume AWS


I have 2 mongo cluster with 3 nodes and a replica set configurated. The goal is to import the database from clusterA to clusterB via a master snapshot.

Those are the steps that I followed.

  • Created snapshot from Ec2 masterA.
  • Created volumeA from created snapshot.
  • Attach volumeA to masterB.
  • Mounted volumeA in masterB in /data/db2.
  • Updated /etc/mongo/mongod.conf to point the new storage.
  • Restarted MongoDB.

No errors when restarting, but when I connect back to the database, I still see the old collections. However, the directory /data/db2 shows a different size and matches the database in clusterA.

Thank you, any help is appreciated.


Solution

  • Found the solution:

    So, we have one mongo cluster clusterA, with 1 master and 2 workers.

    In clusterA, we make a snapshot from master volume, snapA and we create a volume from that snapshot volumeA.

    If we want to import mongo database from clusterA to clusterB:

    • First, attach volumeA in masterB.
    • Mount volume, for example in /data/db2.

    Once the volume is attached and mounted, follow this Mongo guide https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/.

    After that, you'll have successfully imported a mongo backup from clusterA to clusterB via volume snapshot.

    Regards.