RMAN笔记小结

时间:2022-08-20 11:42:54

首先感谢junsansi和leshani两位大师的文笔;我可是好好看了很多遍;这两位哦;我跟你们说;对rman的解说那是相当精彩;文章形如流水,通俗易懂;内容那是入木三分...;好了我也不多说了,反正我现在也词穷了;对一个语文不及格的来说;说了这么多成语也不容易;××费就不收你们的了;说真的很感谢这两位;反正我对rman相当的研究了。rman:(Recovery Manager);顾名思义那就是一个备份/恢复的工具;同时对迁移,克隆也是一把好手。说到迁移...DG好像有话说;暂时不让它说。

对oracle数据库备份/恢复;

  • 备份还是采用rman备份的好;原因吗?因为rman就是用来备份+恢复的工具。哦???。
  1. rman只备份oracle用到过的数据块;可以跳过未使用的数据块;这样备份集比“物理备份”要少;比逻辑备份我就不说了
  2. 它能够备份整个数据库或数据库部件,如表空间、数据文件、控制文件、归档文件以及Spfile参数文件。

好处当然不只1-2点;容你慢慢去学习。

  • 至于恢复吗

尽量使用flase database去恢复;如这恢复不了(这是要看你能够闪回的最晚时间;或者是文件丢失)。才去用rman去恢复。

有了完整的备份;一起都是浮云;这话说的有点大?但是备份还是不能少;

下面是一些笔记(挑选);至于详细大家还是去看他们的博客;我这就不复制了。

1.  alter system switch logfile 和 alter system archive log current 区别和含义:
alter system switch logfile 是强制日志切换,不一定就归档当前的重做日志文件(若自动归档打开,就归档前的重做日志,若自动归档没有打开,就不归档当前重做日志。)
alter system archive log current 是归档当前的重做日志文件,不管自动归档有没有打都归档。

2.  备份控制文件

RMAN> backup current controlfile;

SQL>alter database backup controlfile to trace as '/data/control01.txt';
3. 密码文件
orapwd file=<fname> password=<password> entries=<users> force=<y/n>
orapwd file=orapwSY5221 password=oracle force=y entries=10            --force=y:表示允许覆盖原密码文件
 
4. 如何查找dbid
   rman target /
  SQL> select dbid from v$database;
 
5. filesperset 和 maxpiecesize的含义
   filesperset: 允许备份集文件最多有多少个。
   maxpiecesize  :允许备份集最大有多少

学习rman;至少要了解oracle体系结构(必要条件);里面的参数重在理解;能灵活运用。
例如;就三思出的那个定时备份的题目来说;我写的脚本就是这样的;
run{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
allocate channel c1 type disk;
backup database format 'f:\oracle\backup\back_%U' plus archivelog delete all input;
delete noprompt obsolete;
release channel c1;
}
还是那句话重在理解;能灵活运用。就行。
最后奉送一个备份脚本;很完善的rman备份脚本

 #!/bin/bash
 # User specific environment and startup programs  

 if [ -f ~/.bash_profile ];
 then
 source ~/.bash_profile
 fi  

 ORACLE_SID=ora11g;                            export ORACLE_SID
 RMAN_LEVEL=${};                              export RMAN_LEVEL
 TIMESTAMP=`date +%Y%m%d%H%M`;                 export TIMESTAMP
 DATE=`date +%Y%m%d`;                          export DATE
 RMAN_DIR=/data/backup/rman;   export RMAN_DIR
 RMAN_DATA=${RMAN_DIR}/${DATE};                export RMAN_DATA
 RMAN_LOG=/data/backup/log;                     export RMAN_LOG        

 # Check rman level
 #======================================================================
 if [ "$RMAN_LEVEL" == "F" ];
 then  unset INCR_LVL
       BACKUP_TYPE=full
 else
       INCR_LVL="INCREMENTAL LEVEL ${RMAN_LEVEL}"
       BACKUP_TYPE=lev${RMAN_LEVEL}
 fi  

 RMAN_FILE=${RMAN_DATA}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP};       export RMAN_FILE
 SSH_LOG=${RMAN_LOG}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}.log;      export SSH_LOG  

 MAXPIECESIZE=4G;                                                export MAXPIECESIZE  

 #Check RMAN Backup Path
 #=========================================================================  

 if ! test -d ${RMAN_DATA}
 then
 mkdir -p ${RMAN_DATA}
 fi  

 echo "---------------------------------" >>${SSH_LOG}
 echo "   " >>${SSH_LOG}
 echo "Rman Begin  to Working ........." >>${SSH_LOG}
 echo "Begin time at:" `date` --`date +%Y%m%d%H%M` >>${SSH_LOG}  

 #Startup rman to backup
 #=============================================================================
 $ORACLE_HOME/bin/rman log=${RMAN_FILE}.log << EOF
 connect target /
 run {
 CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF  DAYS;
 CONFIGURE BACKUP OPTIMIZATION ON;
 CONFIGURE CONTROLFILE AUTOBACKUP ON;
 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${RMAN_FILE}_%F';
 ALLOCATE CHANNEL 'ch1' TYPE DISK maxpiecesize=${MAXPIECESIZE};
 ALLOCATE CHANNEL 'ch2' TYPE DISK maxpiecesize=${MAXPIECESIZE};
 set limit channel ch1 readrate=;
 set limit channel ch1 kbytes=;
 set limit channel ch2 readrate=;
 set limit channel ch2 kbytes=;
 CROSSCHECK ARCHIVELOG ALL;
 DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
 BACKUP
 ${INCR_LVL}
 DATABASE FORMAT '${RMAN_FILE}_%U' TAG '${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}';
 SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
 BACKUP ARCHIVELOG ALL FORMAT '${RMAN_FILE}_arc_%U' TAG '${ORACLE_SID}_arc_${TIMESTAMP}'
 DELETE  INPUT;
 DELETE NOPROMPT OBSOLETE;
 RELEASE CHANNEL ch1;
 RELEASE CHANNEL ch2;
 }
 sql "alter database backup controlfile to trace as ''${RMAN_DATA}/cntl_${BACKUP_TYPE}.bak''";
 exit;
 EOF
 RC=$?  

 cat ${RMAN_FILE}.log >>${SSH_LOG}
 echo "Rman Stop working @ time:"`date` `date +%Y%m%d%H%M` >>${SSH_LOG}  

 echo >>${SSH_LOG}
 echo "------------------------" >>${SSH_LOG}
 echo "------ Disk Space ------" >>${SSH_LOG}
 df -h >>${SSH_LOG}  

 echo >>${SSH_LOG}  

 " ]; then
     echo "------ error ------" >>${SSH_LOG}
 else
     echo "------ no error found during RMAN backup peroid------" >>${SSH_LOG}
     rm -rf ${RMAN_FILE}.log
 fi  

 #Remove old backup than 3 days
 #============================================================================
 RMDIR=${RMAN_DIR}/`/bin/date +%Y%m%d -d "3 days ago"`;   export RMDIR
 echo >>${SSH_LOG}
 echo -e "------Remove old backup than 3 days ------\n" >>${SSH_LOG}  

 if test -d ${RMDIR}
     then
     rm -rf ${RMDIR}
     RC=$?
 fi  

 echo >>${SSH_LOG}  

 " ]; then
     echo -e "------ Remove old backup exception------ \n" >>${SSH_LOG}
 else
     echo -e "------ no error found during remove old backup set peroid------ \n" >>${SSH_LOG}
 fi  

 exit