每天自动备份Oracle数据库,并压缩存档
最近系统测试运行,为了保留历史数据,所以写了一个自动备份数据库的脚本。
首先调用Exp备份,然后调用RAR压缩,并删除原始备份文件。所有备份的压缩文件都是保留的
关于自动执行的问题,我是调用了计划任务,目前一个半小时执行一次 运行了两天 基本正常
Option Explicit
On Error Resume Next
Dim fname, cmd
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
fname = FormatDateTime(Now(),2)
fname = fname+"-"+FormatDateTime(Now(),4)
fname = Replace(fname,":","-")
cmd = "exp log=../backup/DBBak_" & fname & ".log file=../backup/DBBak_" & fname & ".dmp parfile=exp.txt"
WshShell.run cmd
WScript.Sleep 300000
cmd = """C:\Program Files\WinRAR\rar"" m -ag ..\dbrar\DBBak.RAR ..\backup\DBBak_*.*"
WshShell.run cmd
Set WshShell = Nothing
'WScript.Echo cmd
On Error Resume Next
Dim fname, cmd
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
fname = FormatDateTime(Now(),2)
fname = fname+"-"+FormatDateTime(Now(),4)
fname = Replace(fname,":","-")
cmd = "exp log=../backup/DBBak_" & fname & ".log file=../backup/DBBak_" & fname & ".dmp parfile=exp.txt"
WshShell.run cmd
WScript.Sleep 300000
cmd = """C:\Program Files\WinRAR\rar"" m -ag ..\dbrar\DBBak.RAR ..\backup\DBBak_*.*"
WshShell.run cmd
Set WshShell = Nothing
'WScript.Echo cmd