#!/bin/bash help() { echo "Usage: start-migration-pre-check.sh [ Required options] Required options: -u -H -U -p -P -s -d Example: start-migration-pre-check.sh -u 09352622-5db9-4053-b3f2-791d3f8c8f63 -H yoursourceserver.com -U root -p YourPassW0rd -P 5432 -d postgres -s true Use -h for infromation about this script. " exit 2 } if [[ $# -eq 0 ]]; then help fi while [[ $# -gt 0 ]]; do case $1 in -u) UUID=$2 shift shift ;; -H) SOURCE_HOST=$2 shift shift ;; -U) SOURCE_USER=$2 shift shift ;; -p) SOURCE_PASSWORD=$2 shift shift ;; -P) SOURCE_PORT=$2 shift shift ;; -d) DBNAME=$2 shift shift ;; -s) SSL=$2 shift shift ;; -h) help ;; -*|--*) echo "Invalid option" echo help ;; esac done if [[ -z $UUID || -z $SOURCE_HOST || -z $SOURCE_USER || -z $SOURCE_PORT || -z $SOURCE_PASSWORD || -z $SSL ]] then echo "Missing required variable. You need to define all required arguments." echo help fi echo -e "Creating migration check task… \n" DATA="{\"migration_check\": { \"source_service_uri\": \"postgres://$SOURCE_USER:$SOURCE_PASSWORD@$SOURCE_HOST:$SOURCE_PORT/$DBNAME\" }, \"operation\": \"migration_check\"}" result=$(curl -s -u "$UPCLOUD_USERNAME:$UPCLOUD_PASSWORD" -X POST -H Content-Type:application/json https://api.upcloud.com/1.3/database/$UUID/tasks -d "$DATA") taskId=$( jq -r '.id?' <<< $result) if [[ "$taskId" == "null" ]]; then echo -e "Error: failed to create migration_check task!" echo "$result" exit 1 fi echo -e "Success: migration check task created" echo -e "id: $taskId \n" echo -e "Polling for migration check task result... \n" taskFinished=0 count=1 while [ $taskFinished -eq 0 ]; do sleep 3 taskResult=$(curl -s -u "$UPCLOUD_USERNAME:$UPCLOUD_PASSWORD" -X GET -H Content-Type:application/json https://api.upcloud.com/1.3/database/$UUID/tasks/$taskId) echo "Task Result : poll #$count " echo "$taskResult" | jq successResult=$( jq -r '.success?' <<< $taskResult) if [ $successResult == "true" ] || [ $successResult == "false" ]; then taskFinished=1 echo -e "\n" echo "migration check task completed" break fi ((count=count+1)) echo -e "\n" done