rman備份腳本

  1. [oracle@11rac1 ~]$ cat hot_rman_backup.sh

  2. #!/bin/sh

  3. # $Header: hot_database_backup.sh,v 1.3 2010/08/04 17:56:02 $

  4. #

  5. # ---------------------------------------------------------------------------

  6. # this script directory.

  7. # ---------------------------------------------------------------------------

  8. SHELL_HOME=/home/oracle

  9. # ---------------------------------------------------------------------------

  10. # Determine the time executing this script.

  11. # ---------------------------------------------------------------------------

  12. RMAN_DATA=`date'+%Y%m%d%H'`

  13. # ---------------------------------------------------------------------------

  14. # test log directiry .  If not, run the following lines.

  15. # ---------------------------------------------------------------------------

  16. if [ ! -d "$SHELL_HOME/log" ]

  17. then

  18.        mkdir -p $SHELL_HOME/log

  19. fi

  20. # ---------------------------------------------------------------------------

  21. # Put outputin <this file name>.out. Change as desired.

  22. # Note: output directory requires write permission.

  23. # ---------------------------------------------------------------------------

  24. RMAN_LOG_FILE=${SHELL_HOME}/log/hot_rman_backup_${RMAN_DATA}.out

  25. # ---------------------------------------------------------------------------

  26. # You may want todelete the output file so that backup information does

  27. # not accumulate.  If not, delete the following lines.

  28. # ---------------------------------------------------------------------------

  29. if [ -f "$RMAN_LOG_FILE" ]

  30. then

  31.        rm -f "$RMAN_LOG_FILE"

  32. fi

  33. # ---------------------------------------------------------------------------

  34. # rman p_w_picpath output directory.

  35. # ---------------------------------------------------------------------------

  36. RMAN_IMAGE_DIR=/home/oracle/rman

  37. echo "rman p_w_picpath output directory:${RMAN_IMAGE_DIR}">>$RMAN_LOG_FILE

  38. # ---------------------------------------------------------------------------

  39. # Log the start of this script.

  40. # ---------------------------------------------------------------------------

  41. echo Script $0 >> $RMAN_LOG_FILE

  42. echo ==== started on `date` ==== >> $RMAN_LOG_FILE

  43. echo >> $RMAN_LOG_FILE

  44. # ---------------------------------------------------------------------------

  45. # Replace /db/oracle/product/ora102, below, with the Oracle home path.

  46. # ---------------------------------------------------------------------------

  47. ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

  48. export ORACLE_HOME

  49. # ---------------------------------------------------------------------------

  50. # Replace ora102, below, with the Oracle SID of the target database.

  51. # ---------------------------------------------------------------------------

  52. ORACLE_SID=power1

  53. export ORACLE_SID

  54. # ---------------------------------------------------------------------------

  55. # Set the target connect string.

  56. # Replace"sys/manager", below, with the target connect string.

  57. # ---------------------------------------------------------------------------

  58. TARGET_CONNECT_STR=sys/manager

  59. # ---------------------------------------------------------------------------

  60. # Set the Oracle Recovery Manager name.

  61. # ---------------------------------------------------------------------------

  62. RMAN=$ORACLE_HOME/bin/rman

  63. # ---------------------------------------------------------------------------

  64. # Print out the value of the variables setby this script.

  65. # ---------------------------------------------------------------------------

  66. echo >> $RMAN_LOG_FILE

  67. echo   "RMAN: $RMAN" >> $RMAN_LOG_FILE

  68. echo   "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE

  69. echo   "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE

  70. echo   "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE

  71. # ---------------------------------------------------------------------------

  72. # Print out the value of the variables setby bphdb.

  73. # ---------------------------------------------------------------------------

  74. echo  >> $RMAN_LOG_FILE

  75. # ---------------------------------------------------------------------------

  76. # NOTE: This script assumes that the databaseis properly opened. If desired,

  77. # this would be the place to verify that.

  78. # ---------------------------------------------------------------------------

  79. echo >> $RMAN_LOG_FILE

  80. # ---------------------------------------------------------------------------

  81. # If this script is executed from a NetBackup schedule, NetBackup

  82. # sets an NB_ORA environment variable based on the schedule type.

  83. # The NB_ORA variable isthen used to dynamically set BACKUP_TYPE

  84. # For example, when:

  85. #     schedule type is                BACKUP_TYPE is

  86. #     ----------------                --------------

  87. # Automatic Full                     INCREMENTAL LEVEL=0

  88. # Automatic Differential Incremental INCREMENTAL LEVEL=1

  89. # Automatic Cumulative Incremental   INCREMENTAL LEVEL=1 CUMULATIVE

  90. #  

  91. # Foruser initiated backups, BACKUP_TYPE defaults to incremental

  92. # level 0 (full).  To change the defaultfor a user initiated

  93. # backup to incremental or incremental cumulative, uncomment

  94. # one of the following two lines.

  95. # BACKUP_TYPE="INCREMENTAL LEVEL=1"

  96. # BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"

  97. #  

  98. # Note that we use incremental level 0 to specify full backups.

  99. # That is because, although they are identical in content, only

  100. # the incremental level 0 backup can have incremental backups of

  101. # level > 0 applied to it.

  102. # ---------------------------------------------------------------------------

  103. INCR_DATA=`date'+%A'`

  104. if [ "$INCR_DATA" = "Sunday" ]

  105. then

  106.        echo "Full backup requested" >> $RMAN_LOG_FILE

  107.        BACKUP_TYPE="INCREMENTAL LEVEL=0"

  108. else

  109.        echo "Differential incremental backup requested" >> $RMAN_LOG_FILE

  110.        BACKUP_TYPE="INCREMENTAL LEVEL=1"

  111. #elif [ "$NB_ORA_CINC" = "1" ]

  112. #then

  113. #        echo "Cumulative incremental backup requested" >> $RMAN_LOG_FILE

  114. #        BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"

  115. #  

  116. #elif [ "$BACKUP_TYPE" = "" ]

  117. #then

  118. #        echo "Default - Full backup requested" >> $RMAN_LOG_FILE

  119. #        BACKUP_TYPE="INCREMENTAL LEVEL=0"

  120. fi

  121. echo "BACKUP_TYPE">> $RMAN_LOG_FILE

  122. echo ${BACKUP_TYPE} >> $RMAN_LOG_FILE

  123. # ---------------------------------------------------------------------------

  124. # Call Recovery Manager to initiate the backup. This example does not use a

  125. # Recovery Catalog. If you choose to use one, replace the option'nocatalog'

  126. # from the rman command line below with the  

  127. # 'catalog <userid>/<passwd>@<net service name>' statement.

  128. #

  129. # Note: Any environment variables needed at run timeby RMAN  

  130. #       must be setand exported within the switch user (su) command.

  131. # ---------------------------------------------------------------------------

  132. #  Backs up the whole database.  This backup is part of the incremental

  133. #  strategy (this means it can have incremental backups of levels > 0

  134. #  applied to it).

  135. #

  136. #  We do not need to explicitly request the control file to be included

  137. #  in this backup, as it is automatically included each time file 1 of

  138. #  the system tablespace is backed up (the inference: as it is a whole

  139. #  database backup, file 1 of the system tablespace will be backed up,

  140. #  hence the controlfile will also be included automatically).

  141. #

  142. #  Typically, a level 0 backup would be done at least once a week.

  143. #

  144. #  The scenario assumes:

  145. #     o you are backing your database up to two tape drives

  146. #     o you want each backup setto include a maximum of 5 files

  147. #     o you wish to include offline datafiles, andread-only tablespaces,

  148. #       in the backup

  149. #     o you want the backup tocontinue if any files are inaccessible.

  150. #     o you are not using a Recovery Catalog

  151. #     o you are explicitly backing up the control file.  Since you are

  152. #       specifying nocatalog, the controlfile backup that occurs

  153. #       automatically as the result of backing up the system file is

  154. #       not sufficient; it will not contain records for the backup that

  155. #       is currently in progress.

  156. #     o you want to archive the current log, back up all the

  157. #       archive logs using two channels, putting a maximum of 20 logs

  158. #       in a backup set, and deleting them once the backup is complete.

  159. #

  160. #  Note that the format string is constructed to guarantee uniqueness and

  161. #  to enhance NetBackup for Oracle backup and restore performance.

  162. #

  163. #

  164. #  NOTE WHEN USING NET SERVICE NAME: When connecting to a database

  165. #  using a net service name, you must use a send command or a parms operand to

  166. #  specify environment variables.  In other words, when accessing a database

  167. #  through a listener, the environment variables setat the system level are not

  168. #  visible when RMAN is running.  For more information on the environment

  169. #  variables, please refer to the NetBackup for Oracle Admin. Guide.

  170. #

  171. # ---------------------------------------------------------------------------

  172. ORACLE_HOME=$ORACLE_HOME

  173. export ORACLE_HOME

  174. ORACLE_SID=$ORACLE_SID

  175. export ORACLE_SID

  176. $RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append << EOF

  177. RUN {

  178. ALLOCATE CHANNEL ch00 TYPE DISK;

  179. ALLOCATE CHANNEL ch01 TYPE DISK;

  180. # crosscheck archivelog  

  181. CROSSCHECK ARCHIVELOG ALL;

  182. # crosscheck backup p_w_picpath

  183. CROSSCHECK BACKUP;

  184. #DELETE OBSOLETE BACKUP IMAGE

  185. DELETE NOPROMPT OBSOLETE;

  186. #DELETE EXPIRED BACKUP IMAGE

  187. DELETE NOPROMPT EXPIRED BACKUP;  

  188. BACKUP

  189.    $BACKUP_TYPE

  190.    SKIP INACCESSIBLE

  191.    TAG hot_db_bk_level0

  192.    FILESPERSET 2

  193.    # recommended format

  194.    FORMAT '${RMAN_IMAGE_DIR}/bk_%s_%p_%t'

  195. DATABASE;

  196.    sql 'alter system archive log current';

  197. RELEASE CHANNEL ch00;

  198. RELEASE CHANNEL ch01;

  199. # backup all archive logs

  200. ALLOCATE CHANNEL ch00 TYPE DISK;

  201. ALLOCATE CHANNEL ch01 TYPE DISK;

  202. BACKUP

  203.   filesperset 20

  204.   FORMAT '${RMAN_IMAGE_DIR}/al_%s_%p_%t'

  205.   ARCHIVELOG ALLDELETE INPUT;

  206. RELEASE CHANNEL ch00;

  207. RELEASE CHANNEL ch01;

  208. #

  209. # Note: During the process of backing up the database, RMAN also backs up the

  210. # control file.  This version of the control file does not contain the

  211. # information about the current backup because "nocatalog" has been specified.

  212. # To include the information about the current backup, the control file should

  213. # be backed up as the last step of the RMAN section.  This step would not be

  214. # necessary if we were using a recovery catalog or auto control file backups.

  215. #

  216. ALLOCATE CHANNEL ch00 TYPE DISK;

  217. BACKUP

  218.    # recommended format

  219.    FORMAT '${RMAN_IMAGE_DIR}/cntrl_%s_%p_%t'

  220. CURRENT CONTROLFILE;

  221. RELEASE CHANNEL ch00;

  222. }

  223. exit

  224. EOF

  225. # ---------------------------------------------------------------------------

  226. # Print dateto logfile

  227. # ---------------------------------------------------------------------------

  228. echo Script $0 >> $RMAN_LOG_FILE

  229. echo ==== endon `date` ==== >> $RMAN_LOG_FILE

  230. echo >> $RMAN_LOG_FILE

  231. 把腳本增加到crontab中

[oracle@11rac1 ~]$ crontab -l
1 3 * * * ksh /home/oracle/hot_rman_backup.sh >>/home/oracle/log/hot_rman_backup_crontab_`date "+\%Y\%m\%d\%H\%M"`.log 2>&1

每天早上的3點進行備份,另外我們還需要的就是在RMAN中配置備份的保留時間與controlfile與spfile的自己備份。



http://luoping.blog.51cto.com/534596/1009594

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章