Windows Batch Script to Take Backup of Server Event Log
By Anuket Jain On 18 May 2016 In Scripting
One of the most common, and well suited, applications for a command line script is to take backup of event log. Event log is necessary for troubleshooting systems. Command line scripts can be automated to run at any time without any human interaction.
See Also:
This tutorial will help you to take a backup of event log.
Simple Batch Script:
Create Backup Directory:
First we need to create backup directory. In which we contain event log backups and log files.
C:\> MKDIR c:\Backup C:\> MKDIR c:\BackupLogs
Backup Location: c:\Backup LogFile: c:\BackupLogs
Create Backup Script:
Copy and paste below script in file:
rem Script start here rem Timestamp Generator set BACKUP_PATH=c:\Backup\ rem Parse the date (e.g., Tus 17/05/2016) set cur_yyyy=%date:~10,4% set cur_mm=%date:~4,2% set cur_dd=%date:~7,2% rem Parse the time (e.g., 11:20:56.39) set cur_hh=%time:~0,2% if %cur_hh% lss 10 (set cur_hh=0%time:~1,1%) set cur_nn=%time:~3,2% set cur_ss=%time:~6,2% set cur_ms=%time:~9,2% rem Set the timestamp format set timestamp=%cur_yyyy%%cur_mm%%cur_dd%-%cur_hh%%cur_nn%%cur_ss%%cur_ms% wevtutil epl System %BACKUP_PATH%\system_%timestamp%.evtx wevtutil epl Application %BACKUP_PATH%\application_%timestamp%.evtx wevtutil epl Security %BACKUP_PATH%\security_%timestamp%.evtx rem End of Script
Execute Batch Script:
To run the batch file, double-click on it. Once the batch file has completed running it closes automatically.
Enjoy it!
No Responses