Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch file, script, file rotate on size

Posted on 2014-03-03
18
Medium Priority
?
2,496 Views
Last Modified: 2014-03-05
Hi experts,

Looking for your kind assistance and help.

I have server application it generate continues log always.
I have schedule running everyday the file will be moved to the new location.
But the file size is around 200mb in day...it is very difficult to manage the storage.
I am looking for help..how to zip compress the file in same name by batch file so that it  will do automatically.


@echo off
set datetime=%date:~-4%_%date:~-7,2%_%date:~-10,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %datetime%
move "D:\Program\rsa\key\log\*.audit" "D:\Program\Backup\to HP\AUDIT_TEXT_Files\PRI_RSA_Audit_Text_File_%datetime%.audit
0
Comment
Question by:Skumar_CCSA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 3
18 Comments
 
LVL 57

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 39901190
Here is a script that does what you describe.  It requires 7-ZIP which can be downloaded from:

http://www.7-zip.org/

@echo off

REM Specify folders and files to operate on
set BaseDir=D:\Program\rsa\key\log
set DestDir=D:\Program\Backup\to HP\AUDIT_TEXT_Files
set ExtFilter=audit
set ZipFilter=gz
set Zip=c:\program files\7-zip\7za.exe

REM Current date time in YYYY_MM_DD_hh_mm_ss format for timestamp on moved files
set datetime=%date:~-4%_%date:~-7,2%_%date:~-10,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %datetime%

REM Move all matching files to destination folder renaming with date/time stamp
"%Zip%" a -tgzip "%DestDir%\PRI_RSA_Audit_Text_File_%datetime%.%ZipFilter%" "%BaseDir%\*.%ExtFilter%"
del "%BaseDir%\*.%ExtFilter%" /y

REM Only keep 30 newest files in destination folder
for /F "tokens=* skip=30" %%A in ('dir /b /a-d /tc /o-d "%DestDir%\*.%ZipFilter%"') do del "%DestDir%\%%~A"

Open in new window

~bp
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39901770
you may want to look into logrotate equivalents for windows

logrotate native reimplementation
http://sourceforge.net/projects/logrotatewin/

python implementation
http://sourceforge.net/directory/security-utilities/logging/log-rotation/os:linux/freshness:recently-updated/

bundled cygwiin ddls and original logrotate program
https://www.itefix.no/i2/logwot8
0
 

Author Comment

by:Skumar_CCSA
ID: 39902524
i have checked in another server, it automatically compressed..
the format is .gz
i think it happens without instaling any zip software.
can you please help.
0
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 
LVL 27

Expert Comment

by:skullnobrains
ID: 39902583
beginnig with XP, window comes bundled with the possibility to read and write zip files trough the explorer, so the zip dll has to be available to programs wether a zip soft is installed or not

it is fairly possible that your server directly writes compressed logs. if you have no uncompressed logs at all, it is sure to be the case

in your case, since the extension is gzip, it is more likely that your server comes bundled with gzip and is able to take care of compression itself. wether it writes compressed logs or takes care of compression + rotation from time to time is a matter of what software that is and how it is configured

the feature is very common in servers targetted for the window platform (and that do not use the event log) precisely because windows does not have a logrotate program.
0
 

Author Comment

by:Skumar_CCSA
ID: 39902587
my server is win 2008 r2
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39903056
What software is generating those compressed log files, my guess would be that it incorporates the capability within it.  I don't believe there is any native Windows capability to generate gzip files.

~bp
0
 

Author Comment

by:Skumar_CCSA
ID: 39903064
Software : VASCO , Identikey Authentication Server....runs with PostgreSQL
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39903074
Okay, not familiar with that, and could find anything quickly on their website about compressing log files, so not sure if it produces the gzip files you are seeing on another server, or if a utility is being used there.

~bp
0
 

Author Comment

by:Skumar_CCSA
ID: 39903082
Yes actually i have the option for those log file to archive and compress.
But for audit file ..I did not have that option in the software.
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39903090
Ah, okay, so in that case the software has built in support for generating some files in gzip format, but you will have to do the audit file yourself, using something like 7ZIP.

~bp
0
 

Author Comment

by:Skumar_CCSA
ID: 39903101
Yes...correct.
I am able to unzip those file using 7zip...
Also like to check with you....is it possible to do zip in regular way as we have in built compress function in windows OS...I seen when I compress the file..the size become 20mb from 200mb.
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39903624
What are you referring to by "in built compress function in windows"?

~bp
0
 

Author Comment

by:Skumar_CCSA
ID: 39903719
compressed ("zipped") folder feature in widows
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 39903733
What is the command you use at a windows command line for that?

~bp
0
 

Author Comment

by:Skumar_CCSA
ID: 39903778
I see the command in this link...
I already tried to do...but did not help...
thought of posting for experts help...
thanks to help..
http://technet.microsoft.com/en-us/library/bb490884.aspx
0
 

Author Comment

by:Skumar_CCSA
ID: 39903869
Like to check is it possible ?
Batch file will run everyday or one in 4 hours. ( batch/ script file though task scheduler)
When the log.audit file exceeds more then 500MB, it should start renaming the file and zip the file.
keep latest 30 files.

Source  - D:\abc\log.audit
Destination File : D:\Auth_Audit_currentdateandtime.zip

Zip to be used windows feature....as I have restriction that no software's installed.

thanks to help...
0
 

Author Closing Comment

by:Skumar_CCSA
ID: 39905336
It worked greatly in my testing server having the software installed.
but i dont have permissions to install the software.
however the solution given...it helped me.
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39906193
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question