<

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

18 Points
18 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
Comment
Author:Amit
0 Comments

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Join & Write a Comment

Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month