You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
system-tests/sbin/ngcp-mysql-compare-dbs

103 lines
2.2 KiB

#!/bin/bash
set -euo pipefail
usage() {
cat - <<__USAGE__
$(basename "$0") used to compare mysql schemes between two hosts.
Usage: $(basename "$0") [options]
Options:
--formatter=[tap] - Specify the output format.
Skip it to get human readable output.
-h|--help - Show this message.
__USAGE__
}
get_local_instances() {
local_instances+=("${NGCP_HOSTNAME:-localhost}:3306")
if [[ "${NGCP_TYPE}" == 'carrier' && "${NGCP_IS_PROXY}" == 'yes' ]]; then
local_instances+=("${NGCP_HOSTNAME}:3308")
fi
}
FORMATTER=''
args=$(getopt -n "$(basename "$0")" -o h -l help,formatter: -- "$@")
eval set -- "${args}"
while true; do
case "${1}" in
--formatter)
FORMATTER="${2}"
shift 2
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
*)
log_error "Unknown parameter '${1}'"
exit 1
;;
esac
done
NGCP_ROLES='/etc/default/ngcp-roles'
if [[ ! -r "${NGCP_ROLES}" ]]; then
echo "Cannot read mandatory config file ${NGCP_ROLES}" 2>&1
exit 1
fi
. "${NGCP_ROLES}"
MYSQL_CREDENTIALS='/etc/mysql/sipwise_extra.cnf'
if [[ ! -r "${MYSQL_CREDENTIALS}" ]]; then
echo "Cannot read mandatory config file '${MYSQL_CREDENTIALS}'" 2>&1
exit 1
fi
declare -a opts
if [[ -n "${FORMATTER}" ]]; then
opts+=(--formatter="${FORMATTER}")
fi
declare -a schemes=()
while IFS= read -r -d $'\0'; do
schemes+=("${REPLY}")
done < <(find '/usr/share/ngcp-db-schema/schema/' -name "*.json" -print0)
declare -a local_instances=()
get_local_instances
rc=0
for local_mysql in "${local_instances[@]}"; do
for schema in "${schemes[@]}"; do
schema_name="${schema##*/}"
schema_name="${schema_name%.json}"
if [[ "${local_mysql}" =~ 3308 ]]; then
case "${schema_name}" in
syslog|stats|fileshare|ldap|accounting|sipstats)
echo "Skipping schema ${schema_name} on ${local_mysql} instance"
continue
;;
esac
fi
if ! /usr/share/ngcp-system-tests/compare_dbs.pl \
--host-db1="${local_mysql%:*}" \
--port-db1="${local_mysql#*:}" \
--schema-file="${schema}" \
--schema-name="${schema_name}" \
"${opts[@]}"; then
rc=1
fi
done
done
exit ${rc}