Linux下RMAN备份脚本

SKIP 选项
Excludes datafiles or archived redo logs from the backup set according to the criteria specified by the following keywords.
Note: You can also specify this option in the backupSpec clause.

OFFLINE
Specifies that offline datafiles should be excluded from the backup set.

READONLY
Specifies that read-only datafiles should be excluded from the backup set.

INACCESSIBLE
Specifies that datafiles or archived redo logs that cannot be read due to I/O errors should be excluded from the backup set.

A datafile is only considered inaccessible if it cannot be read. Some offline datafiles can still be read because they still exist on disk. Others have been deleted or moved and

so cannot be read, making them inaccessible.


FILESPERSET = integer
Specifies the maximum number of input files in each backup set. If you set FILESPERSET = n, then RMAN never includes more than n files in a backup set. The default for

FILESPERSET is the lesser of these two values: 64, number of input files divided by the number of channels. For example, if you back up 100 datafiles by using two channels, RMAN

sets FILESPERSET to 50.

RMAN always attempts to create enough backup sets so that all allocated channels have work to do. An exception to the rule occurs when there are more channels than files to back up. For example, if RMAN backs up two datafiles when three channels are allocated and FILESPERSET = 1, then one channel is necessarily idle.

示例:
平均文件数指:文件数/通道数。
allocate channel 提供备份并发度,若平均文件数<filesperset则会按照 平均文件数/备份集 进行备份,若超过则按照filesperset的数量生成备份集;例如:
1、run {
allocate channel ch1 type disk;
allocate channel ch2 type disk;
backup datafile 3,4,5,6 filesperset 3;
release channel ch1;
release channel ch2;
}
平均数是 4(文件数)/2(channel数) = 2 ,小于filesperset 3,则生成2个备份集,每个备份集包含2个数据文件

2、run {
allocate channel ch1 type disk;
allocate channel ch2 type disk;
backup datafile 3,4,5,6 filesperset 1;
release channel ch1;
release channel ch2;
}
则生成4个备份集,每个包含一个数据文件 

rman nocatalog target sys/Oracle msglog rmanLog.out append  --将命令执行的日志追加到rmanLog.out文件,如果没有append,则会覆盖已有的rmanLog.out文件。

备份脚本:

  1. #########################################################################  
  2. ##   t_database_backup.sh      ##  
  3. ##   created by Tianlesoftware   ##  
  4. ##        2010-7-16                 ##  
  5. #########################################################################  
  6. #!/bin/bash  
  7. # ---------------------------------------------------------------------------  
  8. # Determine the user which is executing this script.  
  9. # ---------------------------------------------------------------------------  
  10. CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`  
  11.   
  12. # ---------------------------------------------------------------------------  
  13. # Put output in <this file name>.out. Change as desired.  
  14. # Note: output directory requires write permission.  
  15. # ---------------------------------------------------------------------------  
  16. RMAN_LOG_FILE=${0}.out  
  17. # ---------------------------------------------------------------------------  
  18. # You may want to delete the output file so that backup information does  
  19. # not accumulate.  If not, delete the following lines.  
  20. # ---------------------------------------------------------------------------  
  21. if [ -f "$RMAN_LOG_FILE" ]  
  22. then  
  23. rm -f "$RMAN_LOG_FILE"  
  24. fi  
  25. # -----------------------------------------------------------------  
  26. # Initialize the log file.  
  27. # -----------------------------------------------------------------  
  28. echo >> $RMAN_LOG_FILE  
  29. chmod 666 $RMAN_LOG_FILE  
  30. # ---------------------------------------------------------------------------  
  31. # Log the start of this script.  
  32. # ---------------------------------------------------------------------------  
  33. echo Script {1} >> $RMAN_LOG_FILE  
  34. echo ==== started on `date` ==== >> $RMAN_LOG_FILE  
  35. echo >> $RMAN_LOG_FILE  
  36. # ---------------------------------------------------------------------------  
  37. # Oracle home path.  
  38. # ---------------------------------------------------------------------------  
  39. ORACLE_HOME=/home/oracle/product/10.2.0/db_1  
  40. export ORACLE_HOME  
  41. # ---------------------------------------------------------------------------  
  42. # the Oracle SID of the target database.  
  43. # ---------------------------------------------------------------------------  
  44. ORACLE_SID=oralife  
  45. export ORACLE_SID  
  46. # ---------------------------------------------------------------------------  
  47. # The Oracle DBA user id (account).  
  48. # ---------------------------------------------------------------------------  
  49. ORACLE_USER=oracle  
  50. export ORACLE_USER  
  51. # ---------------------------------------------------------------------------  
  52. # Set the Oracle Recovery Manager name.  
  53. # ---------------------------------------------------------------------------  
  54. RMAN=$ORACLE_HOME/bin/rman  
  55. # ---------------------------------------------------------------------------  
  56. # Print out the value of the variables set by this script.  
  57. # ---------------------------------------------------------------------------  
  58. echo >> $RMAN_LOG_FILE  
  59. echo   "RMAN: $RMAN" >> $RMAN_LOG_FILE  
  60. echo   "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE  
  61. echo   "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE  
  62. echo   "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE  
  63. # ---------------------------------------------------------------------------  
  64. # Print out the value of the variables set by bphdb.  
  65. # ---------------------------------------------------------------------------  
  66. #echo  >> $RMAN_LOG_FILE  
  67. #echo   "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE  
  68. #echo   "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE  
  69. #echo   "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE  
  70. #echo   "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE  
  71. #echo   "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE  
  72. # ---------------------------------------------------------------------------  
  73. # NOTE: This script assumes that the database is properly opened. If desired,  
  74. # this would be the place to verify that.  
  75. # ---------------------------------------------------------------------------  
  76. echo >> $RMAN_LOG_FILE  
  77. # ---------------------------------------------------------------------------  
  78. # ---------------------------------------------------------------------------  
  79. # Call Recovery Manager to initiate the backup.  
  80. # ---------------------------------------------------------------------------  
  81.   
  82. CMD_STR="  
  83. ORACLE_HOME=$ORACLE_HOME  
  84. export ORACLE_HOME  
  85. ORACLE_SID=$ORACLE_SID  
  86. export ORACLE_SID  
  87. $RMAN nocatalog target sys/admin  msglog $RMAN_LOG_FILE append << EOF  
  88. RUN {  
  89. allocate channel c1 type disk;  
  90. allocate channel c2 type disk;  
  91.   
  92. BACKUP FORMAT '/home/oracle/backup/oralife_%U_%T' skip inaccessible filesperset 5  DATABASE TAG oralife_hot_db_bk;  
  93.   
  94. sql 'alter system archive log current';  
  95.   
  96. BACKUP FORMAT '/home/oracle/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;  
  97.   
  98. backup current controlfile tag='bak_ctlfile' format='/home/oracle/backup/ctl_file_%U_%T';  
  99. backup spfile tag='spfile' format='/home/oracle/backup/oralife_spfile_%U_%T';  
  100.   
  101. release channel c2;  
  102. release channel c1;  
  103. }  
  104. report obsolete;  
  105. delete noprompt obsolete;  
  106. crosscheck backup;  
  107. delete noprompt expired backup;  
  108. list backup summary;  
  109. #EOF  
  110. "  
  111. # Initiate the command string  
  112.   
  113. if [ "$CUSER" = "root" ]  
  114. then  
  115.     echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE  
  116.     su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE  
  117.     RSTAT=$?  
  118. else  
  119.     echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE  
  120.     /bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE  
  121.     RSTAT=$?  
  122. fi  
  123.   
  124. # ---------------------------------------------------------------------------  
  125. # Log the completion of this script.  
  126. # ---------------------------------------------------------------------------  
  127. if [ "$RSTAT" = "0" ]  
  128. then  
  129.     LOGMSG="ended successfully"  
  130. else  
  131.     LOGMSG="ended in error"  
  132. fi  
  133.   
  134. echo >> $RMAN_LOG_FILE  
  135. echo Script {1} >> $RMAN_LOG_FILE  
  136. echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE  
  137. echo >> $RMAN_LOG_FILE  
  138.   
  139. #/bin/mailx -s "RMAN Backup SID " [email protected] < $RMAN_LOG_FILE  
  140.   
  141. exit $RSTAT  

邮件配置...

相关推荐