Script to remove BES log files/directories

02-02-2009, 02:57 PM
|
|
BES Activated
|
|
Join Date: Feb 2009
Posts: 1
|
|
Script to remove BES log files/directories
'THIS SCRIPT Checks for folders older than 7 days in the path D:\PROGRAM FILES\RESEARCH IN MOTION\BLACKBERRY ENTERPRISE SERVER\LOGS.
'If folders are older than 7 days they are deleted.
'A logfile is written to the D:\PROGRAM FILES\RESEARCH IN MOTION\BLACKBERRY ENTERPRISE SERVER\LOGS path on completion.
'This logfile is overwritten at each run.
On Error Resume Next
'Define the constants
'Number of days to retain the folder
CONST ADJUSTDATE = -7
'Enter your folder path to the BlackBerry logs below
CONST FOLDERPATH = "D:\PROGRAM FILES\RESEARCH IN MOTION\BLACKBERRY ENTERPRISE SERVER\LOGS"
CONST FILENAME = "DeleteLogsScript.log"
'Get the File System Objects
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(FOLDERPATH)
Set subFolders = folder.SubFolders
'Set the log file
sLogFilePath = FOLDERPATH & "\" & FILENAME
set logfile = fso.CreateTextFile(sLogFilePath, True)
'Write the log file
logfile.WriteLine("BES Delete Logs started on " & Now )
logfile.WriteLine("The following folders were deleted")
'Set the date to delete folders older than
dateold = DateAdd("d", ADJUSTDATE, Date)
'Process all the folders
For Each folderObject in SubFolders
errorvalue=0 'ensure the error value is reset for each folder
datemod = DateValue(folderObject.DateLastModified)
'Delete folders that are old
IF datemod < dateold Then
fso.DeleteFolder folderobject, true 'this line deletes the folders
errorvalue = Err.Number
If ErrorValue = 0 Then 'The folder was deleted ok
logfile.WriteLine( folderobject.Name )'record folders that were successfully deleted
Else
If Errorvalue = 70 Then
'Error value 70 denotes the folder could not be deleted for access reasons. Most likely the folder (or a file within it) is in use.
logfile.WriteLine (folderObject.path & " could not be deleted. This folder, or a file within it, may be in use.")
Else
logfile.WriteLine (folderObject.path & " could not be deleted. Unknown error")
End If
End If
End IF
Next
'Write the log file
logfile.WriteLine("BES Delete Logs Completed on.")
logfile.Close
'Clear the variables
Set subFolders = Nothing
Set folder = Nothing
Set fso = Nothing
Set logfile = Nothing
|

02-02-2009, 03:09 PM
|
 |
Super Moderator
|
|
Join Date: Dec 2008
Location: West Michigan
Posts: 763
|
|
Silly question - what is the difference between this script and using the BlackBerry Server Configuration panel (Logging tab) to set the 'Debug log maximum daily file age'?
__________________
You may know me as Juwaack68
|

02-04-2009, 09:43 AM
|
|
BES Activated
|
|
Join Date: Feb 2009
Location: FL
Posts: 3
|
|
I don't think the "BlackBerry Server Configuration panel (Logging tab) to set the 'Debug log maximum daily file age'" removes the directories it just removes the .txt files, could be wrong though.
|

02-04-2009, 01:34 PM
|
|
BES Activated
|
|
Join Date: Feb 2009
Location: NC
Posts: 1
|
|
Steve086, you are exactly right. We have 30 days set on our logging and it just removes the txt files within the directories.
-Chris
|

04-16-2009, 08:44 PM
|
|
BES Activated
|
|
Join Date: Apr 2009
Location: kansas
Posts: 6
|
|
does it delete off of last modified date or the internal stamp date of the log file? Can this be setup in windows schedular
|

04-16-2009, 11:20 PM
|
 |
Proprietor
|
|
Join Date: Nov 2008
Posts: 2,237
|
|
Quote:
Originally Posted by hayabusa
does it delete off of last modified date or the internal stamp date of the log file? Can this be setup in windows schedular
|
Great question; I don't know. I created a script to zip log files and ignore having the BES do it ...
__________________
http://blog.port3101.org/hdawg/
The views expressed by me on Port3101 and its affiliated sites are my own and do not necessarily reflect the views of my employer.
|

05-11-2009, 02:10 PM
|
 |
BES Expert
|
|
Join Date: May 2009
Location: Philadelphia, PA
Posts: 98
|
|
so the script deleted the folders for me but the log file didnt update correctly. all it wrote to the log was...
BES Delete Logs started on 5/11/2009 1:08:53 PM
The following folders were deleted
BES Delete Logs Completed on.
also, it left logs more than 7 days old, ran it today and it left logs since 4/25/2009
any ideas?
__________________
Two months ago, I saw a provocative movie on cable TV. It was called The Net, with that girl from the bus.
|

05-11-2009, 08:44 PM
|
 |
Proprietor
|
|
Join Date: Nov 2008
Location: Atlanta, GA
Posts: 2,032
|
|
By the way, I opened an SDR for having MDS logs (MDAT) to have a configurable retention. A separate one was opened for all other log files, audit logs, orphaned log folders, etc.
__________________
BCSA (4.1, 5.0) | BCSD (4.1, 5.0)
The views expressed by me on Port3101.org are my own and do not necessarily reflect the views of my employer.
|

05-12-2009, 01:30 PM
|
 |
BES Expert
|
|
Join Date: May 2009
Location: Philadelphia, PA
Posts: 98
|
|
fixed a few bugs in your script. it now writes what files it deletes the log and records the date when it finishes.
also if you have the "debug log max daily file age" set, then your folders will have been modified more recently (mine was set to 7 days) and thus not all folders you might expect would be deleted. i changed the one param to folderObject.DateCreated and it then only leaves exactly 7 days (or whatever u specify). it won't delete the webserver logs as they're in use. make sure you move your installer files if you need them as they will be deleted.
'THIS SCRIPT Checks for folders older than 7 days in the path D:\BESLog\BlackBerry Enterprise Server\Logs.
'If folders are older than 7 days they are deleted.
'A logfile is written to the D:\BESLog\BlackBerry Enterprise Server\Logs path on completion.
'This logfile is overwritten at each run.
On Error Resume Next
'Define the constants
'Number of days to retain the folder
CONST ADJUSTDATE = -7
'Enter your folder path to the BlackBerry logs below
CONST FOLDERPATH = "D:\BESLog\BlackBerry Enterprise Server\Logs"
CONST FILENAME = "DeleteLogsScript.log"
'Get the File System Objects
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(FOLDERPATH)
Set subFolders = folder.SubFolders
'Set the log file
sLogFilePath = FOLDERPATH & "\" & FILENAME
set logfile = fso.CreateTextFile(sLogFilePath, True)
'Write the log file
logfile.WriteLine("BES Delete Logs started on " & Now )
logfile.WriteLine("The following folders were deleted")
'Set the date to delete folders older than
dateold = DateAdd("d", ADJUSTDATE, Date)
'Process all the folders
For Each folderObject in SubFolders
ErrorValue = 0 'ensure the error value is reset for each folder
datemod = DateValue(folderObject.DateLastModified)
'Delete folders that are old
IF datemod < dateold Then
folname = folderObject.path
fso.DeleteFolder folderObject, true 'this line deletes the folders
ErrorValue = Err.Number
If ErrorValue = 76 Then
'The folder was deleted ok
logfile.WriteLine (folname & " successfully deleted.") 'record folders that were successfully deleted
Else
If ErrorValue = 70 Then
'Error value 70 denotes the folder could not be deleted for access reasons. Most likely the folder (or a file within it) is in use.
logfile.WriteLine (folderObject.path & " could not be deleted. This folder, or a file within it, may be in use.")
Else
logfile.WriteLine (folderObject.path & " could not be deleted. Unknown error")
End If
End If
End IF
Next
'Write the log file
logfile.WriteLine("BES Delete Logs Completed on " & NOW)
logfile.Close
'Clear the variables
Set subFolders = Nothing
Set folder = Nothing
Set fso = Nothing
Set logfile = Nothing
Set folname = Nothing
__________________
Two months ago, I saw a provocative movie on cable TV. It was called The Net, with that girl from the bus.
Last edited by RadHaz75; 05-12-2009 at 01:34 PM.
|

05-15-2009, 07:23 PM
|
|
BES Activated
|
|
Join Date: May 2009
Posts: 1
|
|
Hi,
What is the file type for this script, is it .vbs?
I changed BES logs directory and I changed it to 15 days, but when I run it, nothing happens.
Thanks in advance.
Quote:
Originally Posted by RadHaz75
fixed a few bugs in your script. it now writes what files it deletes the log and records the date when it finishes.
also if you have the "debug log max daily file age" set, then your folders will have been modified more recently (mine was set to 7 days) and thus not all folders you might expect would be deleted. i changed the one param to folderObject.DateCreated and it then only leaves exactly 7 days (or whatever u specify). it won't delete the webserver logs as they're in use. make sure you move your installer files if you need them as they will be deleted.
'THIS SCRIPT Checks for folders older than 7 days in the path D:\BESLog\BlackBerry Enterprise Server\Logs.
'If folders are older than 7 days they are deleted.
'A logfile is written to the D:\BESLog\BlackBerry Enterprise Server\Logs path on completion.
'This logfile is overwritten at each run.
On Error Resume Next
'Define the constants
'Number of days to retain the folder
CONST ADJUSTDATE = -7
'Enter your folder path to the BlackBerry logs below
CONST FOLDERPATH = "D:\BESLog\BlackBerry Enterprise Server\Logs"
CONST FILENAME = "DeleteLogsScript.log"
'Get the File System Objects
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(FOLDERPATH)
Set subFolders = folder.SubFolders
'Set the log file
sLogFilePath = FOLDERPATH & "\" & FILENAME
set logfile = fso.CreateTextFile(sLogFilePath, True)
'Write the log file
logfile.WriteLine("BES Delete Logs started on " & Now )
logfile.WriteLine("The following folders were deleted")
'Set the date to delete folders older than
dateold = DateAdd("d", ADJUSTDATE, Date)
'Process all the folders
For Each folderObject in SubFolders
ErrorValue = 0 'ensure the error value is reset for each folder
datemod = DateValue(folderObject.DateLastModified)
'Delete folders that are old
IF datemod < dateold Then
folname = folderObject.path
fso.DeleteFolder folderObject, true 'this line deletes the folders
ErrorValue = Err.Number
If ErrorValue = 76 Then
'The folder was deleted ok
logfile.WriteLine (folname & " successfully deleted.") 'record folders that were successfully deleted
Else
If ErrorValue = 70 Then
'Error value 70 denotes the folder could not be deleted for access reasons. Most likely the folder (or a file within it) is in use.
logfile.WriteLine (folderObject.path & " could not be deleted. This folder, or a file within it, may be in use.")
Else
logfile.WriteLine (folderObject.path & " could not be deleted. Unknown error")
End If
End If
End IF
Next
'Write the log file
logfile.WriteLine("BES Delete Logs Completed on " & NOW)
logfile.Close
'Clear the variables
Set subFolders = Nothing
Set folder = Nothing
Set fso = Nothing
Set logfile = Nothing
Set folname = Nothing
|
|

05-16-2009, 11:25 PM
|
 |
Proprietor
|
|
Join Date: Nov 2008
Posts: 2,237
|
|
Quote:
Originally Posted by zee
Hi,
What is the file type for this script, is it .vbs?
I changed BES logs directory and I changed it to 15 days, but when I run it, nothing happens.
Thanks in advance.
|
That is indeed VBS ... just use the script I made
__________________
http://blog.port3101.org/hdawg/
The views expressed by me on Port3101 and its affiliated sites are my own and do not necessarily reflect the views of my employer.
|

07-20-2009, 08:29 PM
|
|
BES Activated
|
|
Join Date: Feb 2009
Location: Costa Rica
Posts: 1
|
|
Hi guys, I just want to know what happend with the Webserver and Installer Folders/logs could those be deleted?
|

07-20-2009, 09:03 PM
|
 |
Proprietor
|
|
Join Date: Nov 2008
Posts: 2,237
|
|
Sure you can delete them. Once the installation is successful you're all set. If the webserver directory is empty you can delete it too.
__________________
http://blog.port3101.org/hdawg/
The views expressed by me on Port3101 and its affiliated sites are my own and do not necessarily reflect the views of my employer.
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|