脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - VBS - 定时自动备份IIS的WWW日志的vbs脚本

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

2020-07-15 11:03VBS脚本之家 VBS

本文主要分享定时自动备份IIS的WWW日志的vbs脚本,极具参考价值,有需要的朋友可以了解下

  1. dim IISCount,IISObject,logfiledir,fso,LogFilePeriods,inputtime,site,sites,i,j,sitename(999),WshShell  
  2. 'on error resume next  
  3. set WshShell = WScript.CreateObject("WScript.Shell")  
  4. Set fso = CreateObject("scripting.FileSystemObject")  
  5. set IISCount=GetObject("IIS://localhost/w3svc")  
  6. sites=0  
  7. for each site in IISCount  
  8. if (site.class="IIsWebServer") then   
  9. sitename(sites)=site.name  
  10. sites=sites+1  
  11. end if  
  12. next  
  13.  
  14. MsgBox "IIS中一共" & sites & "个站点,ID分别为:"  
  15. for j=1 to sites-1  
  16. MsgBox sitename(j)  
  17. next  
  18.  
  19. inputtime=inputbox("您要备份哪天的日志?如备份2004-01-01,则输入040101")  
  20. MsgBox "备份" &inputtime& "天的日志"  
  21.  
  22. MsgBox "开始备份.............."  
  23. for i=0 to sites-1  
  24. Set IISOBJect = GetObject("IIS://localhost/w3svc/" & sitename(i))   
  25. MsgBox "备份ID=" & sitename(i) &" Sitename=" & IISObject.servercomment &"的站点"  
  26. logfiledir = IISObject.LogFileDirectory & "w3svc" & sitename(i)'设置第一个站点的日志路径  
  27. if (Err.Number<>0) then logfiledir=IISCount.LogFileDirectory  
  28. Err.clear  
  29. 'if IISObject.LogFilePeriod=1 then LogFilePeriods="days"  
  30. 'if IISObject.LogFilePeriod=2 then LogFilePeriods="weeks"  
  31. 'if IISObject.LogFilePeriod=3 then LogFilePeriods="months"  
  32. 'if IISObject.LogFilePeriod=4 then LogFilePeriods="hours"  
  33. 'if IISObject.LogFilePeriod=0 AND IISObject.LogFileTruncateSize=-1 then LogFilePerirods="onefile"  
  34. 'if IISObject.LogFilePeriod=0 AND IISObject.LogFileTruncateSize>0 then LogFilePerirods="size"&IISObject.LogFileTruncateSize  
  35. LogFilePeriods=IISObject.LogFilePeriod  
  36. if (Err.Number<>0) then LogFilePeriods=IISCount.LogFilePeriod  
  37. Err.clear  
  38. if (NOT LogFilePeriods=1 AND NOT LogFilePeriods=4) then   
  39. MsgBox "对不起,您的日志偶就不给备份,咋地吧"  
  40. WScript.quit  
  41. end if  
  42. if (NOT fso.folderexists("d:backup")) then   
  43. MsgBox "the folder d:backup is not exist,now create it"  
  44. fso.CreateFolder("d:backup")  
  45. Msgbox "created d:backup succuful"  
  46. end if  
  47. if (NOT fso.FolderExists("d:backup"&IISObject.servercomment)) then  
  48. MsgBox "the folder d:backup" & IISObject.servercomment & " is not exist,now create it"  
  49. fso.CreateFolder("d:backup" & IISObject.servercomment)  
  50. MsgBox "created d:backup" & IISObject.servercomment &" succuful"  
  51. end if  
  52.  
  53. MsgBox "now backup the logfiles"  
  54. logfiledir = WshShell.ExpandEnvironmentStrings(logfiledir) '将环境变量转换成字符串  
  55. MsgBox logfiledir  
  56. fso.Copyfile logfiledir &"ex"&inputtime&"*","d:backup"& IISObject.servercomment  
  57. if Err.number<>0 then   
  58. MsgBox "this site no files"  
  59. else  
  60. MsgBox "backup logfiles succuful"  
  61. end if  
  62.  
  63. inputifdel=inputbox("是否删除已备份文件?输入“YES”进行删除")  
  64. if inputifdel="YES" then  
  65. fso.DeleteFile (logfiledir&"ex"&inputtime&"*")  
  66. MsgBox "删除文件成功"  
  67. else  
  68. MsgBox "文件已保留"  
  69. end if  
  70. next  
  71. MsgBox "备份所有的日志文件成功,嘿嘿"  

延伸 · 阅读

精彩推荐
  • VBS雷客图ASP站长安全助手vbs测试版代码

    雷客图ASP站长安全助手vbs测试版代码

    雷客图ASP站长安全助手是一个基于ASP的帮助站长维护网站安全的程序。这个版本(vbs测试版)主要用于服务器本地运行以查找ASP木马。此版本为测试版,希...

    脚本之家2312020-07-03
  • VBSAdsutil.vbs 在脚本攻击中的妙用[我非我原创]

    Adsutil.vbs 在脚本攻击中的妙用[我非我原创]

    adsutil.vbs是什么?相信用过IIS的网管员不会不知道。这是IIS自带的提供于命令行下管理IIS的一个脚本。位于%SystemDrive%\Inetpub\AdminScripts目录下。...

    VBS教程网2312020-07-07
  • VBSWINDOWS脚本实践:为SAP补丁制作的VBS脚本代码

    WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码

    本文主要分享WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码,有需要的童鞋可以参考下...

    脚本之家3232020-07-06
  • VBSVBS数组深入浅出

    VBS数组深入浅出

    VBS数组在应用中没有像其他语句那么广泛,VBS数组存在不少功能上的局限性(如二维数组的定义、赋值),在使用上也没有java等语言那么便捷...

    VBS教程网2962020-08-18
  • VBSVBS编程教程 (第1篇)

    VBS编程教程 (第1篇)

    VBScript的全称是:Microsoft Visual Basic Script Editon.(微软公司可视化BASIC脚本版). 正如其字面所透露的信息, VBS(VBScript的进一步简写)是基于Visual Basic的脚本语言....

    VBS教程网4812020-07-15
  • VBSVBS文本文件操作实现代码

    VBS文本文件操作实现代码

    这篇文章主要介绍了VBS文本文件操作实现代码,需要的朋友可以参考下...

    VBS代码网8912020-08-12
  • VBSVBS教程:正则表达式简介 -正则表达式语法

    VBS教程:正则表达式简介 -正则表达式语法

    正则表达式语法 一个正则表达式就是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式。该模式描述在查找文字主体时待匹配的...

    VBS教程网3302019-11-25
  • VBS灵活实用VBS入门教程应用篇

    灵活实用VBS入门教程应用篇

    上一篇文章我们了解了VBS编程的一些基础知识,要更深入地学习还要学习选择结构和循环结构。 ...

    VBS教程网5742020-07-01