Implementation of IIS server backup Transfer

Source: Internet
Author: User
Tags microsoft website

Original Article : You are welcome to repost it. Please retain the author's name and source when reprinting.
By jacksonluo
I. Pre-configuration of IIS server (other security aspects will not be mentioned) (taking freeshare.com.cn as an example)
1. Create the (freeshare.com.cn) computer user name for this domain and set a Security Password
2. Create a directory folder for this domain, such as (D: \ Inetpub \ freeshare.com.cn)
3. Set Directory Access Permissions. freeshare.com.cn has full control over this directory (providing anonymous users to access this website)
4. Create a separate application process pool that describes the domain name (company name) and create independent applications for each VM. Program The process pool does not affect the operation of the entire server. When creating a process pool, you can set the user name and password separately and set the CPU and number of connections. The default value is used here.
5. create a VM, select the application process pool created above, select the anonymous user freeshare.com.cn in Directory Security, and set the password to be consistent with the user name of freeshare.com.cn created on the computer, otherwise, the website cannot be accessed.
Okay, this is what we need to do for every virtual host. Do we need to do this manually? The answer is no. In Windows, you can also implement Script Programming. (I didn't know it)
So what can I do without manual work? Use Vbscript.
Ii. Use a script to create a VM
Save as createsiglewebsite. vbs CopyCode The Code is as follows: dim sitenum, ipaddr, portnum, lencomputer, webservercomment, and logdirectory
Dim user_password, groupname, tmpfolder, usernamecomp, webserverautostart
Dim webanonymoususername
Webservercomment = "company name" 'this variable is used for website description, computer user description, and full name
Usernamecomp = "freeshare.com.cn" 'this variable is used for the computer user name and user directory
Hostname = ": 80: www.freeshare.com.cn" 'vm site Host Name
Webanonymoususername = getcomputer () & "\" & usernamecomp 'Anonymous user of the VM (the local computer name is added before)
User_password = "***********" 'password of a computer user and an anonymous user.
Groupname = "guests" 'Group of computer users
Ipaddr = "" 'computer ip address, which can be blank
Tmpfolder = "D: \ Inetpub \" & usernamecomp 'target directory
Lencomputer = Len (getcomputer () + 1 'computer name + '\' Length
Portnum = "80" 'vm Port
Webserverautostart = "true" 'whether to run true and false after creating a VM
Logdirectory = "" 'log directory
'Check whether the user's computer account exists
If not checkuser (usernamecomp) then
'Add this computer user account
Adduser getcomputer (), usernamecomp, user_password, webservercomment, webservercomment, groupname
Else
Wscript. Echo "the user name of this computer also exists .............."
End if
'Create a user's home directory
Createfiledirectory (tmpfolder)
'Modify the access permission of the user's home directory
Setntfsdirectoryperssion (usernamecomp)
'Create an application process pool
Createapppool webservercomment
'Create a VM site
Createwebsite getcomputer (), ipaddr, hostname, tmpfolder, logdirectory, webservercomment, usernamecomp, user_password, webserverautostart
'Buildnum = buildnum + 1
'Wscript. echo "============================================== ======== "& buildnum &" ============================== =========================="
'Create a site application pool for each IIS Virtual Host application site
Function createapppool (strname)
On Error resume next
Err. Clear
Set objapppoolsexist = GetObject ("IIS: //" & getcomputer () & "/w3svc/apppools" & strname)
If err. Number = 0 then
Wscript. Echo "the application process pool has been created ............."
Set objapppoolsexist = nothing
Exit Function
Else
Set objapppools = GetObject ("IIS: //" & getcomputer () & "/w3svc/apppools ")
Err. Clear
Set objapppool = objapppools. Create ("iisapplicationpool", strname)
If err. Number = 0 then
Objapppool. apppoolidentitytype = 2 'RUNS as nt authority \ Network 3 run as specific user account 1 runs as nt authority \ Local Service 0 runs as nt authority \ System
Objapppool. setinfo
If err. Number = 0 then
Createapppool = true
Wscript. Echo "application" & strname & "created successfully! "
Else
Createapppool = false
Wscript. Echo "application" & strname & "creation failed! "
End if
Else
Createapppool = false
End if
End if
Set objapppool = nothing
Set objapppools = nothing
Set objapppoolsexist = nothing
End Function
Function createwebsite (strcomputer, ipaddr, webserverbingings, websitedirectory, logdirectory, websiteinfo, guestusername, guestuserpass, startorstop)
Dim W3SVC, Webserver, newwebserver, newdir
Dim bindings, bindingstring, newbindings, sitenum, siteobj, bdone
On Error resume next
Err. Clear
'Check whether the w3svc Service (Web Service) can be loaded)
Set w3svc = GetObject ("IIS: //" & getcomputer () & "/W3SVC ")
If err. Number <> 0 then': an error message is displayed.
Wscript. Echo "cannot be enabled:" & "IIS: //" & getcomputer () & "/W3SVC"
Exit Function
End if
'Check whether a site with the same IP address, port, and host name has been set
Bindingstring = ipaddr & webserverbingings
For each webserver in w3svc
If webserver. Class = "iiswebserver" then
Bindings = webserver. serverbindings
If bindingstring = bindings (0) then
Wscript. Echo "VM:" & hostname & ", already exists, cannot be created ......!. "
Exit Function
End if
End if
Next
'Determine a site number that does not exist as the new site number. The default website site number is 1, so it starts from 2.
Sitenum = 2
Bdone = false
While (not bdone)
Err. Clear
Set siteobj = GetObject ("IIS: //" & getcomputer () & "/w3svc/" & sitenum) 'load the specified site
If (ERR. Number = 0) then
'Wscript. Echo "step_1 site" & sitenum & ""
Sitenum = sitenum + 1
Else
'Wscript. Echo "step_1 site" & sitenum & "nonexistent"
Err. Clear
Set newwebserver = W3SVC. Create ("iiswebserver", sitenum) 'create a specified site
If (ERR. Number <> 0) then
Wscript. Echo sitenum & "creation failed"
Sitenum = sitenum + 1
Else
Wscript. Echo sitenum & "created successfully"
Bdone = true
End if
End if
If (sitenum> 1000) then' the maximum number of site creation points on the server
Wscript. Echo "exceeds the maximum number of site creation points on the server. The number of the site being created is:" & sitenum &"."
Exit Function
End if
Wend
'Perform basic site configuration
Newbindings = array (0)
Newbindings (0) = bindingstring
Newwebserver. serverbindings = newbindings
Newwebserver. servercomment = webservercomment
Newwebserver. anonymoususername = guestusername
Newwebserver. anonymoususerpass = guestuserpass
Newwebserver. keytype = "iiswebserver"
Newwebserver. frontpageweb = true
Newwebserver. enabledefadoc Doc = true
Newwebserver. defaultdoc = "default.htm, default. asp, index.htm, index.asp,index.html, default.html"
Newwebserver. logfiledirectory = logdirectory
Newwebserver. setinfo
Set newdir = newwebserver. Create ("iiswebvirtualdir", "root ")
Newdir. Path = websitedirectory
Newdir. accessread = true
Newdir. appfriendlyname = webservercomment
Newdir. appcreate true
Newdir. accessscript = true
Newdir. authntlm = true
Newdir. appisolated = "2"
Newdir. apppoolid = webservercomment
'Newdir. appcreate3 2, websiteinfo, false
Newdir. authflags = "authanonymous | authntlm" 'integrated Windows Authentication
Err. Clear
Newdir. setinfo
If (ERR. Number <> 0) then
Wscript. Echo "An error occurred while creating the main directory ."
Exit Function
End if
If startorstop = true then
Err. Clear
Set newwebserver = GetObject ("IIS: //" & getcomputer () & "/w3svc/" & sitenum)
Newwebserver. Start
If err. Number <> 0 then
Wscript. Echo "An error occurred while starting the site! "
Err. Clear
End if
End if
Wscript. Echo "the site is successfully created. The site number is:" & sitenum & ", and the domain name is:" & webserverbingings
'Setcpulimitvar strcomputer, sitenum, 100' maximum CPU usage
End Function
Function getcomputer ()
Dim objnet
Set objnet = Createobject ("wscript. Network ")
Getcomputer = objnet. computername
Set objnet = nothing
End Function
Function createfiledirectory (username)
Set fsobject = Createobject ("scripting. FileSystemObject ")
On Error resume next
Err. Clear
If not fsobject. folderexists (username) then
Fsobject. createfolder (username)
If err. Number <> 0 then
Wscript. Echo "creating directory" & username & "failed! "
Else
Wscript. Echo "creating directory" & username & "successful! "
End if
Else
Wscript. Echo "directory" & username & "already exists. You cannot create it! "
End if
Set fsobject = nothing
End Function
Function setntfsdirectoryperssion (sourcedirectory)
Dim wshshell, oexec
Dim exedirectory
Exedirectory = "C: \ Program Files \ Resource Kit \ xcacls.exe c: \ Inetpub \"
Orders_exec = exedirectory & sourcedirectory & "/e/T/g" & sourcedirectory & ": F; F"
Set wshshell = Createobject ("wscript. Shell ")
Set oexec = wshshell. Exec (orders_exec)
If oexec. Status = 0 then
Wscript. Echo "Command executed successfully! "
Else
Wscript. Echo "command execution failed! Insufficient permissions or the program cannot run in DOS state"
End if
Set wshshell = nothing
End Function
Function checkuser (struser)
On Error resume next
'Check if domain is already part of username passed to function
If instr (struser, "\") = 0 then
Set objgrp = GetObject ("winnt: //" & getcomputer () & "/" & struser & ", user ")
Else
Set objgrp = GetObject ("winnt: //" & replace (struser, "\", "/") & ", user ")
End if
If err. Number = 0 then
Checkuser = true
Else
Checkuser = false
End if
Set objgrp = nothing
On Error goto 0
End Function
Function adduser (computer, username, password, fullname, info, groupname)
Dim intreturn, fsobject
On Error resume next
'Execute the Account creation command
Set computeraccoutobj = GetObject ("winnt: //" & getcomputer () & "/" & username & ", user ")
If err. Number = 0 then
Wscript. Echo username & "the computer user already exists ...."
Else
Set computerobj = GetObject ("winnt: //" & getcomputer ())
Set newuser = computerobj. Create ("user", username)
Newuser. setinfo
'Set the account
Newuser. setpassword (password) 'account password
Newuser. fullname = fullname 'account full name
Newuser. Description = info' account description
Newuser. userflags = & h10000 XOR & h0040' & h20000 (the user must change the password upon next login) & h0040 (the user cannot change the password) & h10000 (the password is always correct) & h0002 (account temporarily suspended)
Newuser. setinfo
Wscript. Echo "Account" & username & "created successfully! "
Set objselectgroup = GetObject ("winnt: //" & getcomputer () & "/guests, group ")
Set objadduser = GetObject ("winnt: //" & getcomputer () & "/" & username & ", user ")
Objselectgroup. Add (objadduser. adspath)
End if
Set computerobj = nothing
Set computeraccoutobj = nothing
Set computeraccoutgroupobj = nothing
End Function

after the program is completed, you only need to save the above program *. in the vbs Windows Directory, you can directly execute it. The above uses an xcacls applet to modify the NTFS permission. You can download it from the official Microsoft website, you can also access http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/xcacls-o.asp to download and install the tool.
For more information, see IIS server backup transfer solution (2)

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.