定时自动备份IIS的WWW日志的vbs脚本
定时自动备份IIS的WWW日志的vbs脚本
发布时间:2016-12-28 来源:查字典编辑
摘要:dimIISCount,IISObject,logfiledir,fso,LogFilePeriods,inputtime,site,sit...

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"备份所有的日志文件成功,嘿嘿"

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新vbs学习
热门vbs学习
脚本专栏子分类