Linux下RMAN備份指令碼

來源:互聯網
上載者:User

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 " daimm@sf-express.com < $RMAN_LOG_FILE  
  140.   
  141. exit $RSTAT  

郵件配置...

參考:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.