Timed automatic backup of the Web log's VBS script for IIS _vbs

Source: Internet
Author: User
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 "& Sites &" Sites in IIS, IDs are: "
For J=1 to Sites-1
MsgBox SiteName (j)
Next

Inputtime=inputbox ("Which day do you want to back up the log?") If Backup 2004-01-01, then enter 040101 ")
MsgBox "Backup" &inputtime& "Day Log"

MsgBox "Start Backup ....... ..."
For I=0 to Sites-1
Set IIsObject = GetObject ("iis://localhost/w3svc/" & SiteName (i))
MsgBox "Backup Id=" & SiteName (i) & "Sitename=" & iisobject.servercomment & "Site"
Logfiledir = iisobject.logfiledirectory & "w3svc" & SiteName (i) ' Set the log path for the first site
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 "I'm sorry, your log is not back to me, I do."
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) ' converts environment variables to strings
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 ("Do you want to delete the backed-up files?") Enter "yes" for deletion)
If inputifdel= "YES" Then
Fso. DeleteFile (logfiledir& "ex" &inputtime& "*")
MsgBox "Delete file succeeded"
Else
MsgBox "file reserved"
End If
Next
MsgBox "Back up all log files successfully, Hey Hei"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.