#!/bin/sh
#
# $Id$ Copyright (c) 2025 EMC Corporation.
#
# All rights reserved.  This is an UNPUBLISHED work, and
# comprises proprietary and confidential information of EMC.
# Unauthorized use, disclosure, and distribution are strictly
# prohibited.  Use, duplication, or disclosure of the software
# and documentation by the U.S. Government is subject to
# restrictions set forth in a license agreement between the
# Government and EMC or other written agreement specifying
# the Government's rights to use the software and any applicable
# FAR provisions, such as FAR 52.227-19.
#
#
# All rights reserved.
#
#
# This script is part of the NWUI
#
#
#
#
# ====================================================================
#

nwuihome=`rpm -q --qf "%{INSTPREFIXES}\n" lgtonwui 2> /dev/null`
if [ $? -ne 0 ]; then
    nwuiservhome=`rpm -q --qf "%{INSTPREFIXES}\n" lgtonwuiserv 2> /dev/null`
    MCUI_HOME=$nwuiservhome
else
    MCUI_HOME=$nwuihome
fi

directory="/opt/nsr/authc-server/tomcat/conf"

if [ ! -d $directory ]; then
	directory="/opt/nwui/tomcat/conf"
fi
hostName=`awk "/monitoring.hostname/" $directory/nwui-app.properties | cut -d '=' -f2 `

echo $hostName

MONITORING_HOME="${MCUI_HOME}/monitoring"
POSTGRESDB_HOME="${MONITORING_HOME}/postgres/16"
echo $POSTGRESDB_HOME

"$POSTGRESDB_HOME/bin/pg_basebackup" -P -v --wal-method=fetch -D "$MONITORING_HOME/pgdata" -U nwuiuser -p 5435 -h $hostName
chown -R nsrnwui:nsrnwui "$MONITORING_HOME/pgdata"
