7zip Batch File and Rotate File Names

Here’s the scenario:
Customer has a syslog server (Kiwi’s free syslog server) running on Windows2003 Server on a crappy 100GB server. They wanted a way to rotate the logs (free version does not allow for automatic rotation) and compress the logs. Every hour the syslog file grows by 7MB. That might not seem like a lot, but each month that’s 5.2GB and every year it’s 61GB. OK, maybe that’s not a lot to you, but on a 100GB server it adds up quickly.

I compressed a test log of 46MB. It compressed to 8KB. Wow, eh? 7Zip is free, you can download it using sourceforge so it’ll run on Windows or linux.

I wrote up a batch file to auto grab, compress, and name the file after the date. You’ll need to add the 7z variable to the system path to make things easier (system variables, under path add C:\program files\7-zip)

@echo off
7z a c:/%date:~4,2%-%date:~7,2%-%date:~10,4%-syslog.7z c:/test/
pause

As a breakdown, the first line turns off writing the commands on the executed script window.
7z is the executable, a is add files, the date spits out month-day-year followed by -syslog.7z, c:/test/ is the path you want compressed
Pause just makes it so you have to hit enter to close the command window

Obviously change the c:/test/ to something you want to backup. You can also use c:/test/test.jpg as a specific file name.

One thought on “7zip Batch File and Rotate File Names”

  1. “Krojamsoft BatchRename” Tool is a powerful tool, that allows you to quickly rename all the files in a specified directory. You can remove spaces, replace spaces with underscore, uppercase/lowercase filename, add a prefix/suffix, remove/replace strings and also catalog files by adding an incremental number to the file name.

Leave a Reply

Your email address will not be published. Required fields are marked *