#!/bin/bash set -e myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" . "$myDir/config.sh" . "$myDir/apply.config.sh" todayDir=$(date +%Y-%m-%d) pattern="$baculaDir/mnt/local-backup/${todayDir}_??-??_full.gz" files=($pattern) backupFile="${files[0]}" "$myDir/restore-backup.sh" "$backupFile" rm -r "$baculaDir" if [[ "${#dbClusterSiblings[@]}" -gt "0" ]]; then for node in "${dbClusterSiblings[@]}"; do ssh root@$node service mysql stop ssh root@$node "if pgrep mariadbd; then pkill -9 mariadbd; fi" done galera_new_cluster else service mariadb start fi echo "Applying custom script." mysql -e "UPDATE util.config SET environment = '$dbEnvironment', lastDump = NOW()" mysql < "$myDir/apply.sql" echo "Upgrading tables." mysql_upgrade echo "Applying repository changes." curl --silent --request POST --location --user "$jenkinsAuth" "$jenkinsUrl/build?delay=0sec" echo "Waiting for Jenkins job to end." jobResult=null while [ "$jobResult" = "null" ]; do sleep 10 jobResult=$(curl --silent --location --user "$jenkinsAuth" "$jenkinsUrl/lastBuild/api/json" | jq --raw-output ".result") done echo "Job result: $jobResult" echo "Promoting to master." "/root/scripts/promote-master.sh" for node in "${dbClusterSiblings[@]}"; do ssh root@$node service mysql start done