惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Martin Fowler
Martin Fowler
雷峰网
雷峰网
IT之家
IT之家
小众软件
小众软件
M
MIT News - Artificial intelligence
博客园 - 聂微东
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
C
Check Point Blog
云风的 BLOG
云风的 BLOG
腾讯CDC
H
Help Net Security
Y
Y Combinator Blog
I
InfoQ

博客园 - Johnny shen

XP 32-bit Upgrade to Win7 32-bit Review 文章: 扩展 Reporting Services 2008 与 Reporting Services 2005:所获得的经验 Microsoft SQL Server 2008故障转移群集在Hyper-V虚拟机上的多种组建方式 Hyper-v与CPU 虚拟化典型故障一例 MS Dynamics CRM 4.0 Installation on SQL2008 error 多个微软Windows版本在未来一年内将渐渐退出并不再提供技术支持 微软拼音输入法2010 Beta2简评 - Johnny shen SQL Server 2005 OLAP技术研究与实现 Storing Hierarchical Data in Oracle & MS SQL Database TCP/IP Troubleshooting Undo Windows Update Restriction - Johnny shen 苏州主讲[常见加密算法和身份验证协议探究] 上海主讲RMS信息保护 无锡主讲微软企业信息系统远程客户端安全技术和应用 AD Bulk import or export Enabling IP Routing for Windows XP On-site training for Roche Shanghai in Aug. 3 ASIA MVP Summit in Singapore ISA2004 EE Global Readness Training Camp
自动备份多台服务器System Event Log解决方案
Johnny shen · 2008-02-28 · via 博客园 - Johnny shen

审计需要备份公司多台Windows2000/2003成员服务器(DC在总部),并将其并入公司的数据自动备份方案中。
1. 考虑先用脚本实现备份过程,文件名eventlogsbackup.vbs.(脚本如下,其中需维护一服务器清单)
2. 建立一批文件Eventlogsbackup.bat, 包含语句cscript eventlogsbackup.vbs
3. Schedule a task 来用你的域帐户RunAs运行此批文件,当然之前你必须将此域帐号加入到能读写系统Event的用户组中.(用这种方法,你的域帐户的密码不用担心是明文而被看到)
4. 运行此任务,所有的服务器的Event logs数据将被集中备份到一点。

On Error Resume Next
Dim strDate
centralDumpPath = "\\Dserver\Eventlogs\"
RemoteDumpPath = "C:\EventLogs\"
arrLogs=Array("Application","System","Security")
Set oFS = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("wscript.shell")
Set oTS = oFS.OpenTextFile("C:\EventLogs\serverlist.txt")
arrComputers=Split(Trim(oTS.ReadAll),VbCrLf)
oTS.Close
For Each sComputer In arrComputers
  if Len(sComputer)>0 Then 'skip any blank lines
      For Each strLog In arrLogs
          strDate = CStr(Date())
          strDate = Replace(strDate, "/", "-")
          remoteDumpFile =  UCase(sComputer) &_
           "-" & strLog & "-" & strDate & ".evt"  
          rc=BackupLog(strLog,remoteDumpPath & remoteDumpFile,sComputer)
              If rc(0)=0 Then
               strSource="\\" & sComputer & "\" & Replace(remoteDumpPath &_
                remoteDumpFile, "C:", "C$")
               strDestination=centralDumpPath & sComputer &_
                "\" & remoteDumpFile
               MoveFile strSource,strDestination
              Else
               Wscript.Echo "Couldn't get log " & strLog & " from " & sComputer &_
                ".  Error code: " & rc(0) & " " & rc(1)
              End If
      Next
    End If
Next
WScript.Quit

Function BackupLog(sLog,sFile,sComputer)
On Error Resume Next
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFile) Then oFS.DeleteFile sFile,True
 Set oWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate,(Security,Backup)}!\\" & _
 sComputer & "\root\cimv2")
Set cLogFiles = oWMIService.ExecQuery _
 ("Select * from Win32_NTEventLogFile where " & _
 "LogFileName='" & sLog & "'")
If cLogFiles.Count =0 Then
    BackupLog=Array("-1","Nothing to backup for event log " & sLog)
    Exit Function
End If
 For Each oLogfile in cLogFiles
   WScript.Echo "Creating " & sFile
    oLogFile.BackupEventLog(sFile)
  If Err.number=0 Then
    BackupLog=Array(0,"Successfully backed up " & sLog & " to " & sFile)
    wshshell.LogEvent 0, "Successfully backed up " & sLog & " log to " & sFile
   'no error - safe to clear the Log
   'WScript.Echo "Clearing event log " & strLog & " on " & sComputer
   'wshshell.LogEvent 0, "Clearing event log of " & strLog & " on " & sComputer
    'Uncomment the next line to actually clear the log. I have it
    'commented out for test purposes
   'oLogFile.ClearEventLog()
  Else
    BackupLog=Array(Err.Number,Err.Description)
    wshshell.LogEvent 0, "Failure on backed up " & sLog & " log to " & sFile
  End If
Next
End Function

Function MoveFile(strSource,strDestination)
On Error Resume Next
Set oFS = CreateObject("Scripting.FileSystemObject")
strParentFolder = oFS.GetParentFolderName(strDestination)
   If oFS.FolderExists(strParentFolder)=False Then
    WScript.Echo "Creating " & strParentFolder
    oFS.CreateFolder strParentFolder
        If Err.Number<>0 Then
            WScript.Echo "Failed to create " & strParentFolder
            Exit Function
        End If
   End If
    WScript.Echo "Copying " & strSource & " to " & strDestination
    oFS.CopyFile strSource,strDestination,True
    If Err.Number=0 Then oFS.DeleteFile strSource
End Function