Migration of MindSphere MongoDB to MongoDB Atlas¶
This documentation describes one of the procedures to migrate your MongoDB data hosted by MindSphere to an own account from MongoDB Atlas.
If you would like to use your application connected to a MongoDB Backing Service after October 31st 2020, then you need to take action.
Get Backup from MindSphere CloudFoundry MongoDB¶
The steps to get a backup which can be restored with
mongorestore command differentiate between XS-sized and M-sized MindSphere CloudFoundry MongoDB instances.
Before creating, downloading a backup or MongoDB dump, make sure that no app is writing into your MongoDB instance.
XS-sized MindSphere CloudFoundry MongoDB Instances¶
The following steps are only valid for XS-sized service instances.
Download a Backup¶
- Open the Service Dashboard (see Backup and Restore Service Instances).
- Set an encryption key.
- Create a Backup.
- Download a Backup (see Download a Backup).
To Decrypt backup, execute the following command:
cat <backupFile> | openssl enc -md md5 -aes256 -d -pass 'pass:<Encryption Key>' | gunzip -c > decrypted-backup
<Encryption Key>is the key that was set in the Service Dashboard, while downloading the backup.
M-sized MindSphere CloudFoundry MongoDB Instances¶
The following steps are necessary for M-sized service instances. However, they are also valid for XS-sized service instances.
Create ssh tunnel to MongoDB instances¶
For the creation of an ssh tunnel to your MongoDB instance, an app has to be bound to the MongoDB instance.
- Get host name and credentials of your MongoDB instance using CF CLI:
cf env <app-name>
<app-name>is the name of your app which is bound to your MongoDB instance.
- Note the default_database, master host name (incl. port), username and password of your MongoDB instance:
- Create tunnel to MongoDB instance by using the following command:
From the example screenshot above, the command is:
cf ssh <app-name> -L <local-port>:<host-name-incl-port>`
cf ssh pymon -L 27017:mod16dfa2-mongod-initial-master-0.node.dc1.a9ssvc:27017
pymonis the name of your app.
Create MongoDB Dump¶
After the tunnel to your MongoDB instance is open, you can create a dump of your database.
- Open another shell locally
- Install mongodump on local shell (see Mongodump).
- Create dump of your MongoDB instance with
mongodump -h localhost:<local-port> -u "<username>" -p "<password>" --gzip --db=<default_database> --archive=backup.archive
In the example screenshot, the command is:
mongodump -h localhost:27017 -u "a9s-brk-usr-c47fc03fc7b51ba39c36cd7ef5ea0214cb44" -p "a9s503d87721c74d094457046192a2423bfe7ac" --gzip --db=mod16dfa2 --archive=backup.archive
Create MongoDB cluster and restore data on MongoDB Atlas¶
- Open MongoDB Atlas.
- Sign In or Create Account.
- Create MongoDB Cluster
For eu1, region create it on AWS in region Frankfurt
For eu2, region create it on Azure in region westeurope
4. Create Database Access User
Restore backup into Cluster¶
- Install mongorestore (see Mongorestore).
- On MongoDB Atlas, you can find you mongorestore command.
Open your cluster on MongoDB Atlas and click on "Command Line Tools".
- Copy the restore command
mongorestore --host MyCluster-shard-0/mycluster-shard-00-00-80us0.mongodb.net:27017,mycluster-shard-00-01-80us0.mongodb.net:27017,mycluster-shard-00-02-80us0.mongodb.net:27017 --ssl --username myUser --password <PASSWORD> --authenticationDatabase admin
<atlasUser>, that you have created.
--gzip --archive=decrypted-backupto the end of the command. With this, the command is as below:
mongorestore --host MyCluster-shard-0/mycluster-shard-00-00-80us0.mongodb.net:27017,mycluster-shard-00-01-80us0.mongodb.net:27017,mycluster-shard-00-02-80us0.mongodb.net:27017 --ssl --username myUser --password <atlasPwd> --authenticationDatabase admin --gzip --archive=backup.archive
- Execute the restore command.
- After restore has finished, you can see your database in MongoDB Atlas.
- Save the database name for future reference. In this example, it is
Change connection to MongoDB Atlas cluster in MindSphere CloudFoundry¶
For region China 1, please refer to Change connection to MongoDB Alibaba Cloud cluster in MindSphere CloudFoundry.
- In MongoDB Atlas, navigate to your project and select "Clusters".
Click on "CONNECT" button of your cluster you want to connect to. Select "Connect your application".
- Select your driver and version.
- Copy the connection string.
<atlasPwd>, you have created.
- Replace the database name
/testby the database that you have saved. For example
- With this changes, you will have a connection string like below:
- In CF CLI, create a User-Provided-Service.
cf cups <my-mongodb.com-cluster> -p "uri"
- When requested for uri, insert your connection string.
- Unbind MindSphere CloudFoundry Backing Service from your app.
cf us <myapp> <my-old-mongodb>
- Bind User-Provided-Service to your app.
cf bs <myapp> <my-mongodb.com-cluster>
- Restage your app.
cf restage <myapp>
- Remember to change the service instance name to the User-Provided-Service in your
- MongoDB TLS/SSL is standard
- Latency time may be higher than before
Tipp: Create DB in AWS Frankfurt to minimize the latency time
- Your application may need more outbound traffic
- Keep in mind that your database endpoint is now accessible over internet. Please consider the security recommendations below and implement all additional security measures recommended by your organization.
- Whitelist MongoDB Atlas cluster Access for MindSphere CloudFoundry IP addresses only.
You can find the CloudFoundry IP addresses here.
Any questions left?
Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.