定时自动备份IIS的WWW日志的vbs脚本
程序员文章站
2022-07-04 20:34:48
dim iiscount,iisobject,logfiledir,fso,logfileperiods,inputtime,site,sites,i,j,sit...
dim iiscount,iisobject,logfiledir,fso,logfileperiods,inputtime,site,sites,i,j,sitename(999),wshshell
'on error resume next
set wshshell = wscript.createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")
set iiscount=getobject("iis://localhost/w3svc")
sites=0
for each site in iiscount
if (site.class="iiswebserver") then
sitename(sites)=site.name
sites=sites+1
end if
next
msgbox "iis中一共" & sites & "个站点,id分别为:"
for j=1 to sites-1
msgbox sitename(j)
next
inputtime=inputbox("您要备份哪天的日志?如备份2004-01-01,则输入040101")
msgbox "备份" &inputtime& "天的日志"
msgbox "开始备份.............."
for i=0 to sites-1
set iisobject = getobject("iis://localhost/w3svc/" & sitename(i))
msgbox "备份id=" & sitename(i) &" sitename=" & iisobject.servercomment &"的站点"
logfiledir = iisobject.logfiledirectory & "w3svc" & sitename(i)'设置第一个站点的日志路径
if (err.number<>0) then logfiledir=iiscount.logfiledirectory
err.clear
'if iisobject.logfileperiod=1 then logfileperiods="days"
'if iisobject.logfileperiod=2 then logfileperiods="weeks"
'if iisobject.logfileperiod=3 then logfileperiods="months"
'if iisobject.logfileperiod=4 then logfileperiods="hours"
'if iisobject.logfileperiod=0 and iisobject.logfiletruncatesize=-1 then logfileperirods="onefile"
'if iisobject.logfileperiod=0 and iisobject.logfiletruncatesize>0 then logfileperirods="size"&iisobject.logfiletruncatesize
logfileperiods=iisobject.logfileperiod
if (err.number<>0) then logfileperiods=iiscount.logfileperiod
err.clear
if (not logfileperiods=1 and not logfileperiods=4) then
msgbox "对不起,您的日志偶就不给备份,咋地吧"
wscript.quit
end if
if (not fso.folderexists("d:backup")) then
msgbox "the folder d:backup is not exist,now create it"
fso.createfolder("d:backup")
msgbox "created d:backup succuful"
end if
if (not fso.folderexists("d:backup"&iisobject.servercomment)) then
msgbox "the folder d:backup" & iisobject.servercomment & " is not exist,now create it"
fso.createfolder("d:backup" & iisobject.servercomment)
msgbox "created d:backup" & iisobject.servercomment &" succuful"
end if
msgbox "now backup the logfiles"
logfiledir = wshshell.expandenvironmentstrings(logfiledir) '将环境变量转换成字符串
msgbox logfiledir
fso.copyfile logfiledir &"ex"&inputtime&"*","d:backup"& iisobject.servercomment
if err.number<>0 then
msgbox "this site no files"
else
msgbox "backup logfiles succuful"
end if
inputifdel=inputbox("是否删除已备份文件?输入“yes”进行删除")
if inputifdel="yes" then
fso.deletefile (logfiledir&"ex"&inputtime&"*")
msgbox "删除文件成功"
else
msgbox "文件已保留"
end if
next
msgbox "备份所有的日志文件成功,嘿嘿"
'on error resume next
set wshshell = wscript.createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")
set iiscount=getobject("iis://localhost/w3svc")
sites=0
for each site in iiscount
if (site.class="iiswebserver") then
sitename(sites)=site.name
sites=sites+1
end if
next
msgbox "iis中一共" & sites & "个站点,id分别为:"
for j=1 to sites-1
msgbox sitename(j)
next
inputtime=inputbox("您要备份哪天的日志?如备份2004-01-01,则输入040101")
msgbox "备份" &inputtime& "天的日志"
msgbox "开始备份.............."
for i=0 to sites-1
set iisobject = getobject("iis://localhost/w3svc/" & sitename(i))
msgbox "备份id=" & sitename(i) &" sitename=" & iisobject.servercomment &"的站点"
logfiledir = iisobject.logfiledirectory & "w3svc" & sitename(i)'设置第一个站点的日志路径
if (err.number<>0) then logfiledir=iiscount.logfiledirectory
err.clear
'if iisobject.logfileperiod=1 then logfileperiods="days"
'if iisobject.logfileperiod=2 then logfileperiods="weeks"
'if iisobject.logfileperiod=3 then logfileperiods="months"
'if iisobject.logfileperiod=4 then logfileperiods="hours"
'if iisobject.logfileperiod=0 and iisobject.logfiletruncatesize=-1 then logfileperirods="onefile"
'if iisobject.logfileperiod=0 and iisobject.logfiletruncatesize>0 then logfileperirods="size"&iisobject.logfiletruncatesize
logfileperiods=iisobject.logfileperiod
if (err.number<>0) then logfileperiods=iiscount.logfileperiod
err.clear
if (not logfileperiods=1 and not logfileperiods=4) then
msgbox "对不起,您的日志偶就不给备份,咋地吧"
wscript.quit
end if
if (not fso.folderexists("d:backup")) then
msgbox "the folder d:backup is not exist,now create it"
fso.createfolder("d:backup")
msgbox "created d:backup succuful"
end if
if (not fso.folderexists("d:backup"&iisobject.servercomment)) then
msgbox "the folder d:backup" & iisobject.servercomment & " is not exist,now create it"
fso.createfolder("d:backup" & iisobject.servercomment)
msgbox "created d:backup" & iisobject.servercomment &" succuful"
end if
msgbox "now backup the logfiles"
logfiledir = wshshell.expandenvironmentstrings(logfiledir) '将环境变量转换成字符串
msgbox logfiledir
fso.copyfile logfiledir &"ex"&inputtime&"*","d:backup"& iisobject.servercomment
if err.number<>0 then
msgbox "this site no files"
else
msgbox "backup logfiles succuful"
end if
inputifdel=inputbox("是否删除已备份文件?输入“yes”进行删除")
if inputifdel="yes" then
fso.deletefile (logfiledir&"ex"&inputtime&"*")
msgbox "删除文件成功"
else
msgbox "文件已保留"
end if
next
msgbox "备份所有的日志文件成功,嘿嘿"
上一篇: VBS通过WMI获取CPU使用率的代码