#!/bin/sh
# $Id: prefreeze,v 2.1.6.1 2002/06/12 18:24:27 ptle Exp $
#ident "$Source: /project/vras-cvs/src/common/cmd/vras/samples/sample_db_snapshot/prefreeze,v $"
#
#
# Copyright (c) 2002 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
#
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
#
#               RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#               VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043
#

# --------------------------------------------------------------------
#
# prefreeze
#
# This script is called when user runs vradmin ibc command with 
# "sample_db_snapshot" as the taskname in the ibc command as follows:
#
#   vradmin -g <diskgroup> ibc <rvg_name> sample_db_snapshot [<sechost>] ...
# 
# This script:
#   is executed by the vradmin ibc command on the Secondary host
#   is used to carry out operations needed prior to the execution of
#      the onfreeze script on the Secondary host. In this example,
#      a snapshot of the Secondary volumes will be taken in the
#      onfreeze script, this prefreeze script can be used to add
#      snapshot plexes to the Secondary volumes.
#   is given the following parameters in the listed orders:
#      DG_NAME     name of diskgroup in which the RVG resides.
#      RVG_NAME    name of the RVG.
#      TASK_NAME   the task name used in the ibc command line. In this
#                  sample, it is sample_db_snapshot.
#      RLINK_NAME  name of the Secondary RLink.
#   must be executable by the root user
#   should exit with 0 upon successful completion
#
# Note: the parameters are always given by the vradmin ibc command.
# They are available for use in this script, and it's perfectly fine
# if they are not used anywhere in this script.
#
# To function correctly, this script must:
#   *  have the appropriate values defined in the "CUSTOMIZATION
#      SECTION" of this script.
#
# --------------------------------------------------------------------


# --------------------------------------------------------------------
# main script starts here
# --------------------------------------------------------------------

DG_NAME=$1
RVG_NAME=$2
TASK_NAME=$3
RLINK_NAME=$4

VOL_LIST=`/usr/sbin/vxrvg -g $DG_NAME getdatavols $RVG_NAME`

# --------------------------------------------------------------------
# ========             CUSTOMIZATION SECTION                  ========
# --------------------------------------------------------------------

#
# Set the value of ADD_SNAP_PLEX to "yes" if you want to create snapshot
# plexes for the Secondary data volumes and set it to "no" otherwise.
#
ADD_SNAP_PLEX="no"

#
# Set the value of ENABLE_FMR to "yes" if you have a license for using
# FastResync and want to enable FastResync on the Secondary volumes.
#
ENABLE_FMR="no"

# --------------------------------------------------------------------
# ========          END OF CUSTOMIZATION SECTION              ========
# --------------------------------------------------------------------


if [ "$ADD_SNAP_PLEX" = "yes" ]
then
	# Create a snapshot plex for each Secondary data volume.
	for vol in $VOL_LIST
	do
		/usr/sbin/vxassist -g $DG_NAME snapstart $vol > /dev/null 2>&1

		if [ $? -ne 0 ]
		then
			echo "ERROR: Failed to create snapshot plex for volume $vol"
			exit 1
		fi
	done
fi

if [ "$ENABLE_FMR" = "yes" ]
then
	# Enable FastResync (FR) for Secondary volumes
	for vol in $VOL_LIST
	do
		if [ "`/usr/sbin/vxprint -g $DG_NAME -F%fastresync $vol`" = "off" ]
		then
			/usr/sbin/vxvol -g $DG_NAME set fastresync=on $vol
			if [ $? -ne 0 ]
			then
				echo "ERROR: Cannot enable FastResync on volume $vol"
				exit 1
			fi
		fi
	done
fi

exit 0
