Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 日志备份的批处理文件&;清楚的_Batch File_Logging_Event Log - Fatal编程技术网

Batch file 日志备份的批处理文件&;清楚的

Batch file 日志备份的批处理文件&;清楚的,batch-file,logging,event-log,Batch File,Logging,Event Log,小结:我正在处理一个批处理脚本文件,以便将Windows事件日志备份到映射的网络驱动器。每次脚本运行时,我都使用netlogon建立到网络驱动器的通道。我想专门备份“应用程序、安全性和系统”日志。我希望每隔60天将日志备份到同一目录,但不希望用相同的名称覆盖现有日志文件。因此,我发现我可以将日期附加到单个日志文件名中。备份所需的日志后,我希望清除当前计算机上的日志 以下是我到目前为止的情况: 我只需要一个命令就可以每60天备份一次事件日志,因为它们不会在目标目录中相互覆盖。我想我最终会使用顶级脚

小结:我正在处理一个批处理脚本文件,以便将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


也许每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
@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