Migrate your data to Percona Server for MongoDB
If you use Percona Server for MongoDB, migrate your data to it from the MongoDB virtual machine in your Kubernetes cluster
読み終わるまでの所要時間 2 分最終更新 6日前
Migrate your data from the MongoDB virtual machine (VM) to Percona Server for MongoDB (PSMDB) in your Kubernetes cluster at your own pace with a staged approach. The Terraform variable
enable_percona_mongo- The custom URI, if provided
- The existing MongoDB VM
- The new PSMDB cluster
- Connect to your MongoDB instance through SSH, for example, using AWS Systems Manager Agent (SSM Agent).
-
To assign the role to the user who is to run the backup script, run this command:
backup
Use these values:# Connect to MongoDB and grant the backup rolemongo --username {admin_username} --password {admin_password} --authenticationDatabase admindb.grantRolesToUser("asset-manager", ['backup'])- : the
admin_usernameuser if you're using our MongoDB VMasset-manager - : the password that is stored in the
admin_passwordsecret in Secret Managermongo_db_connection_string
-
Copy the backup script from the following location, and then run it:
To provide the correct username and password, run this command:./aws/scripts/mongodb-backup.sh./mongodb-backup.sh asset-manager {password} - Retrieve the .tar file, for example, using the Secure Copy Protocol (SCP).
-
To validate which pod is the primary pod, run these commands:
The password is stored in thekubectl exec -it psmdb-db-rs0-x -c mongod -- bashmongo --username {admin_username} --password {admin_password} --authenticationDatabase adminrs.status()secret in Secret Manager.psmdb_asset_manager_passwordThe primary pod is the pod that has these values:"state" : 1"stateStr" : "PRIMARY"
-
To retrieve .the tar file using SCP and copy it to the PSMDB primary pod, run this command:
kubectl cp ~/tmp/mongo_data_backup_YYYY-MM-DD_HH-MM-SS.tar.gz psmdb-db-rs0-x:/tmp/mongo_backup_YYYY-MM-DD_HH-MM-SS.tar.gz -c mongod
-
Copy the restore script from the following location to the primary pod:
Run this command:./aws/scripts/mongodb-restore.shkubectl cp ~/scripts/mongodb-restore.sh psmdb-db-rs0-x:/tmp/mongodb-restore.sh -c mongod -
To connect to the primary pod and import the backup, run these commands:
kubectl exec -it psmdb-db-rs0-x -c mongod -- bashcd /tmpchmod +x mongodb-restore.sh./mongodb-restore.sh asset-manager {password} mongo_backup_YYYY-MM-DD_HH-MM-SS.archive
-
To update the terraform variable to use the new PSMDB cluster, run this command:
mongo_connection_urimongo_connection_uri = "mongodb+srv://asset-manager:{password}@psmdb-db-rs0.{kubernetes_namespace}.svc.cluster.local?authSource=admin&replicaSet=rs0&ssl=false" - Restart the Asset Manager services so that they use the new connection string.
-
When you're sure that the new PSMDB cluster is working, you can disable MongoDB VM instance by setting the Terraform variable .
enable_mongo=false