在执行脚本之前,先修改几个参数值:
修改控制文件的保存时间,从默认的7天改成14天
SQL> show parameter control
SQL> alter system set control_file_record_keep_time=14 scope=both;
开启控制文件的自动备份,开启之后在数据库备份或者数据文件(比如添加数据文件)有修改的时候都会自动备份控制文件和spfile文件。
configure controlfile autobackup on;
当数据库兼容性设置为大于等于10.0.0时,尽管在没有0级备份情况做1级的增量备份实际上是一个全备,但是这个全备也是1级的,不能用作1级积累增量备份的基础备份,这个是在设计备份策略的时候要注意的问题。
#+--------------------------------------------------------------+
#|(C) 2011 LEISHIFEI All Right Reserved.
#+--------------------------------------------------------------+
#|File :hot_database_backup.sh
#|Source :$Source$
#|Description :Rman nocatalog full backup for Oracle 10g
#| linux or aix.
#+--------------------------------------------------------------+
#|Authors :leishifei
#+--------------------------------------------------------------+
#|Date :$Date$
#|Version :$Revision$
#+--------------------------------------------------------------+
#!/bin/sh
#+--------------------------------------------------------------+
# | Determine the user which is executing this script.
#+--------------------------------------------------------------+
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
#+--------------------------------------------------------------+
# | Put output in <this file name>.out. Change as desired.
# | Note: output directory requires write permission.
#+--------------------------------------------------------------+
RMAN_LOG_FILE=${0}.out
#+--------------------------------------------------------------+
# | You may want to delete the output file so that backup information does
# | not accumulate. If not, delete the following lines.
#+--------------------------------------------------------------+
if [ -f "$RMAN_LOG_FILE" ]
then
rm -f "$RMAN_LOG_FILE"
fi
#+--------------------------------------------------------------+
# | Initialize the log file.
#+--------------------------------------------------------------+
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
#+--------------------------------------------------------------+
# | Log the start of this script.
#+--------------------------------------------------------------+
echo Script $0 >> $RMAN_LOG_FILE
echo --------started on `date` -------->> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
#+--------------------------------------------------------------+
# | Oracle home path.
#+--------------------------------------------------------------+
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
#+--------------------------------------------------------------+
# | the Oracle SID of the target database.
#+--------------------------------------------------------------+
ORACLE_SID=orcl
export ORACLE_SID
#+--------------------------------------------------------------+
# | The Oracle DBA user id (account).
#+--------------------------------------------------------------+
ORACLE_USER=oracle
export ORACLE_USER
#+--------------------------------------------------------------+
# | Set the Oracle Recovery Manager name.
#+--------------------------------------------------------------+
RMAN=$ORACLE_HOME/bin/rman
#+--------------------------------------------------------------+
# | Print out the value of the variables set by this script.
#+--------------------------------------------------------------+
echo >> $RMAN_LOG_FILE
echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
#+--------------------------------------------------------------+
# | NOTE: This script assumes that the database is properly opened. If desired,
# | this would be the place to verify that.
#+--------------------------------------------------------------+
echo >> $RMAN_LOG_FILE
#+--------------------------------------------------------------+
# | Call Recovery Manager to initiate the backup.
#+--------------------------------------------------------------+
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog target sys/oracle msglog $RMAN_LOG_FILE append << EOF
RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/u01/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u01/backup/ORCL_spfile_%U_%T';
release channel c2;
release channel c1;
}
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
#EOF
"
#+--------------------------------------------------------------+
# | Initiate the command string
#+--------------------------------------------------------------+
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
#+--------------------------------------------------------------+
# | Log the completion of this script.
#+--------------------------------------------------------------+
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo --------$LOGMSG on `date` -------- >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
exit $RSTAT
#+--------------------------------------------------------------+
# | The end.
#+--------------------------------------------------------------+