052-check-gcp-nodes-has-same-azure-lsn.sh 869 Bytes
Newer Older
1 2 3 4
#!/bin/bash

set -eu

5
# shellcheck source=/dev/null
6 7
source "${BASE}/env_${ENVIRONMENT}"

Matteo Melli's avatar
Matteo Melli committed
8
azure_master_lsn="$(echo "select case when pg_is_in_recovery() 
9
      then pg_last_xlog_replay_location() 
10
      else pg_current_xlog_location() end;" \
11
    | ssh_remote "$AZURE_MASTER" sudo -u gitlab-psql gitlab-psql -v ON_ERROR_STOP=1 -d postgres -t -A)"
Matteo Melli's avatar
Matteo Melli committed
12
gcp_master_candidate_lsn="$(echo "select case when pg_is_in_recovery() 
13
      then pg_last_xlog_replay_location() 
Matteo Melli's avatar
Matteo Melli committed
14
      else pg_current_xlog_location() end;" \
15
    | ssh_remote "$GCP_MASTER_CANDIDATE" sudo -u gitlab-psql gitlab-psql -v ON_ERROR_STOP=1 -d postgres -t -A)"
16 17 18
if [ "$azure_master_lsn" == "$gcp_master_candidate_lsn" ]
then
  echo "GCP and Azure have same LSN: $azure_master_lsn"
Matteo Melli's avatar
Matteo Melli committed
19
  exit 0
20 21
fi
echo "GCP and Azure have NOT same LSN. Current LSNs are: Azure/$azure_master_lsn GCP/$gcp_master_candidate_lsn"
Matteo Melli's avatar
Matteo Melli committed
22
exit 1