0

摘要:我正在处理一个批处理脚本文件,以将 Windows 事件日志备份到映射的网络驱动器。每次脚本运行时,我都使用 netlogon 建立到网络驱动器的通道。我想专门备份“应用程序、安全性和系统”日志。我想每 60 天将日志备份到同一个目录,但我不想覆盖现有的同名日志文件。所以我发现我可以将日期附加到单个日志文件名。备份所需的日志后,我想清除当前计算机上的日志。

这是我到目前为止所拥有的:

我只需要一个命令来每 60 天备份一次事件日志,它们不会在目标目录中相互覆盖。我想我最终会使用顶级脚本。

@echo off
net use y: \\server_name\shared_folder_name /USER:admin password /persistent:yes
wmic nteventlog where filename='application' backupeventlog C:\Users\Public\Desktop\Application.evt
wmic nteventlog where filename='security' backupeventlog C:\Users\Public\Desktop\Security.evt
wmic nteventlog where filename='system' backupeventlog C:\Users\Public\Desktop\System.evt
wmic nteventlog where filename='application' cleareventlog
wmic nteventlog where filename='system' cleareventlog
wmic nteventlog where filename='security' cleareventlog
exit

@echo off
XCOPY C:\Windows\System32\winevt\Logs\Application.evtx Y:\Analysis\Logs\ /T /E /Y /C
XCOPY C:\Windows\System32\winevt\Logs\Security.evtx Y:\Analysis\Logs\ /T /E /Y /C
XCOPY C:\Windows\System32\winevt\Logs\System.evtx Y:\Analysis\Logs\ /T /E /Y /C
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
exit
4

1 回答 1

0

也许每 60 天安排一次 - 它已经用日期戳写入文件。

@echo off
net use y: \\server_name\shared_folder_name /USER:admin password /persistent:yes

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%"
set "target=C:\Users\Public\Desktop"

wmic nteventlog where filename='application' backupeventlog  "%target%\Application-%datestamp%.evt"
wmic nteventlog where filename='security' backupeventlog "%target%\Security-%datestamp%.evt"
wmic nteventlog where filename='system' backupeventlog "%target%\System-%datestamp%.evt"
wmic nteventlog where filename='application' cleareventlog
wmic nteventlog where filename='system' cleareventlog
wmic nteventlog where filename='security' cleareventlog
exit
于 2013-10-18T02:39:14.537 回答