DEV Community

Revathi Joshi for AWS Community Builders

Posted on

Database Migration steps with the AWS CLI - 2

This is 2nd article on Database Migration Steps using AWS CLI, showing on how to set up a replication task. The replication task runs on the replication instance and migrates data from the source endpoint to the target endpoint.

Please read my 1st article, Database Migration steps with the AWS CLI - 1, where I have shown on how to create and set up a replication instance, source and target endpoints.

You can use the AWS DMS console or the AWS CLI or the AWS SDK to perform the database migration.

Please visit my GitHub Repository for Database Migration articles on various topics being updated on constant basis.

Let’s get started!

Objectives:

6. Create a replication task.

7. Describe the replication task.

8. Start the replication task.

9. Check the progress of the replication task.

10. Stop the replication task.

11. Delete the replication task.

12. Delete the source and target endpoints.

13. Delete the replication instance.

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • Cloud9 IDE with AWS CLI.

Resources Used:

AWS Database Migration Service

AWS CLI Command Reference on DMS

Steps for implementation to this project:

6. Create a replication task.

  • If the test connections are successful, use the following command to create the task:
aws dms create-replication-task --replication-task-identifier replication-task-1 --source-endpoint-arn $source_endpoint_arn --target-endpoint-arn $target_endpoint_arn --replication-instance-arn $rep_instance_arn --migration-type full-load --table-mappings file:///tmp/table-mappings --replication-task-settings file:///tmp/task-settings

Enter fullscreen mode Exit fullscreen mode

7. Describe the replication task.

  • After the task is created, describe the task to check that it is ready to be executed.
aws dms describe-replication-tasks --filters "Name=replication-task-id,Values=replication-task-1"

Enter fullscreen mode Exit fullscreen mode
  • Run the following command to save the replication task ARN for use in later steps:

replication task ARN

replication_task_arn=$(aws dms describe-replication-tasks --filters "Name= replication-task-id,Values=replication-task-1" --query "ReplicationTasks[0].ReplicationTaskArn" --output text)

Enter fullscreen mode Exit fullscreen mode
  • Run the following command to check the status of the task:
aws dms describe-replication-tasks --filters "Name=replication-task-arn,Values=$replication_task_arn" --query "ReplicationTasks[0].Status" 

Enter fullscreen mode Exit fullscreen mode

8. Start the replication task.

  • Run the following command to start the task:
aws dms start-replication-task --replication-task-arn $replication_task_arn --start-replication-task-type start-replication

Enter fullscreen mode Exit fullscreen mode

9. Check the progress of the replication task.

  • Run the following commands to keep track of the task progress.

  • To monitor the overall task-level statistics, run the following command:

aws dms describe-replication-tasks --filters "Name=replication-task-arn,Values=$replication_task_arn" --query "ReplicationTasks[0].ReplicationTaskStats"

Enter fullscreen mode Exit fullscreen mode
  • To monitor the table-level statistics, run the following command:
aws dms describe-table-statistics --replication-task-arn $replication_task_arn

Enter fullscreen mode Exit fullscreen mode
  • To monitor the task status itself, run the following command:
aws dms describe-replication-tasks --filters "Name=replication-task-arn,Values=$replication_task_arn" --query "ReplicationTasks[0].{Status:Status,StopReason:StopReason}" 

Enter fullscreen mode Exit fullscreen mode

10. Stop the replication task.

  • You can stop the migration after data is completely migrated from source to target.

  • Run the following command to stop the migration task:

aws dms stop-replication-task --replication-task-arn $replication_task_arn

Enter fullscreen mode Exit fullscreen mode

Cleanup

11. Delete the replication task.

  • Run the following command to delete it:
aws dms delete-replication-task --replication-task-arn $replication_task_arn

Enter fullscreen mode Exit fullscreen mode

12. Delete the source and target endpoints.

  • Run the following commands to delete them:
aws dms delete-endpoint --endpoint-arn $source_endpoint_arn

aws dms delete-endpoint --endpoint-arn $target_endpoint_arn

Enter fullscreen mode Exit fullscreen mode

13. Delete the replication instance.

  • Run the following command to delete the replication instance:
aws dms delete-replication-instance --replication-instance-arn $rep_instance_arn 

Enter fullscreen mode Exit fullscreen mode

What we have done so far

We have successfully demonstrated on how to set up a replication task.

Top comments (0)