#Set oracle path
#source $HOME/.keychain/${HOSTNAME}-sh
export SSH_AUTH_SOCK
echo $SSH_AUTH_SOCK
export PATH
unset USERNAME
export LD_ASSUME_KERNEL=2.4.1
export ORACLE_BASE=/opt/oracle9i
export ORACLE_HOME=$ORACLE_BASE/product/9.2.0
export ORACLE_SID=back1
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
#echo "-----------数据库环境设置完成-----------"
# Set shell search paths
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=american_america.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
#echo "----------脚本搜索环境设置完成----------"
# set the backup script enviroment variable.
#export USERPASS=/nolog
export BACKUP_BASE=/home/oracle/backup
export BACKUP_TARGET=${BACKUP_BASE}/data
#export TABLESPACE_TARGET=${BACKUP_TARGET}/tablespace
export DATABASE_TARGET=${BACKUP_TARGET}/database
export CTRFILE_TARGET=${BACKUP_TARGET}/ctrfile
#export ARCLOG_TARGET=${BACKUP_TARGET}/arclog
export LOG_TARGET=${BACKUP_BASE}/log
#echo "--------备份脚本环境变量设置完成---------"
#当前时间
CurDate=`date +%Y-%m-%d_%H:%M:%S`
LogDate=`date +%Y-%m-%d`
#ORACLE用户的用户名
OraUser=oracle
#要备份的表空间变量与登陆数据库的用户
#TableSpace=shiyihai #只在备份表空间时需要
User=sys
Psw=sys
DataBase=back2
#恢复目录用户,表空间与数据库名
RmanTs=rman_ts
RmanUser=rman
RmanPsw=rman
RmanDB=test2
#echo "-----------备份服务器设置完成-------------"
#参数校验
if [ "p"$1 = "p/?" ]
then
echo "Usage:rman_db.sh Command"
echo "------------------------------------------------"
echo "Command : backup (0,1,2,3,4) (增量备份的基础策略备份)"
echo "Parameter - 0 (全量备份)"
echo "Parameter - 1 (一级增量备份)"
echo "Parameter - 2 (二级增量备份)"
echo "Parameter - 3 (三级增量备份)"
echo "Parameter - 4 (四级增量备份)"
echo "------------------------------------------------"
echo "Command : full (备份整个数据库)"
echo "------------------------------------------------"
echo "Command : listts (显示表空间备份历史记录)"
echo "------------------------------------------------"
echo "Command : listdb (显示数据库备份历史记录)"
echo "------------------------------------------------"
#echo "Command : arclog (备份归档日志并删除)"
#echo "------------------------------------------------"
# echo "Command : recoverts (恢复表空间)"
exit
fi
if [ "p"$1 = "p" -o "p"$1$2 = "pbackupts" -o "p"$1$2 = "pbackupdb" ]
then
echo "Usage:rman_db.sh Command"
echo "------------------------------------------------"
echo "Command : backup (0,1,2,3,4) (增量备份的基础策略备份)"
echo "Parameter - 0 (全量备份)"
echo "Parameter - 1 (一级增量备份)"
echo "Parameter - 2 (二级增量备份)"
echo "Parameter - 3 (三级增量备份)"
echo "Parameter - 4 (四级增量备份)"
echo "------------------------------------------------"
echo "Command : full (备份整个数据库)"
echo "------------------------------------------------"
echo "Command : listts (显示表空间备份历史记录)"
echo "------------------------------------------------"
echo "Command : listdb (显示数据库备份历史记录)"
echo "------------------------------------------------"
# echo "Command : arclog (备份归档日志并删除)"
# echo "------------------------------------------------"
# echo "Command : recoverts (恢复表空间)"
exit
fi
if [ "p"$1$2 != "pbackup0" -a "p"$1$2 != "pbackup1" -a "p"$1$2 != "pbackup2" -a "p"$1$2 != "pbackup3" -a "p"$1$2 != "pbackup4" -a "p"$1 != "pfull" -a "p"$1 != "plistdb" ]
then
echo "Usage:rman_db.sh Command"
echo "------------------------------------------------"
echo "Command : backup (0,1,2,3,4)(备份数据库)"
echo "Parameter - 0 (增量备份的基础策略备份)"
echo "Parameter - 1 (一级增量备份)"
echo "Parameter - 2 (二级增量备份)"
echo "Parameter - 3 (三级增量备份)"
echo "Parameter - 4 (四级增量备份)"
echo "------------------------------------------------"
echo "Command : full (备份整个数据库)"
echo "------------------------------------------------"
echo "Command : listts (显示表空间备份历史记录)"
echo "------------------------------------------------"
echo "Command : listdb (显示数据库备份历史记录)"
echo "------------------------------------------------"
# echo "Command : arclog (备份归档日志并删除)"
# echo "------------------------------------------------"
# echo "Command : recoverts (恢复表空间)"
exit
fi
echo "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" >>${LOG_TARGET}/${LogDate}.log
#----------------------------------------------------------------------------------
#测试主备份目录是否可写
if ! test -w ${BACKUP_BASE}
then
echo "没有对${BACKUP_BASE}文件夹的写权限" >>${LOG_TARGET}/${LogDate}.log
echo "`date +%Y.%m.%d.%H.%M.%S`备份终止" >>${LOG_TARGET}/${LogDate}.log
echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
exit 1
fi
#------------------------------------------------------------------------------------
#检查文件夹是否存在
if ! test -d ${BACKUP_TARGET}
then
echo "-----没有备份目录,自动创建-----" >>${LOG_TARGET}/${LogDate}.log
mkdir ${BACKUP_TARGET}
fi
#if ! test -d ${TABLESPACE_TARGET}
#then
# echo "-----没有备份目录,自动创建-----" >>${LOG_TARGET}/${LogDate}.log
# mkdir ${TABLESPACE_TARGET}
#fi
#if ! test -d ${DATABASE_TARGET}
#then
# echo "-----没有备份目录,自动创建-----" >>${LOG_TARGET}/${LogDate}.log
# mkdir ${DATABASE_TARGET}
#fi
#if ! test -d ${CTRFILE_TARGET}
#then
# echo "-----没有备份目录,自动创建-----" >>${LOG_TARGET}/${LogDate}.log
# mkdir ${CTRFILE_TARGET}
#fi
#if ! test -d ${ARCLOG_TARGET}
#then
# echo "-----没有备份目录,自动创建-----" >>${LOG_TARGET}/${LogDate}.log
# mkdir ${ARCLOG_TARGET}
#fi
#------------------------------------------------------------------------------------
if ! test -d ${LOG_TARGET}
then
echo "-----没有日志目录,自动创建-----" >>${LOG_TARGET}/${LogDate}.log
mkdir ${LOG_TARGET}
fi
#----------------------------------------------------------------------------------
#echo "$CurDate 备份开始"
#-----------------------------------------------------------------------------------
#显示相关目录
#echo "基础备份目录 : " ${BACKUP_BASE}
#echo "备份数据文件目录 : " ${BACKUP_TARGET}
#echo "表空间备份目录 : " ${TABLESPACE_TARGET}
#echo "数据库备份目录 : " ${DATABASE_TARGET}
#echo "归档日志备份目录 : " ${ARCLOG_TARGET}
#echo "日志目录 : " ${LOG_TARGET}
#------------------------------------------------------------------------------------
#表空间备份
#if [ $1 = "backupts" ]
#then
#echo "`date +%Y-%m-%d_%H:%M:%S`开始${TABLESPACE}表空间备份" >>${LOG_TARGET}/${LogDate}.log
#rman target catalog <<-EOF >>${LOG_TARGET}/${LogDate}.log
# run {
# allocate channel dev1 type disk;
# backup
# incremental level $2
# filesperset 4
# format "${TABLESPACE_TARGET}/${TableSpace}_level${2}_s%s_t%t_p%p.bak"
# (tablespace ${TableSpace});
# }
# exit;
#EOF
# echo "`date +%Y-%m-%d_%H:%M:%S`${TABLESPACE}表空间备份结束" >>${LOG_TARGET}/${LogDate}.log
# echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" >>${LOG_TARGET}/${LogDate}.log
#fi
#数据库备份
if [ $1 = "backup" ]
then
echo "`date +%Y-%m-%d_%H:%M:%S`开始${DataBase}数据库备份" >>${LOG_TARGET}/${LogDate}.log
rman target catalog <<-EOF >>${LOG_TARGET}/${LogDate}.log
run {
allocate channel dev1 type disk;
backup
incremental level $2
filesperset 4
format "${BACKUP_TARGET}/%d_level${2}_s%s_t%t_p%p.bak"
(database);
}
exit;
EOF
echo "`date +%Y-%m-%d_%H:%M:%S`${DataBase}数据库备份结束" >>${LOG_TARGET}/${LogDate}.log
echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" >>${LOG_TARGET}/${LogDate}.log
fi
#显示表空间备份历史记录
if [ $1 = "listts" ]
then
rman target catalog <<-EOF
list backupset of tablespace $TableSpace;
exit;
EOF
fi
#显示数据库备份历史记录
if [ $1 = "listdb" ]
then
rman target catalog <<-EOF
list backupset of database database;
exit;
EOF
fi
#备份整个数据库
if [ $1 = "full" ]
then
echo "`date +%Y-%m-%d_%H:%M:%S`开始备份${DataBase}数据库" >>${LOG_TARGET}/${LogDate}.log
rman target catalog <<-EOF >>${LOG_TARGET}/${LogDate}.log
run {
allocate channel dev1 type disk;
backup
full
format "${BACKUP_TARGET}/%d_Full_s%s_t%t_p%p.bak"
(database);
}
exit;
EOF
echo "`date +%Y-%m-%d_%H:%M:%S`${DataBase}数据库备份结束" >>${LOG_TARGET}/${LogDate}.log
echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" >>${LOG_TARGET}/${LogDate}.log
fi
#备份归档日志并删除
#if [ $1 = "arclog" ]
#then
#echo "`date +%Y-%m-%d_%H:%M:%S`开始备份归档日志" >>${LOG_TARGET}/${LogDate}.log
#rman target catalog <<-EOF >>${LOG_TARGET}/${LogDate}.log
# run {
# allocate channel dev1 type disk;
# backup
# format "${ARCLOG_TARGET}/ARCLOG_s%s_t%t_p%p.bak"
# (archivelog all delete input);
# }
# exit;
#EOF
# echo "`date +%Y-%m-%d_%H:%M:%S`备份归档日志结束" >>${LOG_TARGET}/${LogDate}.log
# echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" >>${LOG_TARGET}/${LogDate}.log
#fi
#恢复表空间
#if [ $1 = "recoverts" ]
#then
#echo "`date +%Y-%m-%d_%H:%M:%S`开始恢复表空间" >>${LOG_TARGET}/${LogDate}.log
#rman target catalog <<-EOF >>${LOG_TARGET}/${LogDate}.log
# run {
# allocate channel dev1 type disk;
# sql "alter tablespace ${TABLESPACE} offline immediate";
# restore tablespace ${TABLESPACE};
# recover tablespace ${TABLESPACE};
# sql "alter tablespace ${TABLESPACE} online";
# }
# exit;
#EOF
# echo "`date +%Y-%m-%d_%H:%M:%S`恢复表空间结束" >>${LOG_TARGET}/${LogDate}.log
# echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" >>${LOG_TARGET}/${LogDate}.log
#fi
#恢复数据库
#if [ $1 = "recoverdb" ]
#then
#echo "`date +%Y-%m-%d_%H:%M:%S`开始恢复数据库" >>${LOG_TARGET}/${LogDate}.log
#rman target catalog <<-EOF >>${LOG_TARGET}/${LogDate}.log
# run {
# allocate channel dev1 type disk;
# sql "alter tablespace ${TABLESPACE} offline immediate";
# restore tablespace ${TABLESPACE}
# recover tablespace ${TABLESPACE}
# sql "alter tablespace ${TABLESPACE} online";
# }
# exit;
#EOF
# echo "`date +%Y-%m-%d_%H:%M:%S`恢复数据库结束" >>${LOG_TARGET}/${LogDate}.log
# echo "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" >>${LOG_TARGET}/${LogDate}.log
#fi
阅读(979) | 评论(0) | 转发(0) |