- 论坛徽章:
- 0
|
#!/bin/sh
#
# $Id: nsrsyb.sh,v 1.13.84.11 2007/05/11 12:08:56 sharmh Exp $ Copyright (c) 2007, EMC Corporation.
#
#
# Copyright (c) 2007, 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.
#
# nsrsyb
#
# This script is part of the Networker Module for Sybase.
# Modification of this script should be done with care and only after reading
# the administration manual included with this product.
#
# This script should only be run as part of a scheduled savegroup.
#
# Returns 0 on success; 1 on failure.
#
###########################################################################
# This value MUST be set for scheduled backups to run.
###########################################################################
#
# Variable: SYBASE
# Default value:
# Description: Specifies where the Sybase RDBMS is installed.
# Set this variable to the directory where Sybase ASE
# software is installed. This *must* be set for scheduled backups
# to be able to find the Sybase libraries and executables.
#
SYBASE=/export/home/sybase/ASE-12_5
. $SYBASE/SYBASE.sh
###########################################################################
#
# Configuration variables, modifiable by users.
#
###########################################################################
# The following lines may be edited to change the default settings. These
# are for advanced tailoring of backups and should be edited carefully.
###########################################################################
#
# Variable: USE_CONSISTENCY_CHECK
# Default value: true
# If set, this puts a consistency check into the PRECMD variable.
# To disable this, set the USE_CONSISTENCY_CHECK value as follows:
# USE_CONSISTENCY_CHECK=
#
# If this is on, it will set the PRECMD to do a consistency check.
# If you need to customize the PRECMD to do other work, unset this
# value and perform any desired consistency checks in your own
# script.
#
USE_CONSISTENCY_CHECK=true
#
# Variable: DBCCOPT
# Default value: none
# If set, these are the options that the nsrsybcc program uses in its
# consistency check. If not set, the options will be the program defaults
# from the nsrsybcc program.
#
DBCCOPT="-o ckdb"
#
# Variable: PRECMD
# Default value:
# Description: This variable can be used to run a command before nsrsybsv.
#
# If USE_CONSISTENCY_CHECK is set, the PRECMD will be constructed to perform
# a nsrsybcc check on the given saveset. A PRECMD that you set here will
# not be overwritten by a consistency check, however.
#
PRECMD=
#
# Variable: POSTCMD
# Default value: NONE
# Description: This variable can be used to run a command after nsrsybsv
# has completed.
#
POSTCMD=
#
# Variable: BACKUP_OPT
# Default value: none
# If set, these are the options that will be passed to the nsrsybsv
# program in addition to the ones set from savegrp. This is useful
# for setting the debug level.
# Passing -N option is not recommended as it will be overwritten by
# what is passed from the savegroup.
#
#BACKUP_OPT="-D 4"
#
BACKUP_OPT="-b sybasefull"
#
# Variable: NSR_DATA_VOLUME_POOL
# Default value: none
# Description: If this variable is set to name a media pool, then database
# backups will be directed to the named media pool.
#
NSR_DATA_VOLUME_POOL=
#
# Variable: NSR_LOG_VOLUME_POOL
# Default value: none
# Description: If this variable is set to name a media pool, then
# transaction log backups will be directed to the named media pool.
#
NSR_LOG_VOLUME_POOL=
#
# Variable: NSR_COMPRESSION
# Default value: FALSE
# Description: This environment variable specifies whether client-side
# compression is performed on the data.
#
NSR_COMPRESSION=FALSE
#
# Variable: NSR_AES_ENCRYPTION
# Default value: FALSE
# Description: This environment variable specifies whether AES encryption
# is used between the client and server.
#
NSR_AES_ENCRYPTION=FALSE
#
# Variable: NSR_ASE_PASSWORD
# Default value: None
# Description: This environment variable specifies the password
# to be used while dumping for ASE 12.5.2 onwards.
#
NSR_ASE_PASSWORD=
#
# Variable: NSR_ASE_VERIFY
# Default value: None
# Description: This environment variable specifies the verify
# clause to be used while issuing dump command for ASE 12.5.4 onwards.
# The valid values can be either "header" or "full". The value
# is case insensitive. The option header will verify only the
# header before dump. The option full will verify both
# header and row structure.
# Note that the verify clause does not work with ASE 15.0.
#
NSR_ASE_VERIFY=
#
# Variable: NSR_DEBUG_FILE
# Default value: /nsr/applogs/xbsa.messages
# Description: This environment variable specifies which file the XBSA
# messages should be written to.
#
NSR_DEBUG_FILE=/nsr/applogs/xbsa.messages
###########################################################################
# Do not edit anything below this line.
###########################################################################
# Set up the PATH environment variable. This must be configured to include
# the path to the "nsrsybrc", "nsrsybsv", and "nsrsybcc" executables.
PATH=:/bin:/usr/sbin:/opt/networker/bin:/usr/bin:/usr/sbin/nsr
Pid=0 # process to kill if we are cancelled
nsrsybsv_status=0 # did it work?
#
# Make sure all environment variables are exported
#
export_environment_variables()
{
if [ "$NSR_COMPRESSION" != "" ]
then
export NSR_COMPRESSION
fi
if [ "$NSR_AES_ENCRYPTION" != "" ]
then
export NSR_AES_ENCRYPTION
fi
if [ "$NSR_LOG_VOLUME_POOL" != "" ]
then
export NSR_LOG_VOLUME_POOL
fi
if [ "$NSR_DATA_VOLUME_POOL" != "" ]
then
export NSR_DATA_VOLUME_POOL
fi
if [ "$NSR_GROUP" != "" ]
then
export NSR_GROUP
fi
if [ "$PRECMD" != "" ]
then
export PRECMD
fi
if [ "$POSTCMD" != "" ]
then
export POSTCMD
fi
if [ "$SYBASE" != "" ]
then
export SYBASE
fi
if [ "$PATH" != "" ]
then
export PATH
fi
if [ "$NSR_ASE_PASSWORD" != "" ]
then
export NSR_ASE_PASSWORD
fi
if [ "$NSR_ASE_VERIFY" != "" ]
then
export NSR_ASE_VERIFY
fi
if [ "$NSR_DEBUG_FILE" != "" ]
then
export NSR_DEBUG_FILE
fi
}
#
# Handle cancel signals sent by savegrp when user stops the group.
#
handle_signal()
{
if [ $Pid != 0 ]; then
kill -2 $Pid
fi
exit 1
}
#
# Utility function for adding parameters on to the existing precmd.
# This is used to build up the precmd from the command line arguments.
#
add_arg_to_pre_command()
{
if [ "$1" != "" ]
then
PRECMD=$PRECMD" ""$1"
fi
}
#
# Process the arguments to find the saveset name.
# this will be used in the PRECMD for the database
# consistency check. The only things we check for
# are parameters that we'll need to use for the
# nsrsybcc program.
#
# This also builds the actual backup command. Group
# names are problematic since the quoting doesn't work
# quite right, so we always export the group name.
#
processargs()
{
DBCC_SAVESET_NAME=
DBCC_USERNAME=
DBCC_PASSWORD=
DBCC_CLIENT=
DBCC_SERVER=
DBCC_DEBUG=
DBCC_QUIET=
DBCC_VERBOSE=
# Add the backup options to the backup command.
BACKUP_COMMAND="nsrsybsv"
if [ "${BACKUP_OPT}" != "" ];
then
BACKUP_COMMAND=$BACKUP_COMMAND" ""$BACKUP_OPT"
fi
while test $# -gt 0
do
case "$1" in
-N) # Get the save set name
DBCC_SAVESET_NAME="$2"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1 $2"
shift
shift
;;
-g) # get the group name
NSR_GROUP=$2
shift
shift
;;
-U) # get the user name
DBCC_USERNAME="$1 $2"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1 $2"
shift
shift
;;
-P) # get the password
DBCC_PASSWORD="$1 $2"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1 $2"
shift
shift
;;
-c) # get the client
DBCC_CLIENT="$1 $2"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1 $2"
shift
shift
;;
-s) # get the server
DBCC_SERVER="$1 $2"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1 $2"
shift
shift
;;
-D) # get the debug level
DBCC_DEBUG="$1 $2"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1 $2"
shift
shift
;;
-q) # get the quiet flag
DBCC_QUIET="$1"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1"
shift
;;
-v) # get the verbose flag
DBCC_VERBOSE="$1"
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1"
shift
;;
*) # it is some other argument that we will skip
BACKUP_COMMAND=$BACKUP_COMMAND" ""$1"
shift
;;
esac
done
#
# If we don't already have a PRECMD and we are supposed to
# do a database consistency check, we'll build the PRECMD
# to be a database consistency check of the save set name
# supplied. We'll take the default nsrsybcc options.
# To change the options the consistency check uses, edit the PRECMD line
# with the desired options.
#
if [ "${PRECMD}" = "" ] && [ "${USE_CONSISTENCY_CHECK}" != "" ]
then
PRECMD=nsrsybcc
add_arg_to_pre_command "$DBCCOPT"
add_arg_to_pre_command "$DBCC_USERNAME"
add_arg_to_pre_command "$DBCC_PASSWORD"
add_arg_to_pre_command "$DBCC_CLIENT"
add_arg_to_pre_command "$DBCC_SERVER"
add_arg_to_pre_command "$DBCC_DEBUG"
add_arg_to_pre_command "$DBCC_QUIET"
add_arg_to_pre_command "$DBCC_VERBOSE"
add_arg_to_pre_command "$DBCC_SAVESET_NAME"
fi
}
#
# The main portion of this shell.
#
#
# Make sure we respond to savegrp cancellations.
#
trap handle_signal 2 15
#
# Build the nsrsybsv command
#
#
# Find the saveset name to use for the database consistency check
# and construct the BACKUP_COMMAND to call nsrsybsv.
#
processargs "$@"
#
# Export all necessary environment variables
#
export_environment_variables
#
# Call nsrsybsv to do the backups.
#
# echo ${BACKUP_COMMAND}
${BACKUP_COMMAND} &
Pid=$!
wait $Pid
nsrsybsv_status=$?
if [ $nsrsybsv_status != 0 ] ; then
echo "nsrsybsv returned status of "$nsrsybsv_status
echo $0 "exiting."
exit 1
fi
exit 0
谢谢你啦 |
|