#!/bin/bash help () { printf "Script: 08-stop-replication-task.sh \n" printf "Usage: 08-stop-replication-task.sh [ -d ] [ -r ] [ -h ] \n" printf " -- \nWhere: \n" printf " -d This flag sets the CFT stack name for the stack in which all DMS resources are created.\n" printf " This flag can be avoided if AWSDMS_CFSTACK_NAME is set as an environment variable.\n" printf " -r The AWS Region we're running this demo in. This setting needs to stay the same across all scripts run.\n" printf " Using this flag can be avoided if AWS_DEFAULT_REGION is set as an environment variable where running this script\n" printf " -h show help page.\n" } while getopts 'd:r:h' flag; do case "${flag}" in d) AWSDMS_CFSTACK_NAME="${OPTARG}" ;; r) AWS_DEFAULT_REGION="${OPTARG}" ;; h) show_help='true' ;; *) error "Unexpected option ${flag}" ;; esac done if [[ $show_help == "true" ]] then help exit 0 fi if [ -z $AWSDMS_CFSTACK_NAME ] then printf "The AWS stack var isn't set. Please use -s to set this stack, and ensure it's already completed sucessfully.\n" help exit 1 else printf "The AWS Stack is set, continuing.\n" fi if [ -z $AWS_DEFAULT_REGION ] then printf "The AWS default region var isn't set. Please use -r to set this stack.\n" help exit 1 else printf "The AWS default region is set, continuing.\n" fi ##Mainline #Set variable to replication instance arn DMSREP_INSTANCE_ARN=$(aws cloudformation describe-stacks --stack-name $AWSDMS_CFSTACK_NAME | jq -r '.Stacks[].Outputs[] | select(.OutputKey=="ReplicationInstanceArn") | .OutputValue') DMS_TASK_ARN1=$(aws dms describe-replication-tasks | jq -r '.ReplicationTasks[]|select(.ReplicationTaskIdentifier=="dms-task-partitioning")|.ReplicationTaskArn') echo "Replication task ARN:" $DMS_TASK_ARN1 echo "Stop replication task" aws dms stop-replication-task --replication-task-arn ${DMS_TASK_ARN1} echo "Waiting on replication task to stop" sleep 60; echo "Check status of replication task" aws dms describe-replication-tasks --filters Name=replication-instance-arn,Values=${DMSREP_INSTANCE_ARN} --query "ReplicationTasks[:].{ReplicationTaskIdentifier:ReplicationTaskIdentifier,ReplicationTaskArn:ReplicationTaskArn,ReplicationTaskStatus:Status,ReplicationTFullLoadPercent:ReplicationTaskStats.FullLoadProgressPercent}" --output table