Windows下RMAN備份程式碼

hexiaomail發表於2010-03-27

 

全備rman程式碼,用FullBackup_Level0.rman儲存:

run{

allocate channel c1 type disk format 'E:\Backup\%d_Full_0_%T_%s_%p_%I.rbak';

backup incremental level 0 database TAG='Ful_0';

release channel c1;

}

 

然後用vbs呼叫備份檔案Full_Backup.vbs

on error resume next

 

'這個函式只是把日期時間格式化一下,主要是用於備份log檔名的標識。

Function FormatDT(DateTime,Template)  

    If (Not IsDate(DateTime)) or Template = "" Then 

        FormatDT = Template  

        Exit Function 

    End If 

    Dim dtmY,dtmM,dtmD,dtmH ,dtmN,dtmS,dtmW  

    Dim arrFW,arrSW,arrFM,arrSM  

    dtmY = Year(DateTime)  

    dtmM = Month(DateTime)  

    dtmD = Day(DateTime)  

    dtmH  = Hour(DateTime)  

    dtmN = Minute(DateTime)  

    dtmS = Second(DateTime)  

    dtmW = WeekDay(DateTime)  

    arrFW = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")   

    arrSW = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")  

    arrFM = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")  

    arrSM = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")  

 

    Template = Replace(Template,"{Y}",dtmY)  

    Template = Replace(Template,"{y}",Right(dtmY,2))  

    Template = Replace(Template,"{M}",dtmM)  

    Template = Replace(Template,"{m}",Right("00"&dtmM,2))  

    Template = Replace(Template,"{ME}",arrFM(dtmM-1))  

    Template = Replace(Template,"{Me}",arrSM(dtmM-1))  

    Template = Replace(Template,"{D}",dtmD)  

    Template = Replace(Template,"{d}",Right("00"&dtmD,2))  

    Template = Replace(Template,"{H}",dtmH )  

    Template = Replace(Template,"{h}",Right("00"&dtmH ,2))  

    Template = Replace(Template,"{N}",dtmN)  

    Template = Replace(Template,"{n}",Right("00"&dtmN,2))  

    Template = Replace(Template,"{S}",dtmS)  

    Template = Replace(Template,"{s}",Right("00"&dtmS,2))  

    Template = Replace(Template,"{W}",arrFW(dtmW-1))  

    Template = Replace(Template,"{w}",arrSW(dtmW-1))  

    FormatDT = Template  

End Function 

 

呼叫RMAN備份

dt = FormatDT(Now(),"{Y}{m}{d}-{h}{n}{s}")

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run "CMD /C CD E:\Backupt & rman target / cmdfile E:\Backup\rmanScript\FullBackup_Level0.rman msglog E:\Backup\rmanScript\log\FullBackup_" & dt & ".log",0,true

 

'函式呼叫示例:  

'wscript.echo FormatDT(Now(),"{Y}-{M}-{D} {H}:{N}:{S}") & "
" 

'wscript.echo FormatDT(Now(),"{Y}{M}{D} {H}{N}{S}") & "
" 

'wscript.echo FormatDT(Now(),"{w},{D} {Me} {Y}") & "
" 

'wscript.echo FormatDT(Now(),"{h}:{n}:{s}")

 

'==================================================================  

'函式:FormatDT  

'作者:Abo(wupwu@qq.com)  

'日期:2008.09.07  

'功能:日期時間格式化  

'引數:DateTime,日期時間  

'   Template,格式化模板  

'返回:格式化後的字串  

'備註:模板標籤註釋  

'   {Y}:  

'   {y}:2位年  

'   {M}:  

'   {m}:補位月,例:01,02  

'   {ME}:英文月份  

'   {Me}:英文月份縮寫  

'   {D}:  

'   {d}:補位日  

'   {H}:  

'   {h}:補位時  

'   {N}:  

'   {n}:補位分  

'   {S}:  

'   {s}:補位秒  

'   {W}:星期幾英文  

'   {w}:星期幾英文縮寫  

'修改記錄:  

'==================================================================

 

最後在執行計劃中呼叫Full_Backup.vbs,這個要注意執行計劃中Run as:,使用ORA_DBA組中的本地使用者NT AUTHORITY\SYSTEM

C:\WINDOWS\system32\cscript.exe E:\Backup\rmanScript\Full_Backup.vbs

 

增量及日誌程式碼則類似!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9932141/viewspace-630543/,如需轉載,請註明出處,否則將追究法律責任。

相關文章