Welcome to Port3101.org : Your BES Connection Mark forums read | View Forum Leaders
Port3101.org : Your BES Connection



Reply
LinkBack (2) Thread Tools Display Modes
Script to Zip Log Files
 
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-16-2009, 10:16 AM
Sith_Apprentice's Avatar
Super Moderator
 
Join Date: Dec 2008
Posts: 1,056
Default Script to Zip Log Files

Originally Posted by hdawg on BBF.

RIM has the ability to automatically purge old log files as a part of BES. You can go to BlackBerry Server Configuration and change how long the server will keep the logs before purging them (as seen in the picture attached), but you can't do the same for SMS/PIN/Phone logs.

Regardless, if there's one thing you probably know about me, it's that I'm a log junkie. Much like a scale doesn't lie; the logs don't lie ... and I hate to get rid of them; so much that I really have no problem keeping them for a year or more. There is so much value in them, and they really don't take up all the much space if you zip them up ... even in very busy environment. But, if you leave logs as uncompressed text, you could easily see a volume fill up and you'll be out of space wondering what the heck is going on.

That said, to address a few of my desires:

1) To have logs for as long as possible
2) To not waste disk space unnecessarily
3) To make troubleshooting easier
4) To make planning easier (the next time you need an upgrade you can use the data in these logs to backup your claims / requests)
5) To deliver a script that I promised to a customer that has been patiently waiting

I've put together this mega-simple script which can really be modified to just about anything ... just be gentle with it because if you change things around you could easily be deleting entire file systems instead of just zipping up some aging log files.

Attached is a zip file with 3 files:

zip.exe (duh)
forfiles.exe (command to iterate the zip command)
go.cmd (script that you execute)

... and here is the contents of go.cmd:

-----

@ECHO OFF
REM -- Script to individually zip BES Log files ...
REM -- Place this file along with forfiles.exe and zip.exe in the root directory of your BlackBerry Logs folder
REM -- By Default: C:\Program Files\Research in Motion\BlackBerry Enterprise Server\Logs
REM -- This will zip all TXT files in the current and all sub-directories 10 days old or older
REM -- 4/23/2008 - Updated to delete old files / directories
REM -- Change "-d-90" if you want to delete files at an age different than 90 days
REM -- Uncomment the REM -- lines at the bottom if you actually want it to do deletion

forfiles.exe -p. -s -m*.txt -d-10 -c"zip -m @FILE.zip @FILE"

REM -- forfiles.exe -p. -s -d-90 -m*.txt -c"cmd /c if @ISDIR==FALSE del /q /f @FILE"
REM -- forfiles.exe -p. -s -d-90 -m*.csv -c"cmd /c if @ISDIR==FALSE del /q /f @FILE"
REM -- forfiles.exe -p. -s -d-90 -m*.zip -c"cmd /c if @ISDIR==FALSE del /q /f @FILE"
REM -- forfiles.exe -p. -s -d-90 -m*.* -c"cmd /c if @ISDIR==TRUE rd /q @FILE"
-----

Here's a breakdown of what the command is doing:

forfiles.exe (The forfiles command, to iterate through all the log files)
-p. (The starting point for the filelist. "." means the current working directory that forfiles.exe is located in)
-s (Recurse subdirectories)
-m*.txt (Process all .TXT files)
-d-10 (10 days old or older)
-c"zip -m @FILE.zip @FILE" (The command to execute on each file. @FILE represents the current file being processed. zip -m tells it to zip the file and move the file into the zip, therefore removing the original .TXT file. Then the next time this gets run it won't have to zip the file again.)

Put these 3 files in the root of your BES Logs directory ... by default it is: "C:\Program Files\Research in Motion\BlackBerry Enterprise Server\Logs" and schedule go.cmd as a task to run nightly; you'll keep the last 10 days of logs easily accessible and older logs on the file system, just compressed.

I had thought about having each day zip into a single file, but then the structure of what is there gets modified ... I wanted to keep it simple, keep the directory / file structure as it was, but just compress the files.

Alternatively, you could enable file compression on the file system and ignore this script totally ... but I like this better
Attached Files
File Type: zip ziplogfiles.zip (93.5 KB, 237 views)
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-31-2009, 09:55 PM
hdawg's Avatar
Proprietor
 
Join Date: Nov 2008
Posts: 2,257
Blog Entries: 147
Default

w00t
__________________
http://blog.port3101.org/hdawg/
Reply With Quote
  #3 (permalink)  
Old 07-15-2009, 02:49 PM
BES Administrator
 
Join Date: Jan 2009
Location: Atlanta
Posts: 41
Default

Very good stuff, but one comment, one question on this:

Comment:
If you want to have it delete files older then 90 days, you need to move the line
forfiles.exe -p. -s -m*.txt -d-10 -c"zip -m @FILE.zip @FILE"
to the end (after the 4 lines to delete files); otherwise, it zips everything older then 10 days, then when it gets to the lines to find files older then 90 days, it doesn't find anything because zipping the files changed the modified date on all of them.

Question:
Should the lines to delete files also delete the folders? Once I figured out that the zip portion needed to come after the delete portion, it still doesn't appear to be removing the older folders--not sure if I did something to cause this, or if it doesn't delete them by design.
Reply With Quote
  #4 (permalink)  
Old 07-15-2009, 04:06 PM
hdawg's Avatar
Proprietor
 
Join Date: Nov 2008
Posts: 2,257
Blog Entries: 147
Default

Quote:
Originally Posted by jdizzle View Post
Very good stuff, but one comment, one question on this:

Comment:
If you want to have it delete files older then 90 days, you need to move the line
forfiles.exe -p. -s -m*.txt -d-10 -c"zip -m @FILE.zip @FILE"
to the end (after the 4 lines to delete files); otherwise, it zips everything older then 10 days, then when it gets to the lines to find files older then 90 days, it doesn't find anything because zipping the files changed the modified date on all of them.
the del for *.txt really I guess is irrelevant since the files are getting zipped anyway. But yes, it'd need to be moved to be effective for that.

Quote:
Question:
Should the lines to delete files also delete the folders? Once I figured out that the zip portion needed to come after the delete portion, it still doesn't appear to be removing the older folders--not sure if I did something to cause this, or if it doesn't delete them by design.
forfiles.exe -p. -s -d-90 -m*.* -c"cmd /c if @ISDIR==TRUE rd /q @FILE"


^^ should delete the folders.
__________________
http://blog.port3101.org/hdawg/
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.port3101.org/scripts-tools-hints-tricks/717-script-zip-log-files.html
Posted By For Type Date
Script to remove BES log files/directories This thread Refback 05-16-2011 12:51 PM
Re: [Bes-admins] BESX Logs Filling Up Drive This thread Refback 10-05-2010 10:37 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing files dmonty Port 3101: The BES Admin Bar & Grill 7 09-27-2010 07:04 PM
BAS not accessible, not write Log files magikweis Port 3101: The BES Admin Bar & Grill 5 02-15-2010 10:13 PM
Script to remove BES log files/directories Messisa Scripts & Tools / Hints & Tricks 12 07-20-2009 08:03 PM
KB10878 - When to clear debug log files hdawg Featured BlackBerry KB Articles 0 06-27-2009 02:34 AM


All times are GMT -4. The time now is 02:25 AM.
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.


 

SEO by vBSEO 3.3.2 PL2