#!/bin/ksh
# ##################################################################
#
# nightly_bkup.sh - nightly backup
# shell script
#
# ##################################################################
# Oracle Environment settings
PATH=/usr/bin:/usr/ucb:/etc:.:/usr/X/bin:/bin --不同的操作系统,系统命令位置不一样,如date命令,path比较重要
export PATH
ORACLE_SID=PPRD10 ; pw=oracle ; export pw ; export ORACLE_SID
ORACLE_BASE=/data/app/oracle ; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/10.2.0 ; export ORACLE_HOME
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data ; export ORA_NLS33
TNS_ADMIN=$ORACLE_HOME/network/admin ; export TNS_ADMIN
LD_LIBRARY_PATH=$ORACLE_HOME/lib ; export LD_LIBRARY_PATH
PATH=$ORACLE_HOME/bin:/usr/local/bin:/usr/ccs/bin:$PATH:/usr/sbin
export PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/product/jlib ; export CLASSPATH
backup_dir=/data/oradata/BACKUP/PPRD10
data_dir=/data/app/oracle/oradata/PPRD10
#
# Let's start with an export of the database
#
exp system/$pw file=$backup_dir/full_exp_`date +%y%m%d`_PPRD10.dmp full=y \
log=$backup_dir/full_exp_`date +%y%m%d`_PPRD10.log consistent=y > /dev/null
#采用数据泵要数directory的问题,参考我的数据泵的日志,
expdp newccs/hfccs123 DIRECTORY=dump_backup_dir DUMPFILE=NewccsTB_`date +%d%m%Y_%H%M%S`.dmp TABLESPACES=newccs logfile=NewccsTB_`date +%d%m%Y_%H%M%S`.log;
#date 这个date搞了我很长时间,应为没有注意path...
#如若不能显示,用which date 看下date的位置,加到path里就ok了
#
# Now, we'll shut down the database
#
sqlplus /nolog <<EOF
connect / as sysdba
shutdown immediate
EOF
#
# ...and copy the datafiles
#
cp -p $data_dir/* $backup_dir/datafiles/PPRD10
#
# Finally, we'll restart the database and be done
sqlplus /nolog <<EOF
connect / as sysdba
startup
EOF
#
# Just to be safe (with space), we'll compress the export file
#
cd $backup_dir
compress *.dmp
#
# Let's delete the backups and logs that are more than 1 days old
#
find $backup_dir -name "full_exp*" -mtime +1 -exec rm {} \;
#
# Cuz we shut down the database, the management server and intelligent
# agent need to be restarted -- doh!
#
#oemctrl start oms
lsnrctl start
# That's all, folks