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

所属分类: 脚本专栏 / vbs 阅读数: 1442
收藏 0 赞 0 分享
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 "备份所有的日志文件成功,嘿嘿"

更多精彩内容其他人还在看

vbscript Split函数用法详解(字符串转数组函数)

本文详细介绍了vbscript中split函数的用法,有关split函数的一些实例,vbscript中split函数的语法介绍,有需要的朋友参考下
收藏 0 赞 0 分享

VBS实现将Excel表格保存为txt文本

希望能够找到个能给excel表另存为TXT的VBS代码,虽然另存为可以选择,但还是需要直接VBS执行这一步另存为TXT格式的,应该如何写代码呢
收藏 0 赞 0 分享

vbs解决处理TXT文本数据相关问题实现代码

使用vbs处理txt数据时,会遇到一些问题,本文将提供详细的解决方法,希望可以帮助你们
收藏 0 赞 0 分享

关于vbs 生成静态页面过程中出现的问题

访问某个aspx页面,然后把服务器返回的页面以filestream 的形式保存为html格式,接下来将介绍实现代码
收藏 0 赞 0 分享

dim函数第三个参数设置截取字符的长度问题

dim函数的第三个参数,也就是截取字符的长度,我在设置这个的时候,出了些问题,提示无效的过程调用或参数,本文详细介绍如何解决
收藏 0 赞 0 分享

邪恶的eval和new Function使用介绍

这些代码可以干什么?可以肯定的是可以干很多猥琐的事
收藏 0 赞 0 分享

WScript.Shell对象SpecialFolders属性未公开文档分享

WshShell对象的SpecialFolders属性返WshSpecialFolders 对象,该对象是一个特殊文件夹集合,其中包含整套Windows特殊文件夹
收藏 0 赞 0 分享

用VBS修改(设置)系统时间和日期的代码

用 VBS 把系统的时间修改到2038年1月19日3时14分07秒之后,这样某些依赖于 Unix 时间戳的程序就会出问题。那么怎样用 VBS 修改系统的时间呢
收藏 0 赞 0 分享

VBS For Next循环的一些细节

For Next 语句是 VBS 中常用的循环语句,你可能已经用过无数次 For Next 循环,但是你是否注意过它的一些细节呢
收藏 0 赞 0 分享

VBS For Next循环的陷阱分享

在《VBS For Next循环的一些细节》中说到了 For Next 循环的控制变量仅仅在循环开始前求值一次,但是其中存在一处陷阱
收藏 0 赞 0 分享
查看更多