Vous êtes sur la page 1sur 16

Description

Displays physical size off all databases on a UNIX Machine.




Parameters
None
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh

export PATH=/usr/local/bin:$PATH

# Locate oratab file, exit if we can't find it
if [ -f /etc/oratab ]; then
ORATAB="/etc/oratab" ;
elif [ -f /var/opt/oracle/oratab ]; then
ORATAB="/var/opt/oracle/oratab" ;
else
echo
echo "ERROR: Unable to locate oratab file"
exit 1 ;
fi

for i in `egrep '^[a-zA-Z].*:.*:.*$' $ORATAB | awk -F: '{ print $1}' | sort -
u `
do

export ORACLE_SID=$i
export ORAENV_ASK=NO
. oraenv 2>/dev/null

sqlplus -s "/ as sysdba" << EOF 2>/dev/null
compute sum of Mb on report
break on report
col Mb form 999,999
select name, 'DataFiles', sum(df.bytes)/1024/1024 Mb
from dba_data_files df, v\$database
group by name
union
select name, 'TempFiles', sum(tf.bytes)/1024/1024 Mb
from dba_temp_files tf, v\$database
group by name;
exit
EOF
end..
Description
Full database export and compress using named pipes. Use the full database
import script to import the data back.
Parameters
$1 (MANDATORY) - ORACLE_SID of the database to export
$2 (MANDATORY) - The directory of the compressed export file
$3 (MANDATORY) - The database connect string to export from
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh
DATABASE=$1
DUMPDIR=$2
USERPASS=$3
# Check that we have a database to start
if [ -z "${DATABASE}" ]
then
echo
echo "No Database Specified !"
echo
echo "Usage : fulldbexport.ksh "
echo
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo " DUMPDIR - Directory of the compressed export file"
echo " CONNECT - Username/Password of the database user to export
from."
echo
echo " e.g. $ fulldbexport.ksh PROD /dbexport system/manager"
echo
exit 1
fi
# Check the dump directory exists
if [ ! -d "${DUMPDIR}" ]
then
echo
echo "$DUMPDIR does not exist !"
echo
exit 1
fi
# Check we have an Oracle username and password
if [ -z "${USERPASS}" ]
then
echo
echo "No Database connect string specified !"
echo
echo "Usage : fulldbexport.ksh "
echo
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo " DUMPDIR - Directory of the compressed export file"
echo " CONNECT - Username/Password of the database user to export
from."
echo
echo " e.g. $ fulldbexport.ksh PROD /dbexport system/manager"
echo
exit 1
fi
# Get the ORACLE_HOME from the oratab file
ORACLE_HOME=`cat /etc/oratab | grep $DATABASE | awk -F: '{print $2}'`
if [ ! -d "${ORACLE_HOME}" ]
then
echo
echo "$ORACLE_HOME does not exist !"
echo
exit 1
fi
ORACLE_SID=$DATABASE
export ORACLE_SID
PATH=.:$ORACLE_HOME/bin:$PATH; export PATH
LOGFILE=$DUMPDIR/exp${ORACLE_SID}_full.log
PIPEFILE=$DUMPDIR/PIPE.dmp
# Check we have created the named pipe file, or else there is no point
# continuing
if [ ! -p ${PIPEFILE} ]
then
echo
echo "Create the named pipe file ${PIPEFILE} using "
echo " $ mknod p $DUMPDIR/PIPE.dmp"
echo
exit 1
fi
# Create a new empty logfile
exec >$LOGFILE 2>&1
echo
echo "*******************************************************"
echo "* Exporting ${ORACLE_SID} database at `date`"
echo "*******************************************************"
echo

exp $USERPASS full=y consistent=y buffer=1000000 file=${PIPEFILE} | compress
< ${PIPEFILE} > $DUMPDIR/exp${ORACLE_SID}_full.dmp.Z
echo
echo "*******************************************************"
echo "* Export Completed at `date`"
echo "*******************************************************"
echo
exit 0

end
Description
Full database import and uncompress using named pipes.You will need this if
you use the full database export script.
Parameters
$1 (MANDATORY) - ORACLE_SID of the database to import
$2 (MANDATORY) - The directory of the compressed import file
$3 (MANDATORY) - The database connect string to import from
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh
DATABASE=$1
DUMPDIR=$2
USERPASS=$3
# Check that we have a database to start
if [ -z "${DATABASE}" ]
then
echo
echo "No Database Specified !"
echo
echo "Usage : fulldbimport.ksh "
echo
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo " DUMPDIR - Directory of the compressed import file"
echo " CONNECT - Username/Password of the database user to import
from."
echo
echo " e.g. $ fulldbimport.ksh PROD /dbexport system/manager"
echo
exit 1
fi
# Check the dump directory exists
if [ ! -d "${DUMPDIR}" ]
then
echo
echo "$DUMPDIR does not exist !"
echo
exit 1
fi
# Check we have an Oracle username and password
if [ -z "${USERPASS}" ]
then
echo
echo "No Database connect string specified !"
echo
echo "Usage : fulldbimport.ksh "
echo
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo " DUMPDIR - Directory of the compressed import file"
echo " CONNECT - Username/Password of the database user to import
from."
echo
echo " e.g. $ fulldbimport.ksh PROD /dbexport system/manager"
echo
exit 1
fi
# Get the ORACLE_HOME from the oratab file
ORACLE_HOME=`cat /etc/oratab | grep $DATABASE | awk -F: '{print $2}'`
if [ ! -d "${ORACLE_HOME}" ]
then
echo
echo "$ORACLE_HOME does not exist !"
echo
exit 1
fi
ORACLE_SID=$DATABASE
export ORACLE_SID
PATH=.:$ORACLE_HOME/bin:$PATH; export PATH
LOGFILE=$DUMPDIR/imp${ORACLE_SID}_full.log
PIPEFILE=$DUMPDIR/PIPE.dmp
# Check we have created the named pipe file, or else there is no point
# continuing
if [ ! -p ${PIPEFILE} ]
then
echo
echo "Create the named pipe file ${PIPEFILE} using "
echo " $ mknod p $DUMPDIR/PIPE.dmp"
echo
exit 1
fi
# Create a new empty logfile

exec >$LOGFILE 2>&1
echo
echo "*******************************************************"
echo "* Importing ${ORACLE_SID} database at `date`"
echo "*******************************************************"
echo
uncompress < $DUMPDIR/imp${ORACLE_SID}_full.dmp.Z > ${PIPEFILE} | imp
$USERPASS full=y ignore=y commit=y buffer=1000000 file=${PIPEFILE}
echo
echo "*******************************************************"
echo "* Import Completed at `date`"
echo "*******************************************************"
echo
exit 0

..end

Description
Generates SQL script put the tablespace in backup mode and to do a unix copy
to the backup directory. The datafiles can be copied to tape drive from the
backup directory disk copy.
Parameters
$1 (MANDATORY) - ORACLE_SID of the database to hot backup
$2 (MANDATORY) - The tablespace name to back up
$3 (MANDATORY) - The directory to backup the database
$4 (MANDATORY) - The database connect string to export from
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh
function Usage
{
echo ""
echo " Usage : hot_backup.ksh "
echo ""
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo " TABLESPACE NAME : Tablespace to backup "
echo ""
echo " e.g. $ hot_backup.ksh PROD USERS"
echo ""
}
#########################################################
# START OF MAIN SCRIPT
#########################################################
DATABASE=$1
TABLESPACE=$2; export TABLESPACE
ORA_BACKUP=$3; export ORA_BACKUP
USERPASS=$4
# Check that we have a database
if [ -z "${DATABASE}" ]
then
echo
echo "No Database Specified !"
echo
Usage
exit 1
fi
# Check that we have a tablespace name to back up
if [ -z "${TABLESPACE}" ]
then
echo
echo "No Tablespace Name Specified !"
echo
Usage
exit 1
fi
# Check the backup directory exists
if [ ! -d "${ORA_BACKUP}" ]
then
echo
echo "$ORA_BACKUP does not exist !"
echo
exit 1
fi
# Check we have an Oracle username and password
if [ -z "${USERPASS}" ]
then
echo
echo "No Database connect string specified !"
Usage
exit 1
fi
# Get the ORACLE_HOME from the oratab file
ORACLE_HOME=`cat /etc/oratab | grep $DATABASE | awk -F: '{print $2}'`
if [ ! -d "${ORACLE_HOME}" ]
then
echo
echo "$ORACLE_HOME does not exist !"
echo
exit 1
fi
ORACLE_SID=$DATABASE
export ORACLE_SID
PATH=.:$ORACLE_HOME/bin:$PATH; export PATH
# See if we can find svrmgrl, if not use sqldba instead
if [ -x "${ORACLE_HOME}/bin/svrmgrl" ]
then
SVR="svrmgrl"
else
SVR="sqldba lmode=y"
fi
# Generate the backup commands
#
sqlplus -s $USERPASS << EOF
set feed off pages 0 head off echo off line 250 ver off
col col1 newline
spool /tmp/hot1.sql
select 'select * from v$backup;' from dual;
select 'alter tablespace '||'${TABLESPACE}'||' begin backup;' from dual;
select 'host cp -p '||file_name||
' ${ORA_BACKUP}/'||
substr(file_name,instr(file_name,'dbs/')+7,length(file_name)) col1
from dba_data_files where tablespace_name=upper('${TABLESPACE}');
select 'select * from v$backup;' from dual;
select 'alter tablespace '||'{TABLESPACE}'||' end backup;' from dual;
select 'select * from v$backup;' from dual;
exit
EOF
#
# Now start the Backup
#
$SVR << EOF
connect internal
@/tmp/hot1.sql
exit
EOF
exit 0

..end
Description
Generates SQL script put the tablespace in backup mode and to do a unix copy
to the backup directory. The datafiles can be copied to tape drive from the
backup directory disk copy.
Parameters
$1 (MANDATORY) - ORACLE_SID of the database to hot backup
$2 (MANDATORY) - The tablespace name to back up
$3 (MANDATORY) - The directory to backup the database
$4 (MANDATORY) - The database connect string to export from.
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh

function Usage
{
echo ""
echo " Usage : hot_backup.ksh "
echo ""
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo " TABLESPACE NAME : Tablespace to backup "
echo " BACKUP DIRECTORY : target backup location "
echo ""
echo " e.g. $ hot_backup.ksh PROD USERS"
echo ""
}

#########################################################
# START OF MAIN SCRIPT
#########################################################

DATABASE=$1
TABLESPACE=$2; export TABLESPACE
ORA_BACKUP=$3; export ORA_BACKUP

USERPASS="/ as sysdba"

# Check that we have a database
if [ -z "${DATABASE}" ]
then
echo
echo "No Database Specified !"
echo
Usage
exit 1
fi
# Check that we have a tablespace name to back up
if [ -z "${TABLESPACE}" ]
then
echo
echo "No Tablespace Name Specified !"
echo
Usage
exit 1
fi
# Check the backup directory exists
if [ ! -d "${ORA_BACKUP}" ]
then
echo
echo "$ORA_BACKUP does not exist !"
echo
exit 1
fi
# Check we have an Oracle username and password
if [ -z "${USERPASS}" ]
then
echo
echo "No Database connect string specified !"
Usage
exit 1
fi

ORACLE_SID=$DATABASE
export ORACLE_SID
export ORAENV_ASK=NO
. oraenv

if [ ! -d "${ORACLE_HOME}" ]
then
echo
echo "$ORACLE_HOME does not exist !"
echo
exit 1
fi

# Generate the backup commands
#
sqlplus -s "${USERPASS}" << EOF
whenever sqlerror exit 1 rollback
whenever oserror exit 2
set lines 10000 head off feedback off echo off pages 0 termout off
set trims on verify off
col x noprint
col y noprint
col z noprint

spool /tmp/hot1.sql

select t.name z,
t.ts# y,
1 x,
'alter tablespace '||t.name||' begin backup;'
from v\$tablespace t,
dba_tablespaces tbs
where t.name=tbs.tablespace_name
and tbs.tablespace_name = '${TABLESPACE}'
and tbs.status = 'ONLINE'
and (tbs.contents !='TEMPORARY' or tbs.extent_management != 'LOCAL')
union
select d.name z,
d.ts# y,
2 x,
'host cp -p '||rtrim(d.NAME)||' ${ORA_BACKUP}'
from v\$datafile d, v\$tablespace t
where t.ts#=d.ts#
and t.name = '${TABLESPACE}'
union
select t.name z,
t.ts# y,
3 x,
'alter tablespace '||t.name||' end backup;'
from v\$tablespace t,
dba_tablespaces tbs
where t.name=tbs.tablespace_name
and tbs.tablespace_name = '${TABLESPACE}'
and tbs.status = 'ONLINE'
and (tbs.contents !='TEMPORARY' or tbs.extent_management != 'LOCAL')
order by 2,3
/

spool off

exit
EOF
if [ "${?}" != "0" ]
then
echo
echo Hot Backup Generate for tablespace ${TABLESPACE} !
echo
else
#
# Now start the Backup
#
sqlplus -s "${USERPASS}" << EOF
whenever sqlerror exit 2 rollback
whenever oserror exit 1
spool /tmp/hot1.log
@/tmp/hot1.sql
spool off
exit
EOF
if [ "${?}" != "0" ]
then
echo
echo Hot Backup Failed for tablespace ${TABLESPACE} !
echo
fi

fi
exit 0

end
Description
Shut database down and sets the database in Archive Log Mode.
Parameters
$1 (MANDATORY) - ORACLE_SID of the database to set ARCHIVELOG mode.
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh
DATABASE=$1
USERPASS="/ as sysdba"

# Check that we have a database
if [ -z "${DATABASE}" ]
then
echo
echo "No Database Specified !"
echo
echo "Usage : set_archivelog.ksh "
echo
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo
echo " e.g. $ set_archivelog.ksh PROD"
echo
exit 1
fi

ORACLE_SID=$DATABASE
export ORACLE_SID
export ORAENV_ASK=NO
. oraenv

if [ ! -d "${ORACLE_HOME}" ]
then
echo
echo "$ORACLE_HOME does not exist !"
echo
exit 1
fi

#
# SHUT THE DATABASE DOWN
#
sqlplus "${USERPASS}" << EOF
shutdown immediate
exit
EOF

sqlplus "${USERPASS}" << EOF
startup mount exclusive;
alter database archivelog;
alter database open;
archive log start
archive log list
exit
EOF

exit 0
.end
Description
Shut database down and sets the database in Archive Log Mode.

This script uses the assumes you've copied the shutdown database script as
shutdown_db.ksh


Parameters
$1 (MANDATORY) - ORACLE_SID of the database to set ARCHIVELOG mode
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/bin/ksh

DATABASE=$1

# Check that we have a database
if [ -z "${DATABASE}" ]
then
echo
echo "No Database Specified !"
echo
echo "Usage : set_archivelog.ksh "
echo
echo "where ORACLE_SID (Mandatory) - SID of database to start"
echo
echo " e.g. $ set_archivelog.ksh PROD"
echo
exit 1
fi

# Get the ORACLE_HOME from the oratab file
ORACLE_HOME=`cat /etc/oratab | grep $DATABASE | awk -F: '{print $2}'`
if [ ! -d "${ORACLE_HOME}" ]
then
echo
echo "$ORACLE_HOME does not exist !"
echo
exit 1
fi

ORACLE_SID=$DATABASE
export ORACLE_SID
PATH=.:$ORACLE_HOME/bin:$PATH; export PATH
# See if we can find svrmgrl, if not use sqldba instead
if [ -x "${ORACLE_HOME}/bin/svrmgrl" ]
then
SVR="svrmgrl"
else
SVR="sqldba lmode=y"
fi

./shutdown_db.ksh "${DATABASE}" "NORMAL"
$SVR << EOF
connect internal
startup mount exclusive;
alter database archivelog;
alter database open;
archive log start
archive log list
exit
EOF
exit 0
.end.
Description
Gives actual memory usage of Oracle from a Solaris Operating System using the
'pmap' function.
Parameters
See comments within Script
SQL Source
REM Copyright (C) Think Forward.com 1998- 2005. All rights reserved.

#!/usr/bin/sh


usage()
{
echo "Usage: $0 [ SB ]"
echo "Usage: $0 [ P ]"
echo "Usage: $0 [ h ]"
echo " "
echo "specify S for Oracle shadow processes"
echo "specify B for Oracle background processes (includes shared memory
SGA)"
echo "specify h for help"
echo " "
}
echo " "
#
# check usage
#
if [ $# = "0" ];then
usage;exit 1
fi
if [ $1 = "h" ];then
echo "This script uses the Sun Solaris pmap command to determine memory
usage
"
echo "for Oracle server [B]ackground processes and/or [S]hadow processes."
echo "An individual [P]rocess can also be specified."
echo " "
echo "Although the Oracle server background processes memory usage should"
echo "remain fairly constant, the memory used by any given shadow process"
echo "can vary greatly. This script shows only a snapshot of the current"
echo "memory usage for the processes specified."
echo " "
echo "The B option shows the sum of memory usage for all Oracle server"
echo "background processes, including shared memory like the SGA."
echo " "
echo "The S option shows the sum of private memory usage by all"
echo "shadow processes. It does not include any shared memory like the"
echo "SGA since these are part of the Oracle server background processes."
echo " "
echo "The P option shows memory usage for a specified process, broken"
echo "into two categories, private and shared. If the same executable"
echo "for this process was invoked again, only the private memory"
echo "would be allocated, the rest is shared with the currently running"
echo "process."
echo " "
usage;exit 1
fi
echo $1|grep [SBP] > /dev/null
ParmFound=$?
if [ $ParmFound != "0" ];then
usage;exit 1
fi
echo $1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
if [ $1 != "P" ];then
usage;exit 1
fi
if [ "X$2" = "X" ];then
usage;exit 1
fi
echo $2|grep [0-9] > /dev/null
ParmFound=$?
if [ $ParmFound != "0" ];then
usage;exit 1
fi
PidOwner=`ps -ef | grep -v grep | grep $2 | grep -v $0 | awk '{ print $1 }'`
CurOwner=`/usr/xpg4/bin/id -un`
if [ "X$PidOwner" != "X$CurOwner" ];then
echo "Not owner of pid $2, or pid $2 does not exist"
echo " "
usage;exit 1
fi
else
if [ "X${ORACLE_SID}" = "X" ];then
echo "You must set ORACLE_SID first"
usage;exit1
fi
fi
#
# initialize variables
#
Pmap="/usr/proc/bin/pmap"
SharUse="/tmp/omemuseS$$"
PrivUse="/tmp/omemuseP$$"
ShadUse="/tmp/omemuseD$$"
PidPUse="/tmp/omemusePP$$"
PidSUse="/tmp/omemusePS$$"
TotalShad=0
TotalShar=0
TotalPriv=0
PidPriv=0
PidShar=0
#
# shadow processes
#
echo $1|grep S > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
ShadPrc="`ps -ef|grep -v grep|grep oracle$ORACLE_SID|awk '{ print $2 }'`"
echo "" > $ShadUse
for i in $ShadPrc;do
$Pmap $i | grep "read/write" | grep -v shared | awk '{ print $2 }' | awk -
FK
'{ print $1 }' >> $ShadUse
done
for i in `cat $ShadUse`;do
TotalShad=`expr $TotalShad + $i`
done
TotalShad=`expr $TotalShad "*" 1024`
echo "Total Shadow (bytes) : $TotalShad"
/bin/rm $ShadUse
fi
#
# non-shared portion of background processes
#
echo $1|grep B > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
OrclPrc="`ps -ef|grep -v grep|grep ora_|grep $ORACLE_SID|awk '{ print $2 }'`"
BkgdPrc="`echo $OrclPrc|awk '{ print $1 }'`"
echo "" > $PrivUse
for i in $OrclPrc;do
$Pmap $i | grep "read/write" | grep -v shared | awk '{ print $2 }' \
| awk -FK '{ print $1 }' >> $PrivUse
done
for i in `cat $PrivUse`;do
TotalPriv=`expr $TotalPriv + $i`
done
TotalPriv=`expr $TotalPriv "*" 1024`
echo "Total Private (bytes) : $TotalPriv"
#
# shared portion of background processes
#
echo "" > $SharUse
$Pmap $BkgdPrc | grep "read/exec" | awk '{ print $2 }' \
| awk -FK '{ print $1 }' >> $SharUse
$Pmap $BkgdPrc | grep "shared" | awk '{ print $2 }' | awk -FK '{ print $1 }'
>>
$SharUse
for i in `cat $SharUse`;do
TotalShar=`expr $TotalShar + $i`
done
TotalShar=`expr $TotalShar "*" 1024`
echo "Total Shared (bytes) : $TotalShar"
/bin/rm $SharUse $PrivUse
fi
#
# non-shared portion of pid
#
echo $1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
echo "" > $PidPUse

$Pmap $2 | grep "read/write" | grep -v shared | awk '{ print $2 }' | awk -
FK
'{ print $1 }' >> $PidPUse
for i in `cat $PidPUse`;do
PidPriv=`expr $PidPriv + $i`
done
PidPriv=`expr $PidPriv "*" 1024`
echo "Total Private (bytes) : $PidPriv"
#
# shared portion of pid
#
echo "" > $PidSUse
$Pmap $2 | grep "read/exec" | awk '{ print $2 }' | awk -FK '{ print $1 }'
>>
$PidSUse
$Pmap $2 | grep "shared" | awk '{ print $2 }' | awk -FK '{ print $1 }' >>
$Pi
dSUse

for i in `cat $PidSUse`;do
PidShar=`expr $PidShar + $i`
done

PidShar=`expr $PidShar "*" 1024`
echo "Total Shared (bytes) : $PidShar"
/bin/rm $PidPUse $PidSUse
fi
#
# Display grand total
#
Gtotal="`expr $TotalShad + $TotalPriv + $TotalShar + $PidPriv + $PidShar`"
echo " -----"
echo "Grand Total (bytes) : $Gtotal"
echo " "

exit 0

Vous aimerez peut-être aussi