#!/bin/sh
# $Id: onfreeze,v 2.1.6.1 2002/06/12 18:24:25 ptle Exp $
#ident "$Source: /project/vras-cvs/src/common/cmd/vras/samples/sample_db_snapshot/onfreeze,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
#

# --------------------------------------------------------------------
#
# onfreeze
#
# 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 while
#      the Secondary RVG is frozen (after it has received the IBC 
#      message from the Primary RVG).
#   is used to perform any task that needs the Secondary RVG in frozen
#      state (i.e. no updates will be written to Secondary volumes.)
#      In this sample, the task to be performed in this script is 
#      taking snapshot of all the data volumes in the Secondary RVG.
#   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

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

#
# By default, a snapshot volume will be named SNAP-<vol_name>. Set
# SNAP_PREFIX below to your desire prefix if you want a different
# prefix for the snapshot volumes.
#
SNAP_PREFIX="SNAP"

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


# Take a snapshot of each data volume in the Secondary RVG
/usr/sbin/vxrvg -g $DG_NAME -P ${SNAP_PREFIX} snapshot $RVG_NAME

if [ $? -eq 0 ]
then
	echo "INFO: Snapshot created successfully."
	exit 0
else
	echo "ERROR: Failed to create snapshot."
	exit 1
fi
