<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

How to Zip, Archive, move and delete logs from Windows Server using Winrar tool on Windows Server

0 Points
28 Views
Last Modified:
Amit
If you need my quick help, raise the ticket with highest priority.
How to Zip, Archive, move and delete logs from Windows Server using Winrar tool.

If you are a windows admin, you might face disk space issue, due to log files. Few Microsoft products are designed to take care logs by its own. Like Exchange, where you can backup the database and logs will be purged automatically or using circular logging. However, there are products, we don't have option to purge, archive the logs.


Recently, one my client faced similar issue related to logs. They wanted to zip, archive and delete the logs. I reviewed the requirement, searched lot of scripts, tools etc. Finally, i was able to achieve the goal using Winrar tool. I am outlining the steps below.


Below are the steps:


Step 1 Download/Buy Winrar 32 or64bit

Path: https://www.win-rar.com/predownload.html?&f=winrar-x64-550.exe&spV=true&subD=true&L=0


Step 2 Setting up Windows Environmental variable.
How to set Windows Environmental variable to point to installed Winrar tool (Optional, as you can set the path in .bat also)

1) Open Control Panel>System>Advance system settings>Advance tab>Environmental variables

2) Select “Path” variable>Edit

3) Add below path in the text box:
    ;C:\Program Files\WinRAR
4) Click OK and save it.


Step 3 Zipping the log files.
Goto Start>Run>Notepad. Add below command:

WinRAR a -r TargetPath SourcePath


Below is the command to save logs with date appended in the zip file.

WinRAR a -agYYYY-MM-DD -cfg- -ep1 -inul -m5 -r -y "C:\arch\data_.rar" "C:\test\"

or without setting Environment Variable, use below command

"%ProgramFiles%\WinRAR\rar.exe"  a -agYYYY-MM-DD -cfg- -ep1 -inul -m5 -r -y "C:\arch\data_.rar" "C:\test\"


Step 4 Changing path to source.
cd sourcefolderpath (directory from where you will delete log files)

Example:
cd c:\test


Step 5 Deleting logs from source.
Deleting the logs
del /Q /F /S SourceFolderPath (This command delete logs from source in silent mode, including read only)


Step 6 All above command in one file.
Combining all commands into one text file and save it as Logremoval.bat. Below are all commands you need in batch file:

"%ProgramFiles%\WinRAR\rar.exe" a -agYYYY-MM-DD -cfg- -ep1 -inul -m5 -r -y "C:\arch\data_.rar" "C:\test\"
cd "c:\test"
del /Q /F /S *.log


Step 7 Configure .bat using task scheduler.

You can configure this batch file using task manager and run it at specific date and time.


Please note, test this, before you can roll out into production.

0
Author:Amit
0 Comments

Featured Post

OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month