- 论坛徽章:
- 0
|
这是owbackup-all脚本(Bourne Shell)内容:
wx02{owr5000}% more owbackup-all
#!/bin/sh
# Name:
# owbackup-all - Backup all OpenWorks projects managed by the user.
#
# Usage:
# owbackup-all <directory_name> [<extension>]
#
# The following one supports oracle with/without external file backup
# owbackup-all <directory_name> -OEXT <oracle_file_extension>
# -EXTFILEDIR <directory_name_to_store_External_Files>
# Examples:
# $OWHOME/bin/owbackup-all /pa/backups
# $OWHOME/bin/owbackup-all /export/home/backups -ow31.bck
#
# enhanced external file back up support
# $OWHOME/bin/owbackup-all /export/home/backups -OEXT _ow31.bck
# -EXTFILEDIR /export/home/backupExternal
# Arguments:
# directory_name - directory the backup files will be created in
# extension - extension for the backup file (.bck is the default)
# OR
# Arguments:
# directory_name - directory the backup file will be created in
# -OEXT <oracle_file_extension> the extension of the oracle backup file
#
# -EXTFILEDIR <directory_name_to_saveTheExternalFile> the directory the external
# file (OpenWorks project and seismic) back ups will be created in. if the user
# provided the directory name for the external file backups, it means all the
# external file backups should be done.
#
# Notes:
# To run this as a cron job, you must first set OWHOME, ORACLE_HOME,
# and ORACLE_SID. OWSYSSID also needs to be set if it isn't correct
# in $OWHOME/conf/lgcenv.cf.
#
# Description:
# This is a batch interface to the Project Backup functionality of Project
# Administration. It backs up each project the user has manager access to
# in the specified directory with a file name consisting of the project
# name appended to the given extension (or .bck if no extension was
# specified), i.e. TESTDATA.bck.
#
# Files/Databases:
# - $OWHOME/conf/lgcenv.cf OpenWorks Environment Variable File.
#
# Exit and Error Codes:
# - 0 : Successful
# - 1 : UnSuccessful
#
#
#----------------------------------------------------------------------------
# Copyright (C) 2006 LANDMARK GRAPHICS CORP.
# All rights reserved.
#============================================================================
# Added unset DISPLAY to solve Defect 146444 - owbackup/owrestore are using xprops
# which causes backups/restores to fail. TDP 10-Jan-03
#unset DISPLAY
#comment this unset DISPLAY for tar805604. if not comment this out, it does not work.
# Yan 28-Aug-2009
OSNAME=`uname`
print_help()
{
echo "usage: $0 arguments"
echo "arguments: (*) means mandatory"
echo " <directory_name_to_store_TheOracleFile> (*) set the directory to \
store the oracle backup file."
echo " [ -OEXT] <oracle_file_extension> set extension for oracle backup file."
echo " [ -EXTFILEDIR] <directory_name_to_store_TheExternalFiles> \
set the directory to store the project and seismic external backup files"
}
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "help" ]
then
print_help
exit 1
fi
if [ "$1" = "" ]
then
echo "$0: Error: missing <directory_name_to_store_TheOracleFile>"
print_help
exit 1
else
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Directory name to store the oracle backup file set to $1"
else
echo "Directory name to store the oracle backup file set to $1"
fi
oradirname=$1
# for backward compatibility, handle the special case: <directory_name> <extension>
if [ $# -eq 2 ]
then
EXTENSION=$2
fi
fi
# set the default oracle file extension
if [ $# -eq 1 ]; then
EXTENSION=.bck
fi
# in addition the exactly two arguments case, handle all other greater than two arguments cases
if [ $# -gt 2 ]
then
shift # move to the next flag
while [ $# -gt 0 ]
do
temp=$1
temp=`echo $temp | tr '[a-z]' '[A-Z]' ` # convert to upper case for the flag
case $temp in
# if we want to support the extension name start with dash '-', then need more work here
-OEXT) if [ "$2" = "" ] || [ `echo $2|grep "^-" |wc -l` -gt 0 ]
then
echo "$0: Error: missing <oracle_file_extension>"
print_help
exit 1
else
echo "Oracle file extension set to \"$2\""
EXTENSION=$2
shift
fi
;;
-EXTFILEDIR) if [ "$2" = "" ] || [ `echo $2|grep "^-" |wc -l` -gt 0 ]
then
echo "$0: Error: missing <directory_name_to_store_ExternalFiles>"
print_help
exit 1
else
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Directory name to store external files set to \"$2\""
else
echo "Directory name to store external files set to \"$2\""
fi
externaldir=$2
shift
fi
;;
*)
echo "unknown option flag: $1"
print_help
exit 1
;;
esac
shift
done
fi
# handle the case in which user does not specify the -OEXT oracle file extension
if [ "${EXTENSION}" = "" ]
then
EXTENSION=.bck
fi
# If the input extension does not contain a '.', the add a '.' to the extension
echo $EXTENSION | egrep -s '\.'
if [ $? -ne 0 ]; then
EXTENSION=.$EXTENSION
fi
DIRECTORY=$oradirname
# need to check and see if $DIRECTORY is a directory
if [ ! -d $DIRECTORY ]; then
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Input directory name $DIRECTORY is not valid."
else
echo "Input directory name $DIRECTORY is not valid."
fi
exit 1
else
# add the file separator to the DIRECTORY name, it works both in Unix and Windows
DIRECTORY=$DIRECTORY/
fi
# check the directory to store external backup file
if [ -n "${externaldir}" ]; then
if [ ! -d ${externaldir} ]; then
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Input directory name ${externaldir} is not valid."
else
echo "Input directory name ${externaldir} is not valid."
fi
exit 1
else
# add the file separator to the DIRECTORY name, it works both in Unix and Windows
EXTDIRECTORY=${externaldir}/
fi
fi
FILEEXTENSION=".zip"
#
# Set up OS dependent environment for NT or unix.
#
. ${OWHOME}/bin/OwSysDep
#
# Set OW_BATCH_MODE
#
OW_BATCH_MODE="TRUE"
export OW_BATCH_MODE
#
# Set User's name and run directory based on which OS
#
if [ `uname -s` = "Windows_NT" -o `uname -s` = "Windows_95" -o `uname -s` = "Windows_98" ]; then
USER="${USERNAME}"
RUNDIR="${HOME}"
else
if [ ! -d $HOME/run ]; then
mkdir -p $HOME/run
chmod 777 $HOME/run
fi
RUNDIR="${HOME}/run"
fi
#
# Which SID to backup
#
OWSYSSID=`lgc_getenv OWSYSSID`
if [ "${OWSYSSID:-""}" = "" ]; then
echo "*** ERROR: OWSYSSID not set. Correct and re-run."
exit 1
fi
OS_SQLPLUS=sqlplus
#
# find list of projects that user is a manager of
#
SQLCMD="set feedback off
set heading off
set pagesize 0
alter session set current_schema=owsys;
select project_name from owsys.ow_sys_prj_user
where user_id=upper('$USER') and security_level=3 minus
select project_name from owsys.ow_sys_project
where upper(project_type) = 'WORKING';"
PRJS=`echo "${SQLCMD}" | ${OS_SQLPLUS} -s ${owuser}/${owuserpwd}@${OWSYSSID} 2>${OS_NULLDIR}`
if [ "${PRJS:-""}" = "" ]; then
exit 0
fi
echo "Backing up all of" $USER "'s Projects: " $PRJS " on SID =" $OWSYSSID
#
# Find a list of projects that user is not manager of
#
SQLCMD2="set feedback off
set heading off
set pagesize 0
alter session set current_schema=owsys;
select project_name from owsys.ow_sys_prj_user minus
select project_name from owsys.ow_sys_prj_user
where user_id=upper('$USER') and security_level=3 minus
select project_name from owsys.ow_sys_project
where upper(project_type) = 'WORKING';"
PRJS2=`echo "${SQLCMD2}" | ${OS_SQLPLUS} -s ${owuser}/${owuserpwd}@${OWSYSSID} 2>${OS_NULLDIR}`
#
echo "========================================"
echo ""
if [ "${PRJS2:-""}" = "" ]; then
echo ""$USER" is capable of backing up all OpenWorks projects on instance "$OWSYSSID"."
else
echo "UNABLE to backup the following projects as" $USER "on SID =" $OWSYSSID "."
echo ""$USER" is not a manager of these projects:"
echo $PRJS2
fi
echo ""
echo "========================================"
#
#
# For each project this user has privileges for, do backup
#
## need to combine the $1(directoryname) + projectName + extension as a backupfileName
## to pass into the OwBackup.java as a file name.
EXITNUM=0
PRJARY=""
for p in $PRJS
do
APPLICATION="OwBatchBackupAll"
echo "Backup project $p now..."
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Check $RUNDIR/owbackup-all_$p.err for log message..."
else
echo "Check $RUNDIR/owbackup-all_$p.err for log message..."
fi
#print -r "*** pass in the backup file name: $DIRECTORY$p$EXTENSION"
if [ `uname -s` = "Windows_NT" -o `uname -s` = "Windows_95" -o `uname -s` = "Windows_98" ]; then
# if the external file directory is set, then pass in the external file name
# to the application and backup both oracle and external file for each project.
if [ -n "${EXTDIRECTORY}" ]; then
EXTERNALFILENAME="${EXTDIRECTORY}${p}_external${FILEEXTENSION}"
SEISMICFILENAME="${EXTDIRECTORY}${p}_seismic${FILEEXTENSION}"
echo "Application name: $APPLICATION"
echo "Sid name: $OWSYSSID"
echo "Project name: $p"
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Oracle backup file name: $DIRECTORY$p$EXTENSION"
print -r "External backup file name: ${EXTERNALFILENAME}"
print -r "Seismic backup file name: ${SEISMICFILENAME}"
else
echo "Oracle backup file name: $DIRECTORY$p$EXTENSION"
echo "External backup file name: ${EXTERNALFILENAME}"
echo "Seismic backup file name: ${SEISMICFILENAME}"
fi
$OWHOME/bin/OWRuntimeLauncher.bat "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" -ow "${EXTERNALFILENAME}" -s "${SEISMICFILENAME}"
2>$RUNDIR/owbackup-all_$p.err 1>&2
else
$OWHOME/bin/OWRuntimeLauncher.bat "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" 2>$RUNDIR/owbackup-all_$p.err 1>&2
fi
EXITNUM=$?
else
# if the external file directory is set, then pass in the external file name
# to the application and backup both oracle and external file for each project.
if [ -n "${EXTDIRECTORY}" ]; then
EXTERNALFILENAME="${EXTDIRECTORY}${p}_external${FILEEXTENSION}"
SEISMICFILENAME="${EXTDIRECTORY}${p}_seismic${FILEEXTENSION}"
echo "Application name: $APPLICATION"
echo "Sid name: $OWSYSSID"
echo "Project name: $p"
if [ "${OSNAME}" = "Windows_NT" ]
then
print -r "Oracle backup file name: $DIRECTORY$p$EXTENSION"
print -r "External backup file name: ${EXTERNALFILENAME}"
print -r "Seismic backup file name: ${SEISMICFILENAME}"
else
echo "Oracle backup file name: $DIRECTORY$p$EXTENSION"
echo "External backup file name: ${EXTERNALFILENAME}"
echo "Seismic backup file name: ${SEISMICFILENAME}"
fi
$OWHOME/bin/OWRuntimeLauncher.sh "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" -ow "${EXTERNALFILENAME}" -s "${SEISMICFILENAME}" 2
>$RUNDIR/owbackup-all_$p.err 1>&2
else
# only backup the oracle file.
$OWHOME/bin/OWRuntimeLauncher.sh "$APPLICATION" "$p" "$OWSYSSID" -oracle "$DIRECTORY$p$EXTENSION" 2>$RUNDIR/owbackup-all_$p.err 1>&2
fi
EXITNUM=$?
fi
if [ "${EXITNUM}" != "0" ]; then
PRJARY="$PRJARY $p\n"
else
echo "$p: project backup finished"
fi
done
if [ -n "${PRJARY}" ]; then
echo ""
echo "============== Backup the following project(s) failed ================"
if [ `uname -s` = "Linux" ]; then
echo -e $PRJARY
else
echo $PRJARY
fi
fi
|
|