当前位置:Gxlcms > 数据库问题 > Oracle Policy For NBU

Oracle Policy For NBU

时间:2021-07-01 10:21:17 帮助过:12人阅读

Theory:NBU use a automatic script to connect RMAN and backup database
 
Steps:
First,make a automatic script.
Second,build a oracle policy
 
First:
Make a automatic script.NBU has provide some scripts on it‘s client directory
You can find it in /usr/openv/netbackup/ext/db_ext/oracle/samples/rman/
 
I choose a hot backup way to do this test:hot_database_backup.sh
 

You should change some variable which is be marked.


  1. [root@nbuserver rman]# cat hot_database_backup.sh
  2. #!/bin/sh
  3. # $Header: hot_database_backup.sh,v 1.3 2010/08/04 17:56:02 $
  4. #
  5. #bcpyrght
  6. #***************************************************************************
  7. #* $VRTScprght: Copyright 1993 – 2012 Symantec Corporation, All Rights Reserved $ *
  8. #***************************************************************************
  9. #ecpyrght
  10. #
  11. # —————————————————————————
  12. # hot_database_backup.sh
  13. # —————————————————————————
  14. # This script uses Recovery Manager to take a hot (inconsistent) database
  15. # backup. A hot backup is inconsistent because portions of the database are
  16. # being modified and written to the disk while the backup is progressing.
  17. # You must run your database in ARCHIVELOG mode to make hot backups. It is
  18. # assumed that this script will be executed by user root. In order for RMAN
  19. # to work properly we switch user (su -) to the oracle dba account before
  20. # execution. If this script runs under a user account that has Oracle dba
  21. # privilege, it will be executed using this user's account.
  22. # —————————————————————————
  23. # —————————————————————————
  24. # Determine the user which is executing this script.
  25. # —————————————————————————
  26. CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
  27. # —————————————————————————
  28. # Put output in <this file name>.out. Change as desired.
  29. # Note: output directory requires write permission.
  30. # —————————————————————————
  31. RMAN_LOG_FILE=${0}.out
  32. # —————————————————————————
  33. # You may want to delete the output file so that backup information does
  34. # not accumulate. If not, delete the following lines.
  35. # —————————————————————————
  36. if [ -f "$RMAN_LOG_FILE" ]
  37. then
  38. rm -f "$RMAN_LOG_FILE"
  39. fi
  40. # —————————————————————–
  41. # Initialize the log file.
  42. # —————————————————————–
  43. echo >> $RMAN_LOG_FILE
  44. chmod 666 $RMAN_LOG_FILE
  45. # —————————————————————————
  46. # Log the start of this script.
  47. # —————————————————————————
  48. echo Script $0 >> $RMAN_LOG_FILE
  49. echo ==== started on `date` ==== >> $RMAN_LOG_FILE
  50. echo >> $RMAN_LOG_FILE
  51. # —————————————————————————
  52. # Replace /db/oracle/product/ora102, below, with the Oracle home path.
  53. # —————————————————————————
  54. ORACLE_HOME=/db/oracle/product/ora102
  55. export ORACLE_HOME
  56. # —————————————————————————
  57. # Replace ora102, below, with the Oracle SID of the target database.
  58. # —————————————————————————
  59. ORACLE_SID=ora102
  60. export ORACLE_SID
  61. # —————————————————————————
  62. # Replace ora102, below, with the Oracle DBA user id (account).
  63. # —————————————————————————
  64. ORACLE_USER=ora102
  65. # —————————————————————————
  66. # Set the target connect string.
  67. # Replace "sys/manager", below, with the target connect string.
  68. # —————————————————————————
  69. TARGET_CONNECT_STR=sys/manager
  70. # —————————————————————————
  71. # Set the Oracle Recovery Manager name.
  72. # —————————————————————————
  73. RMAN=$ORACLE_HOME/bin/rman
  74. # —————————————————————————
  75. # Print out the value of the variables set by this script.
  76. # —————————————————————————
  77. echo >> $RMAN_LOG_FILE
  78. echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
  79. echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
  80. echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
  81. echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
  82. # —————————————————————————
  83. # Print out the value of the variables set by bphdb.
  84. # —————————————————————————
  85. echo >> $RMAN_LOG_FILE
  86. echo "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
  87. echo "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
  88. echo "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
  89. echo "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
  90. echo "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
  91. # —————————————————————————
  92. # NOTE: This script assumes that the database is properly opened. If desired,
  93. # this would be the place to verify that.
  94. # —————————————————————————
  95. echo >> $RMAN_LOG_FILE
  96. # —————————————————————————
  97. # If this script is executed from a NetBackup schedule, NetBackup
  98. # sets an NB_ORA environment variable based on the schedule type.
  99. # The NB_ORA variable is then used to dynamically set BACKUP_TYPE
  100. # For example, when:
  101. # schedule type is BACKUP_TYPE is
  102. # —————- ————–
  103. # Automatic Full INCREMENTAL LEVEL=0
  104. # Automatic Differential Incremental INCREMENTAL LEVEL=1
  105. # Automatic Cumulative Incremental INCREMENTAL LEVEL=1 CUMULATIVE
  106. #
  107. # For user initiated backups, BACKUP_TYPE defaults to incremental
  108. # level 0 (full). To change the default for a user initiated
  109. # backup to incremental or incremental cumulative, uncomment
  110. # one of the following two lines.
  111. # BACKUP_TYPE="INCREMENTAL LEVEL=1"
  112. # BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"
  113. #
  114. # Note that we use incremental level 0 to specify full backups.
  115. # That is because, although they are identical in content, only
  116. # the incremental level 0 backup can have incremental backups of
  117. # level > 0 applied to it.
  118. # —————————————————————————
  119. if [ "$NB_ORA_FULL" = "1" ]
  120. then
  121. echo "Full backup requested" >> $RMAN_LOG_FILE
  122. BACKUP_TYPE="INCREMENTAL LEVEL=0"
  123. elif [ "$NB_ORA_INCR" = "1" ]
  124. then
  125. echo "Differential incremental backup requested" >> $RMAN_LOG_FILE
  126. BACKUP_TYPE="INCREMENTAL LEVEL=1"
  127. elif [ "$NB_ORA_CINC" = "1" ]
  128. then
  129. echo "Cumulative incremental backup requested" >> $RMAN_LOG_FILE
  130. BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE"
  131. elif [ "$BACKUP_TYPE" = "" ]
  132. then
  133. echo "Default – Full backup requested" >> $RMAN_LOG_FILE
  134. BACKUP_TYPE="INCREMENTAL LEVEL=0"
  135. fi
  136. # —————————————————————————
  137. # Call Recovery Manager to initiate the backup. This example does not use a
  138. # Recovery Catalog. If you choose to use one, replace the option 'nocatalog'
  139. # from the rman command line below with the
  140. # 'catalog <userid>/<passwd>@<net service name>' statement.
  141. #
  142. # Note: Any environment variables needed at run time by RMAN
  143. # must be set and exported within the switch user (su) command.
  144. # —————————————————————————
  145. # Backs up the whole database. This backup is part of the incremental
  146. # strategy (this means it can have incremental backups of levels > 0
  147. # applied to it).
  148. #
  149. # We do not need to explicitly request the control file to be included
  150. # in this backup, as it is automatically included each time file 1 of
  151. # the system tablespace is backed up (the inference: as it is a whole
  152. # database backup, file 1 of the system tablespace will be backed up,
  153. # hence the controlfile will also be included automatically).
  154. #
  155. # Typically, a level 0 backup would be done at least once a week.
  156. #
  157. # The scenario assumes:
  158. # o you are backing your database up to two tape drives
  159. # o you want each backup set to include a maximum of 5 files
  160. # o you wish to include offline datafiles, and read-only tablespaces,
  161. # in the backup
  162. # o you want the backup to continue if any files are inaccessible.
  163. # o you are not using a Recovery Catalog
  164. # o you are explicitly backing up the control file. Since you are
  165. # specifying nocatalog, the controlfile backup that occurs
  166. # automatically as the result of backing up the system file is
  167. # not sufficient; it will not contain records for the backup that
  168. # is currently in progress.
  169. # o you want to archive the current log, back up all the
  170. # archive logs using two channels, putting a maximum of 20 logs
  171. # in a backup set, and deleting them once the backup is complete.
  172. #
  173. # Note that the format string is constructed to guarantee uniqueness and
  174. # to enhance NetBackup for Oracle backup and restore performance.
  175. #
  176. #
  177. # NOTE WHEN USING NET SERVICE NAME: When connecting to a database
  178. # using a net service name, you must use a send command or a parms operand to
  179. # specify environment variables. In other words, when accessing a database
  180. # through a listener, the environment variables set at the system level are not
  181. # visible when RMAN is running. For more information on the environment
  182. # variables, please refer to the NetBackup for Oracle Admin. Guide.
  183. #
  184. # —————————————————————————
  185. CMD_STR="
  186. ORACLE_HOME=$ORACLE_HOME
  187. export ORACLE_HOME
  188. ORACLE_SID=$ORACLE_SID
  189. export ORACLE_SID
  190. $RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append << EOF
  191. RUN {
  192. ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
  193. ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
  194. BACKUP
  195. $BACKUP_TYPE
  196. SKIP INACCESSIBLE
  197. TAG hot_db_bk_level0
  198. FILESPERSET 5
  199. # recommended format
  200. FORMAT 'bk_%s_%p_%t'
  201. DATABASE;
  202. sql 'alter system archive log current';
  203. RELEASE CHANNEL ch00;
  204. RELEASE CHANNEL ch01;
  205. # backup all archive logs
  206. ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
  207. ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
  208. BACKUP
  209. filesperset 20
  210. FORMAT 'al_%s_%p_%t'
  211. ARCHIVELOG ALL DELETE INPUT;
  212. RELEASE CHANNEL ch00;
  213. RELEASE CHANNEL ch01;
  214. #
  215. # Note: During the process of backing up the database, RMAN also backs up the
  216. # control file. This version of the control file does not contain the
  217. # information about the current backup because "nocatalog" has been specified.
  218. # To include the information about the current backup, the control file should
  219. # be backed up as the last step of the RMAN section. This step would not be
  220. # necessary if we were using a recovery catalog or auto control file backups.
  221. #
  222. ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
  223. BACKUP
  224. # recommended format
  225. FORMAT 'cntrl_%s_%p_%t'
  226. CURRENT CONTROLFILE;
  227. RELEASE CHANNEL ch00;
  228. }
  229. EOF
  230. "
  231. # Initiate the command string
  232. if [ "$CUSER" = "root" ]
  233. then
  234. su – $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
  235. RSTAT=$?
  236. else
  237. /usr/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
  238. RSTAT=$?
  239. fi
  240. # —————————————————————————
  241. # Log the completion of this script.
  242. # —————————————————————————
  243. if [ "$RSTAT" = "0" ]
  244. then
  245. LOGMSG="ended successfully"
  246. else
  247. LOGMSG="ended in error"
  248. fi
  249. echo >> $RMAN_LOG_FILE
  250. echo Script $0 >> $RMAN_LOG_FILE
  251. echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
  252. echo >> $RMAN_LOG_FILE
  253. exit $RSTAT

Ok ,after change this value.we can put it anywhere.but you had better remember it‘s path
 
Second:
We should build a Oracle policy
On the Netbackup Administration Console:
click policies>new policy  you should give a name
on this panel.choose oracle policy type.and choose your storage.then new a schedules.I choose Automatic full backup
and then new a client.
The last and important.In the Backup  Selections.you should add a path which direct to the scirpt.
 
ok.let‘s do a test.
click policy name.choose manual backup.you can go Activity Monitor to monitor your job.

Oracle Policy For NBU

标签:nbu   veritas   oracle   policy   

人气教程排行