Chinaunix首页 | 论坛 | 博客
  • 博客访问: 669814
  • 博文数量: 128
  • 博客积分: 265
  • 博客等级: 二等列兵
  • 技术积分: 1464
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-27 20:44
个人简介

just do it

文章分类

全部博文(128)

文章存档

2023年(1)

2020年(1)

2019年(1)

2018年(3)

2017年(6)

2016年(17)

2015年(16)

2014年(39)

2013年(34)

2012年(10)

分类: Oracle

2015-10-13 08:21:18


点击(此处)折叠或打开

  1. oracle9i备份脚本:
  2. 全备(level 0):
  3. bash-3.00$ more ora9i_rman_bak.sh | grep -v "#"
  4.  
  5. CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
  6.  
  7. RMAN_LOG_FILE=${0}.out
  8. if [ -f "$RMAN_LOG_FILE" ]
  9. then
  10.         rm -f "$RMAN_LOG_FILE"
  11. fi
  12.  
  13. echo >> $RMAN_LOG_FILE
  14. chmod 666 $RMAN_LOG_FILE
  15.  
  16.  
  17. echo Script $0 >> $RMAN_LOG_FILE
  18. echo ==== started on `date` ==== >> $RMAN_LOG_FILE
  19. echo >> $RMAN_LOG_FILE
  20.  
  21. ORACLE_HOME=/orahome/oracle/product/9.2.0
  22. export ORACLE_HOME
  23. ORACLE_SID=bims
  24. export ORACLE_SID
  25. ORACLE_USER=oracle
  26. TARGET_CONNECT_STR=/
  27.  
  28. RMAN=$ORACLE_HOME/bin/rman
  29. echo >> $RMAN_LOG_FILE
  30. echo   "RMAN: $RMAN" >> $RMAN_LOG_FILE
  31. echo   "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
  32. echo   "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
  33. echo   "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
  34. echo  >> $RMAN_LOG_FILE
  35. echo   "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
  36. echo   "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
  37. echo   "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
  38. echo   "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
  39. echo   "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
  40. echo >> $RMAN_LOG_FILE
  41.  
  42. if [ "$NB_ORA_FULL" = "1" ]
  43. then
  44.         echo "Full backup requested" >> $RMAN_LOG_FILE
  45.         BACKUP_TYPE="INCREMENTAL LEVEL=0"
  46.  
  47. elif [ "$NB_ORA_INCR" = "1" ]
  48. then
  49.         echo "Differential incremental backup requested" >> $RMAN_LOG_FILE
  50.         BACKUP_TYPE="INCREMENTAL LEVEL=1"
  51.  
  52. elif [ "$NB_ORA_CINC" = "1" ]
  53. then
  54.         echo "Cumulative incremental backup requested" >> $RMAN_LOG_FILE
  55.         BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"
  56.  
  57. elif [ "$BACKUP_TYPE" = "" ]
  58. then
  59.         echo "Default - Full backup requested" >> $RMAN_LOG_FILE
  60.         BACKUP_TYPE="INCREMENTAL LEVEL=0"
  61. fi
  62. CMD_STR="
  63. ORACLE_HOME=$ORACLE_HOME
  64. export ORACLE_HOME
  65. ORACLE_SID=$ORACLE_SID
  66. export ORACLE_SID
  67. NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
  68. export NLS_DATE_FORMAT
  69. $RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append << EOF
  70. crosscheck archivelog all;
  71. delete noprompt expired archivelog all;
  72. RUN {
  73. ALLOCATE CHANNEL ch00 TYPE disk;
  74. ALLOCATE CHANNEL ch01 TYPE disk;
  75. ALLOCATE CHANNEL ch02 TYPE disk;
  76. ALLOCATE CHANNEL ch03 TYPE disk;
  77. BACKUP
  78.     $BACKUP_TYPE
  79.     SKIP INACCESSIBLE
  80.     TAG hot_db_bk_level0
  81.     FILESPERSET 5
  82.     FORMAT '/orahomebak/backup/database/bk_%s_%p_%t'
  83.     DATABASE;
  84.     sql 'alter system archive log current';
  85. RELEASE CHANNEL ch00;
  86. RELEASE CHANNEL ch01;
  87. RELEASE CHANNEL ch02;
  88. RELEASE CHANNEL ch03;
  89. ALLOCATE CHANNEL ch00 TYPE disk;
  90. ALLOCATE CHANNEL ch01 TYPE disk;
  91. BACKUP
  92.    filesperset 20
  93.    FORMAT '/orahomebak/backup/arch/al_%s_%p_%t'
  94.    ARCHIVELOG ALL DELETE INPUT;
  95. RELEASE CHANNEL ch00;
  96. RELEASE CHANNEL ch01;
  97. ALLOCATE CHANNEL ch00 TYPE disk;
  98. BACKUP
  99.     FORMAT '/orahomebak/backup/database/cntrl_%s_%p_%t'
  100.     CURRENT CONTROLFILE;
  101. RELEASE CHANNEL ch00;
  102. }
  103. EOF
  104. "
  105.  
  106. if [ "$CUSER" = "root" ]
  107. then
  108.     su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
  109.     RSTAT=$?
  110. else
  111.     /usr/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
  112.     RSTAT=$?
  113. fi
  114.  
  115.  
  116. if [ "$RSTAT" = "0" ]
  117. then
  118.     LOGMSG="ended successfully"
  119. else
  120.     LOGMSG="ended in error"
  121. fi
  122.  
  123. echo >> $RMAN_LOG_FILE
  124. echo Script $0 >> $RMAN_LOG_FILE
  125. echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
  126. echo >> $RMAN_LOG_FILE
  127.  
  128. exit $RSTAT
  129. Differential incremental backup(level 1):
  130. bash-3.00$ more ora9i_rman_bak.sh | grep -v "#"
  131.  
  132. CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
  133.  
  134. RMAN_LOG_FILE=${0}.out
  135. if [ -f "$RMAN_LOG_FILE" ]
  136. then
  137.         rm -f "$RMAN_LOG_FILE"
  138. fi
  139.  
  140. echo >> $RMAN_LOG_FILE
  141. chmod 666 $RMAN_LOG_FILE
  142.  
  143.  
  144. echo Script $0 >> $RMAN_LOG_FILE
  145. echo ==== started on `date` ==== >> $RMAN_LOG_FILE
  146. echo >> $RMAN_LOG_FILE
  147.  
  148. ORACLE_HOME=/orahome/oracle/product/9.2.0
  149. export ORACLE_HOME
  150. ORACLE_SID=bims
  151. export ORACLE_SID
  152. ORACLE_USER=oracle
  153. TARGET_CONNECT_STR=/
  154.  
  155. RMAN=$ORACLE_HOME/bin/rman
  156. echo >> $RMAN_LOG_FILE
  157. echo   "RMAN: $RMAN" >> $RMAN_LOG_FILE
  158. echo   "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
  159. echo   "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
  160. echo   "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
  161. echo  >> $RMAN_LOG_FILE
  162. echo   "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
  163. echo   "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
  164. echo   "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
  165. echo   "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
  166. echo   "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
  167. echo >> $RMAN_LOG_FILE
  168. echo "Differential incremental backup requested" >> $RMAN_LOG_FILE
  169. CMD_STR="
  170. ORACLE_HOME=$ORACLE_HOME
  171. export ORACLE_HOME
  172. ORACLE_SID=$ORACLE_SID
  173. export ORACLE_SID
  174. NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
  175. export NLS_DATE_FORMAT
  176. $RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append << EOF
  177. crosscheck archivelog all;
  178. delete noprompt expired archivelog all;
  179. RUN {
  180. ALLOCATE CHANNEL ch00 TYPE disk;
  181. ALLOCATE CHANNEL ch01 TYPE disk;
  182. ALLOCATE CHANNEL ch02 TYPE disk;
  183. ALLOCATE CHANNEL ch03 TYPE disk;
  184. BACKUP
  185.     INCREMENTAL LEVEL 1
  186.     SKIP INACCESSIBLE
  187.     TAG hot_db_bk_level1
  188.     FILESPERSET 5
  189.     FORMAT '/orahomebak/backup/database/bk_%s_%p_%t'
  190.     DATABASE;
  191.     sql 'alter system archive log current';
  192. RELEASE CHANNEL ch00;
  193. RELEASE CHANNEL ch01;
  194. RELEASE CHANNEL ch02;
  195. RELEASE CHANNEL ch03;
  196. ALLOCATE CHANNEL ch00 TYPE disk;
  197. ALLOCATE CHANNEL ch01 TYPE disk;
  198. BACKUP
  199.    filesperset 20
  200.    FORMAT '/orahomebak/backup/arch/al_%s_%p_%t'
  201.    ARCHIVELOG ALL DELETE INPUT;
  202. RELEASE CHANNEL ch00;
  203. RELEASE CHANNEL ch01;
  204. ALLOCATE CHANNEL ch00 TYPE disk;
  205. BACKUP
  206.     FORMAT '/orahomebak/backup/database/cntrl_%s_%p_%t'
  207.     CURRENT CONTROLFILE;
  208. RELEASE CHANNEL ch00;
  209. }
  210. EOF
  211. "
  212.  
  213. if [ "$CUSER" = "root" ]
  214. then
  215.     su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
  216.     RSTAT=$?
  217. else
  218.     /usr/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
  219.     RSTAT=$?
  220. fi
  221.  
  222.  
  223. if [ "$RSTAT" = "0" ]
  224. then
  225.     LOGMSG="ended successfully"
  226. else
  227.     LOGMSG="ended in error"
  228. fi
  229.  
  230. echo >> $RMAN_LOG_FILE
  231. echo Script $0 >> $RMAN_LOG_FILE
  232. echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
  233. echo >> $RMAN_LOG_FILE
  234.  
  235. exit $RSTAT

阅读(2285) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~