Friday, August 13, 2010

Script to zip BES Log files

BES has the ability to automatically purge old log files as a built-in function of BES. You can go to BlackBerry Server Configuration and change how long the server will keep the logs before purging them, but you can't do the same for SMS/PIN/Phone logs.
Regardless, 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)

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.



Message Edited by AndyDufresne on 09-05-2008 09:08 AM



------------------------------

If you've found a solution through a post; please mark it as a solution.


If someone's was particularly helpful, give them kudo's!.


Get busy living, or get busy dying.


http://blog.port3101.org/hdawg/



Attachments:



Attachment ziplogfiles.zip 94 KB



 



Source

No comments: