分类: Oracle
2008-04-23 08:02:42
一些作业需要立即通知有故障了,对于这些,我们使用一个VB脚本过滤我们是否遇到了错误并立即向我们发送也个广播,这个脚本一直运行并发送一封内容为日志输出的电子邮件,我们想获取关于这些作业的执行情况而不管它是否成功执行完没有,但是它如果失败的话,我们想得到一封内容为日志的电子邮件和一个广播来定位故障的位置,这个脚本调用3个参数:
代码清单17:
page_on_backup.vbs DBNAME_arc_only_disk.log page_DBNAME_arc_only.log DBNAME |
参数是一个日志名、脚本日志名和数据库名,下面是page_on_backup.vbs的内容,它在我们RMAN 0级备份和归档日志备份时执行。
代码清单18:
'This script emails the log file for a backup and searches it for the phrase "ORA-". If found, pages the recipients 'Additional pager Numbers ' whodat - 7045551212@message.alltel.com ' whodis - 7045551313@messaging.nextel.com Dim ArgObj, var1, var2 Set ArgObj = WScript.Arguments var1 = ArgObj(0) var2 = ArgObj(1) var3 = ArgObj(2) 'email log files Dim WshSHell1 : set WshShell1 = CreateObject("WScript.Shell") WshShell1.Run("D:\oracle\admin\common\error\bmail -s 10.10.10.10 -t support1@thecountyoverthere.gov -f Oracle@thecountyoverhere.gov -h -a " & var1 & " attached -m d:\oracle\admin\common\backup\logs\" & var1 &"") WshShell1.Run("D:\oracle\admin\common\error\bmail -s 10.10.10.10 -t support2@thecountyoverhere.gov -f Oracle@thecountyoverhere.gov -h -a " & var1 & " attached -m d:\oracle\admin\common\backup\logs\" & var1 &"") 'msgbox "var1 = " & var1 & " var2 = " & var2 & "" Const ForReading = 1, ForWriting = 2 Set WshNetwork = WScript.CreateObject("WScript.Network") Dim lgmain : Set lgmain = CreateObject("Scripting.FileSystemObject") Dim lgmain2 : Set lgmain2 = lgmain.OpenTextFile("D:\Oracle\Admin\common\backup\logs\" & var2 &"", ForWriting, True) lgmain2.WriteLine "Processing began: " & Now lgmain2.WriteLine "" lgmain2.WriteLine "" Set objRegEx = CreateObject("VBScript.RegExp") objRegEx.Global = True objRegEx.Pattern = "ORA-" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("D:\oracle\admin\common\backup\ logs\" & var1 & "", ForReading) strSearchString = objFile.ReadAll objFile.Close Set colMatches = objRegEx.Execute(strSearchString) If colMatches.Count > 0 Then Dim WshSHell2 : set WshShell2 = CreateObject("WScript.Shell") WshShell2.Run("D:\oracle\admin\common\error\bmail -s 10.10.10.10 -t 7045551414@my2way.com -f " & var3 & "@thecountyoverhere.gov -h -a " & var3 & "_BACKUP_ERRORS_FOUND") WshShell2.Run("D:\oracle\admin\common\error\bmail -s 10.10.10.10 -t support1@thecountyoverthere.gov -f " & var3 & "@thecountyoverhere.gov -h -a " & var3 & "_BACKUP_ERRORS_FOUND") WshShell2.Run("D:\oracle\admin\common\error\bmail -s 10.10.10.10 -t support2@thecountyoverhere.gov -f " & var3 & "@thecountyoverhere.gov -h -a " & var3 & "_BACKUP_ERRORS_FOUND") lgmain2.WriteLine "page completed" End If If colMatches.Count = 0 Then lgmain2.WriteLine "no problems found, no page required" End If |
首先发生的事情是发送一内容为日志信息的封电子邮件,接下来,在日志中查找错误代码,如果发现错误,就再发送一个广播,如果没有发现错误,脚本就执行完。
结尾
一个成功的备份计划是任何数据库管理员整个数据库策略中主要的组成部分,备份必须精心策划并经常检查,自动化备份是个好事情并非常有用,它也必须充分定义和严格测试,如果你考虑你的环境合乎逻辑它就可以做,问一下你自己“首先必须做什么?下一步必须做什么”等等,当你遇到困难是,思考是否有其他方法完成同一件事情,如果你尝试仔细思考你的环境这将变得更容易,这样你可以按原路返回,有时,改变任务的顺序也可以完成你的目标。