DB2 Data Links Manager Einstieg

online.sh

------------------------- start of 'online.sh' script ----------------------
#Ü/bin/ksh
 
# Sample script for performing a filesystem backup without bringing it
# offline for most of the duration of the backup
# Some sections of the script need to be modified by the users to suit their
# specific needs including replacing some of the parameters with their own.
#  Usage: onlineb <filesystem name>
 
#The dlfs filesystem being backed up would remain accessible in read-only mode
#for most of the time that the filesystem backup is going on.
#For a short while in between it may be necessary to have all users off the 
#filesystem. This would be required at two points; the first, when switching 
#the filesystem to read-only (an unmount followed by re-mount as read-only) 
#and the second when switching it back to read-write (unmount again followed by 
#re-mount as read-write)
 
# Environment dependent variables ...
# To be changed according to needs ...
DLFM_INST=sharada
PATH_OF_EXEC=/home/sharada/amit
 
 
# Local environment variables.
EXEC=quiesce
DLFM_DB_NAME=dlfm_db
 
 
# Function to check if root
check_id()  {
if [ `id -u` -ne 0 ]
then
	echo "You need to be root to run this"
	exit 1
fi}
 
#
# Function to quiesce the tables with Datalinks value in databases registered
# with DLFM_DB
#
quiesce_tables()  
{
    echo "Starting DB2 ..."
    su - $DLFM_INST "-c db2start | tail -n 1"  # Print just the last line
    su - $DLFM_INST "-c $PATH_OF_EXEC/$EXEC -q $DLFM_DB_NAME"
}
 
#
# Function to make the dlfs filesystem read-only 
#
# [The filesystem should not be in use during this time; no user should even
# have 'cd'-ied into the filesystem]
# 	- If the filesystem is NFS exported, unexport it
#
unexport_fs() {
    if exportfs | grep -w $filesystem_name 
    then
        echo $filesystem_name " is NFS exported"
        nfs_export_existed=1
        echo "Unexporting " $filesystem_name
        exportfs -u $filesystem_name
        result=$?
        if [ $result -ne 0 ]
        then
            echo "Failed to unexport " $filesystem_name
            reset_tables
            exit 1
fi    else
        echo $filesystem_name " is not NFS exported"
fi}
 
#
# Function to Unmount the filesystem
#
umount_fs() {
    echo "Unmounting " $filesystem_name
    umount $filesystem_name
    result=$?
    if [ $result -ne 0 ]
    then
        echo "Unable to unmount " $filesystem_name
        echo "Filesystem " $filesystem_name " may be in use"
        echo "Please make sure that no one is using the filesystem and"
        echo "and then press a key"
        read $ans 
        umount $filesystem_name
        result=$?
    fi	
    if [ $result -ne 0 ]
    then
        echo "Unable to unmount " $filesystem_name
        echo "Aborting ..."
        echo "Resetting the quiesced tables ..."
        reset_tables
        exit 1
fi	
    echo "Successfully unmounted " $filesystem_name
}	
 
#
# Function to remount the same filesystem back as read-only or
# read-write depending on the value of "RO" variable.
#
remount_fs()
{
    if [ $RO -eq 1 ] 
    then
        echo "Now re-mounting " $filesystem_name " as read-only"
        mount -v dlfs -r $filesystem_name
    else
        echo "Now re-mounting " $filesystem_name " as read-write"
        mount -v dlfs $filesystem_name
fi    result=$?
    if [ $result -ne 0 ]
    then
        echo "Failed to remount " $filesystem_name 
        echo "Aborting ..."
        reset_tables
        exit 1
fi    echo "Successfully re-mounted " $filesystem_name " as read-only"
}
 
 
#
# Function: If this was NFS exported, then export it a read-only now
#
make_fs_ro() {
    if [ $nfs_export_existed ]
    then
        echo "Re-exporting for NFS as read-only"
        chnfsexp -d $filesystem_name -N -t ro
        result=$?
        if [ $result -ne 0 ]
        then
            echo "Warning: Unable to NFS export " $filesystem_name
            # Not aborting here - continuing with a warning
            # at least the filesystem is available locally
            ## TBD: Or perhaps it would be better to exit 
        else
            echo "Successfully exported " $filesystem_name " as read-only"
fifi}
 
 
#
# Function to do the backup.
# Update this function with the backup command that you want to use.
#
do_backup()  {
 
    echo "Initiating backup of " $filesystem_name
 
#  [ Add lines here to issue your favourite backup command with the right
#    parameters, or uncomment one of the following ]
 
#  To invoke backup via smit, uncomment the following line
#  	smit fs	#  Select Backup a Filesystem
 
#	OR
#  To issue the backup command directly, uncomment and modify the following
#  line with your own options (for example full/incremental) and the 
#  appropriate parameters (you might want to replace /dev/rmt0 by the name of 
#  your backup device)
#	/usr/sbin/backup -f'/dev/rmt0' -'0' $filesystem_name
#	result=$?
#	if [ $result -ne 0 ]
#	then
#		echo "Backup failed"
#		# Do we exit here ? Or cleanup ?
#	else
#		echo "Successful backup"
#	fi
 
#	OR
# Put in your own backup script here
#
}
 
 
#
# Function to remount the filesystem as read-write. And NFS export it, if it
# was NFS exported to start with.
export_fs()  {
    if [ $nfs_export_existed ]
    then
        echo "Exporting back for NFS as read-write"
        chnfsexp -d $filesystem_name -N -t rw 
        result=$?
        if [ $result -ne 0 ]
        then
            echo "Warning: Unable to NFS export " $filesystem_name
            # Not aborting here - continuing with a warning
            # at least the filesystem is available locally
            # TBD: Or perhaps it would be better to exit 
        else
            echo "Successfully exported " $filesystem_name " as read-write"
fifi}
 
# Function to reset Quiesced tables
reset_tables()  {
  su - $DLFM_INST "-c $PATH_OF_EXEC/$EXEC -r $DLFM_DB_NAME"
}
 
 
#***************** MAIN PORTION  starts here ...*****************
 
#Check args
#
if [ $# -lt 1 ]
then
    echo "Usage: " $0 " <filesystem_name>"
    exit 1
fi
check_id
 
#  Quiesce tables ( after waiting for all transactions to get over ...)
quiesce_tables
 
# (i)  umount and remount the filesystem as read-only
 
filesystem_name=$1
unexport_fs
umount_fs
RO=1
remount_fs	  # READ_ONLY
make_fs_ro
 
# (ii) Start BackUp
 
do_backup
 
# (iii) unmount and remount the filesystem as read-write 
 
umount_fs
RO=0
remount_fs  # READ_WRITE
export_fs
 
# Reset all Quiesced tables ...
 
reset_tables
# Now the filesystem is ready for normal operation of Datalinks
echo "Done"
exit 0
------------------------- end of 'online.sh' script ------------------------
 


[ Seitenanfang | Vorherige Seite | Nächste Seite | Inhaltsverzeichnis | Index ]