If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Anybody have an archive script for the db2diag.log file?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-06, 11:43
lavalamp1964 lavalamp1964 is offline
Registered User
 
Join Date: Nov 2006
Posts: 7
Anybody have an archive script for the db2diag.log file?

I'm looking for a script to backup and remove the db2diag.log file. I saw one, but can't make it work. I'm new to bat file creations. Thanks!
Rob

Here it is, but it doesn't work when I try to run it.

@echo off
::---------------------------------------------------------------------------::
:: This is a Windows Shell Script to archive the db2
diagnostic log file. It :: assumes the db2diag.log file
is in the default diagnostic log directory :: and
renames it to db2diag.YYYYMMDD.log It also deletes all
but the last :: seven (7) of these diagnostic log
archives.
::---------------------------------------------------------------------------::
set script_name=%~n0 set script_log=%~n0.log set
script_ver=1.0 set DB2INSTANCE=DB2 set
DB2DATABASE=SAMPLE

title %script_name% v%script_ver% echo %script_name%
v%script_ver% started on %date% at %time%


::---------------------------------------------------------------------------::
:: Set Script Date Variable
::---------------------------------------------------------------------------::
for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set script_date=%%l%%j%%k
)


::---------------------------------------------------------------------------::
:: Set DB2 Path Variable
::---------------------------------------------------------------------------::
if not defined db2path (
for /F %%i in ('db2set db2path') do (set db2path=%%i)
echo %script_name% v%script_ver% set db2path as %db2path% )


set db2diag_path=%db2path%\%db2instance%
echo
%script_name% v%script_ver% set db2diag_path to
%db2diag_path%

set db2diag_file=%db2diag_path%\db2diag.log
echo
%script_name% v%script_ver% set db2diag_file to
%db2diag_file%


::---------------------------------------------------------------------------::
:: Archive DB2 Diagnostic Log File
::---------------------------------------------------------------------------::
echo %script_name% v%script_ver% archiving
%db2diag_file% to db2diag.%script_date%.log ren
%db2diag_file% db2diag.%script_date%.log 2>
%script_log% if not %errorlevel% == 0 ( echo ERROR:
Unable to archive %db2diag_file% to
db2diag.%script_date%.log, RC=%errorlevel% type
%script_log% )


::---------------------------------------------------------------------------::
:: Delete DB2 Diagnostic Log Archives 7 days or older
::---------------------------------------------------------------------------::
set db2diag_arch=%db2diag_path%\db2diag.*.log for /f
"skip=7" %%i in ('dir %db2diag_arch% /b /o:-n') do (
echo %script_name% v%script_ver% purging %%i del
%db2diag_path%\%%i 2> %script_log% if not
%errorlevel% == 0 ( echo ERROR: Unable to delete
archive %%i, RC=%errorlevel% type %script_log% ) )

echo %script_name% v%script_ver% completed on %date% at
%time%
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On