HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: //usr/openv/netbackup/bin/goodies/migrate_vxul_logs
#!/bin/sh
# $Id$
#***************************************************************************
# $Copyright: Copyright (c) 2016 Veritas Technologies LLC. All rights reserved VT25-0977-2658-84-51-3 $
#***************************************************************************
#
# This script uses the VxUL configuration file for NBU to identify the
# default log directory and then creates variables for each OID which
# specifies where to put log files for that OID.
#
# Next the script iterates over all of the old log files and moves them
# to the correct directory.  If it doesn't know what to do with a file,
# it leaves it alone.
#
# Additionally, when it encounters a log file for OID 261 (aggs), it
# will just delete the file since they are no longer created and only
# contained a header line in the past.
#

# The following variable is changed by the Makefile to a valid value.

MACHINE=Linux

# Set umask to 022 to make sure files and directories
# are not created with world writable permissions.
umask 022

# INSERT fn.set_echo_var
#----- $Id$ -----
#
#		This function is a case statement sets
#		the ECHO variable
#		with the appropriate path & flags.

#Define Echo to allow escape characters
case "`uname -s`" in
	Linux*)
		unset POSIXLY_CORRECT
		ECHO="/bin/echo -e"
		;;
	SunOS*)
		ECHO="/usr/bin/echo"
		;;
	*)
		ECHO="echo"
		;;
esac

PATH=/bin:/usr/bin:/sbin:/usr/sbin

#
# Work in a sub-shell since we will be changing directories.
#

(
	#
	# This is where the VxUL configuration file for NBU resides.
	#
	CONFIG_FILE=/usr/openv/netbackup/nblog.conf

	if [ ! -f ${CONFIG_FILE} ] ; then
		${ECHO} "
File ${CONFIG_FILE} does not exist.
Abandoning the execution of migrate_vxul_logs.
"
		exit 1
	fi

	#
	# Find and change directory to the default log directory.
	#
	DEFAULT_LOGDIR=`grep '^Default.LogDirectory=' ${CONFIG_FILE} | cut -f2 -d'='`
	if [ ! -d "${DEFAULT_LOGDIR}" ] ; then
		${ECHO} "
Directory ${DEFAULT_LOGDIR} does not exist.
No log files to migrate.
"
		exit 1
	fi
	${ECHO} "
Migrating log files in ${DEFAULT_LOGDIR}"
	cd ${DEFAULT_LOGDIR}

	#
	# Grab the LogDirectory directives and process them within a sub-shell
	# to keep the dynamic variables in scope.
	#
	grep '^...\.LogDirectory=' ${CONFIG_FILE} | (
	while read LOG_DIRECTIVE
	do
		OID=`${ECHO} ${LOG_DIRECTIVE} | cut -f1 -d'.'`
		SUBDIR=`${ECHO} ${LOG_DIRECTIVE} | cut -f2 -d'='`
		eval SUBDIR${OID}=${SUBDIR}
	done

	#
	# Process the log files one at a time, creating directories on the fly
	# if necessary.  We will list the whole directory and then grep just the
	# log files for NBU out of the stream just in case there are thousands of files.
	#
	ls -1 | grep '51216-...-.*\.log' |
	while read FILENAME
	do
		FILE_OID=`${ECHO} ${FILENAME} | cut -f2 -d'-'`

		#
		# We no longer need log files from OID 261, the only thing in these
		# files were log header lines.
		#
		if [ "${FILE_OID}" = "261" ] ; then
			rm -f ${FILENAME}
			continue
		fi

		#
		# If the OID/SUBDIR is valid, create the proper directory
		# and move the log file there.
		#
		eval SUBDIR=\${SUBDIR${FILE_OID}}
		if [ "${SUBDIR}" != "" ] ; then
			if [ ! -d ${SUBDIR} ] ; then
				mkdir ${SUBDIR}
			fi
			chmod 755 ${SUBDIR}
			chgrp bin ${SUBDIR}

			mv ${FILENAME} ${SUBDIR}
		fi
	done
	)
	ls 51216-???-*.log > /dev/null 2>&1
	if [ $? -eq 0 ] ; then
		${ECHO} "Info: Not all log files were migrated."
	fi
	${ECHO} "Migration of log files complete.
"
)