当前位置: 首页 > 图文教程 > 脚本技术 > VBScript > 定时自动备份IIS的WWW日志的vbs脚本

VBScript
用vbs脚本来关闭 HTML 页面的代码
用vbs实现确定是否安装了某个特定的补丁
用vbs确定用户的登录名的代码
用vbs找到映射到共享的所有驱动器并重新映射它们
可以从一台远程服务器运行 SP2 安装程序Install.vbs
用vbs判断一个日期是否在指定的时段内
vbs+hta中实现在单个 onClick 参数中包括多个子例程的代码
vbs中实现启动两个应用程序,一直等到其中一个程序结束,然后关闭另一个?
用vbs实现对文本文件中的项计数
用vbs对文本文件的内容进行排序
用vbscript把 Word 文档保存为文本文件的代码
用vbs返回 Internet Explorer 的下载控件和 Applet 的列表
用vbscript合并多个文本文件的代码
用vbscript防止本地用户更改其密码
用vbs针对一个 IP 地址范围运行脚本
用vbs 实现从剪贴板中抓取一个 URL 然后在浏览器中打开该 Web 站点
使用vbscript脚本在表单中进行选择的代码
一个把任何文件转成批处理的vbs脚本Any2Bat.vbs
windows脚本调试howto的方法
注册表的禁用与解锁方法集合

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 58 ::
收藏到网摘: n/a

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