环境:
OEL+Oracle 11.2.0.1
ORACLE_SID=orcl2
创建如下目录:
[root@DBA2 /]$ mkdir /backup
[root@DBA2 /]$ mkdir /backup/0
[root@DBA2 /]$ mkdir /backup/1
[root@DBA2 /]$ mkdir /backup/2
[root@DBA2 /]$ mkdir /backup/3
[root@DBA2 /]$ mkdir /backup/4
[root@DBA2 /]$ mkdir /backup/5
[root@DBA2 /]$ mkdir /backup/6
更改属主:
[root@DBA2 ~]# chown -R oracle:dba /backup/
脚本内容如下:
#########################################################
### backup.sh ###
#########################################################
##设置环境变量
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/OraHome
export ORACLE_SID=orcl2
export ORACLE_OWNER=oracle
export ORACLE_TERM=vt100
export PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/bin
NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252
export NLS_LANG
NOW=`date +%w`
rq=`date +%Y%m%d%H%M%S`
RMAN=$ORACLE_HOME/bin/rman
TARGET_CONNECT_STR=/
RMAN_LOG_FILE=/backup/$NOW/$ORACLE_SID.backup_all_out.log
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
FILE_NAME=/backup/$NOW/$ORACLE_SID.$rq
if [ "$NOW" = "0" ]
then
BACKUP_TYPE="INCREMENTAL LEVEL 0"
else
BACKUP_TYPE="INCREMENTAL LEVEL 1"
fi
##逻辑备份
exp system/oracle direct=Y full=y file=$FILE_NAME.logic log=/backup/$NOW/orcl2_logic_backup.log
cat /backup/$NOW/orcl2_logic_backup.log >> $RMAN_LOG_FILE
rm /backup/$NOW/orcl2_logic_backup.log
##物理备份
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
rq=$rq
export rq
$RMAN target $TARGET_CONNECT_STR msglog $RMAN_LOG_FILE append