Mongo DB, dump data to another instance

Photo by Susan Q Yin on Unsplash

Mongo DB, dump data to another instance

To copy all the data from your hello1 EC2 instance to your new hi2 EC2 instance, you can use the mongodump and mongorestore commands. Here are the high-level steps to follow:

  1. On the hello1 EC2 instance, use the mongodump command to create a backup of the MongoDB database. This will create a binary export of the data in the MongoDB database.

     mongodump --archive=/path/to/backup.archive --gzip
    

    This command will create a compressed binary dump of your MongoDB database and save it to a specified file location.

  2. Copy the backup archive from the hello1 EC2 instance to the hi2 EC2 instance. You can use any method you prefer to transfer the file such as scp, rsync or S3 bucket.

  3. On the hi2 EC2 instance, use the mongorestore command to import the backup into the MongoDB database.

     mongorestore --archive=/path/to/backup.archive --gzip
    

    This command will import the backup archive into your MongoDB database on the hi2 EC2 instance.

  4. Once the import process is complete, you can verify that the data has been successfully copied to the hi2 EC2 instance by connecting to the MongoDB database and running queries to check the data.

Please note that the above process assumes that you have the same version of MongoDB installed on both EC2 instances. If the versions are different, you may need to update the database on the hi2 instance to match the version of the backup from the hello1 instance before you can restore the backup.