我该如何定期备份 Windows 应用程序日志?

发布于 2024-07-11 05:55:51 字数 291 浏览 11 评论 0原文

我正在使用一个定期记录到 Windows 应用程序日志(可通过事件查看器管理工具查看)的应用程序,并且我正在寻找一种每天备份它的方法。 这很重要,因为我们有时会发现应用程序存在问题 - 为了进一步调查,我们需要一周前记录的信息。 我们正在寻找的事件不一定仍然存在......我已经尝试过增加大小等等,但我认为自动备份将有助于该过程。 我们最终不会得到巨大的原木,而是多个中等大小的原木。

更喜欢一个简单的解决方案,例如批处理文件+ Windows Scheduler,但也对其他方法感兴趣。

谢谢

I'm working with an application that logs to Windows Application Log regularly (viewable through the Event Viewer administrative tool), and I'm looking for a way to back it up on a daily basis. This is important because we sometimes discover a problem with the application - and to investigate further we need information that was logged a week ago. The events we are looking for aren't necessarily still around ... I've tried increasing the size and all that, but I think an automated backup would facilitate the process. We wouldn't end up with huge logs, but rather, multiple moderately-sized logs.

I would prefer a simple solution like batch file + Windows Scheduler, but would also be interested in other approaches.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彩虹直至黑白 2024-07-18 05:55:51

这是我不久前找到的一个WMI脚本。 这可能就是您正在寻找的!

dim strComputer = "." 'Define here the Remote IP Address or Computername
dim objWMIService
dim colLogFiles
dim objLogfile
dim errBackupLog

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" &  strComputer & "\root\cimv2")

Call eventlogbackup("Application")
Call eventlogbackup("System")
Call eventlogbackup("Security")

Function eventlogbackup(logtype)

Set colLogFiles = objWMIService.ExecQuery ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='" & logtype & "'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog("\\server\eventlogs\" & strComputer & "\" &logtype & ".evt")
 If errBackupLog <> 0 Then
    Wscript.Echo "The " & logtype &" event log could not be backed up."
 Else
    objLogFile.ClearEventLog()
    Wscript.Echo "The " & logtype &" event log is backed up."
 End If
Next

End Function

只需在计划任务中设置此脚本即可开始!

Here is a WMI script that I found a while ago. This could be what you're searching!

dim strComputer = "." 'Define here the Remote IP Address or Computername
dim objWMIService
dim colLogFiles
dim objLogfile
dim errBackupLog

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" &  strComputer & "\root\cimv2")

Call eventlogbackup("Application")
Call eventlogbackup("System")
Call eventlogbackup("Security")

Function eventlogbackup(logtype)

Set colLogFiles = objWMIService.ExecQuery ("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='" & logtype & "'")

For Each objLogfile in colLogFiles
 errBackupLog = objLogFile.BackupEventLog("\\server\eventlogs\" & strComputer & "\" &logtype & ".evt")
 If errBackupLog <> 0 Then
    Wscript.Echo "The " & logtype &" event log could not be backed up."
 Else
    objLogFile.ClearEventLog()
    Wscript.Echo "The " & logtype &" event log is backed up."
 End If
Next

End Function

Just set-up this script in a scheduled task and you're good to go!

小姐丶请自重 2024-07-18 05:55:51

您可以使用 Windows Management Instrumentation (WMI) 读取事件日志并对结果执行任何您喜欢的操作。 这是一篇文章,您可以根据自己的目的进行调整。

You can use Windows Management Instrumentation (WMI) to read the event log and do whatever you like with the result. Here's an article that you may be able to tweak to your purposes.

贩梦商人 2024-07-18 05:55:51

将应用程序通道中的所有事件输出到 XML:

wevtutil.exe qe application

对于可读的文本输出,请使用:

wevtutil.exe qe application /f:text

您可以轻松地将这些输出中的任何一个定期通过管道传输到文件以进行备份。

Output all events in the Application channel, to XML:

wevtutil.exe qe application

For readable text output, use:

wevtutil.exe qe application /f:text

You could easily pipe either of these outputs to a file periodically for backup.

热鲨 2024-07-18 05:55:51

您可能需要考虑设置其中一种工具来将 Windows 事件转发到系统日志服务器。 然后,您不必运行执行备份的进程,您将几乎在将所有日志条目添加到 Windows 事件日志的同时将其转发到第二个位置。

http://ntsyslog.sourceforge.net/
http://edoceo.com/creo/winlogd
http://www.softpanorama.org/Logs/Syslog/syslog_for_windows.shtml

根据您使用的系统日志服务器,您可以设置过滤器来忽略某些事件或将它们发送到不同的文件。 您可以根据需要设置日志滚动。

You might want to consider setting up one of the tools to forward windows events to a syslog server. Then instead of having to run a process that does the backup you will get all the log entries forwarded to a second location nearly at the same time they are added to the windows event log.

http://ntsyslog.sourceforge.net/
http://edoceo.com/creo/winlogd
http://www.softpanorama.org/Logs/Syslog/syslog_for_windows.shtml

Depending on what syslog server you use you can setup filters to ignore some events or send them to different files. You can setup log rolling however you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文