定时自动备份IIS的WWW日志的vbs脚本

时间:2021-05-22

dimIISCount,IISObject,logfiledir,fso,LogFilePeriods,inputtime,site,sites,i,j,sitename(999),WshShell
'onerrorresumenext
setWshShell=WScript.CreateObject("WScript.Shell")
Setfso=CreateObject("scripting.FileSystemObject")
setIISCount=GetObject("IIS://localhost/w3svc")
sites=0
foreachsiteinIISCount
if(site.class="IIsWebServer")then
sitename(sites)=site.name
sites=sites+1
endif
next

MsgBox"IIS中一共"&sites&"个站点,ID分别为:"
forj=1tosites-1
MsgBoxsitename(j)
next

inputtime=inputbox("您要备份哪天的日志?如备份2004-01-01,则输入040101")
MsgBox"备份"&inputtime&"天的日志"

MsgBox"开始备份.............."
fori=0tosites-1
SetIISOBJect=GetObject("IIS://localhost/w3svc/"&sitename(i))
MsgBox"备份ID="&sitename(i)&"Sitename="&IISObject.servercomment&"的站点"
logfiledir=IISObject.LogFileDirectory&"w3svc"&sitename(i)'设置第一个站点的日志路径
if(Err.Number<>0)thenlogfiledir=IISCount.LogFileDirectory
Err.clear
'ifIISObject.LogFilePeriod=1thenLogFilePeriods="days"
'ifIISObject.LogFilePeriod=2thenLogFilePeriods="weeks"
'ifIISObject.LogFilePeriod=3thenLogFilePeriods="months"
'ifIISObject.LogFilePeriod=4thenLogFilePeriods="hours"
'ifIISObject.LogFilePeriod=0ANDIISObject.LogFileTruncateSize=-1thenLogFilePerirods="onefile"
'ifIISObject.LogFilePeriod=0ANDIISObject.LogFileTruncateSize>0thenLogFilePerirods="size"&IISObject.LogFileTruncateSize
LogFilePeriods=IISObject.LogFilePeriod
if(Err.Number<>0)thenLogFilePeriods=IISCount.LogFilePeriod
Err.clear
if(NOTLogFilePeriods=1ANDNOTLogFilePeriods=4)then
MsgBox"对不起,您的日志偶就不给备份,咋地吧"
WScript.quit
endif
if(NOTfso.folderexists("d:backup"))then
MsgBox"thefolderd:backupisnotexist,nowcreateit"
fso.CreateFolder("d:backup")
Msgbox"createdd:backupsuccuful"
endif
if(NOTfso.FolderExists("d:backup"&IISObject.servercomment))then
MsgBox"thefolderd:backup"&IISObject.servercomment&"isnotexist,nowcreateit"
fso.CreateFolder("d:backup"&IISObject.servercomment)
MsgBox"createdd:backup"&IISObject.servercomment&"succuful"
endif

MsgBox"nowbackupthelogfiles"
logfiledir=WshShell.ExpandEnvironmentStrings(logfiledir)'将环境变量转换成字符串
MsgBoxlogfiledir
fso.Copyfilelogfiledir&"ex"&inputtime&"*","d:backup"&IISObject.servercomment
ifErr.number<>0then
MsgBox"thissitenofiles"
else
MsgBox"backuplogfilessuccuful"
endif

inputifdel=inputbox("是否删除已备份文件?输入“YES”进行删除")
ifinputifdel="YES"then
fso.DeleteFile(logfiledir&"ex"&inputtime&"*")
MsgBox"删除文件成功"
else
MsgBox"文件已保留"
endif
next
MsgBox"备份所有的日志文件成功,嘿嘿"

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章