Highlighted

Configuring or getting dbclient log name

Hi, 

I'm trying to automate  SqlServer Backups by executing from control-m, which is a 3rd party schedule software. 

To do this, I have created a .bat file that call the Netbackup exec file (dbbackex.exe).  

I use this code to do this: 

echo "Starting SqlServer Backup on  %COMPUTERNAME% " > C:\backuplog.log
"C:\Program Files\Veritas\NetBackup\bin\dbbackex" -f C:\bcktest.bch -p nopr_bdd_msql_all -s back -np >> C:\backuplog.log

echo %date% %time% >> C:\backuplog.log
echo "Backup Finished " >> C:\backuplog.log

IF %ERRORLEVEL% GTR 0 echo "Backup Finished with ERROR [%ERRORLEVEL%]" >> C:\backuplog.log
IF %ERRORLEVEL% EQU 0 echo "Backup Finished SUCCESSFULLY" >> C:\backuplog.log

echo "Review log file:  C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs" >> C:\backuplog.log

 

I would like to get the ERROR message, not only the code, using this script and if not possible, get dbclient log name to complete the last line and show something like:

Review log file:  C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs\0714115143814-55584-20776-000-000-prg

Does anyone know if this is possible and how could I do this? Or is it possible to configure de path and logfile name?

 

Other posibility I'm thinking of is manage error codes on my own, but I would need Error code list and cannot find it. Does anyone know if this exist?

 

I would accept any other suggestion to get error information. I cannot use any other code but cmd/bat. 

 

Thanks in Advance, 

 

Elena 

 

 

 

1 Solution

Accepted Solutions
Accepted Solution!

Ok - I've just had a go at

Ok - I've just had a go at the script below.

I will attempt to take in to consideration your most recent post above, later today... to see if the script can access the logs that you have indicated - but it's not easy for me - as I don't have an SQL client to test with.

Anyway, try the below for now... just curious to see if it works for you - and I will make it use the logs you have highlighted.

@echo off
setlocal enabledelayedexpansion

set z_path=%~dp0
set z_name=%~n0

set z_file_lis=!z_path!!z_name!.lis
set z_file_log=!z_path!!z_name!.log
set z_file_tmp=!z_path!!z_name!.tmp

if exist "!z_file_lis!"  del "!z_file_lis!"
if exist "!z_file_tmp!"  del "!z_file_tmp!"

set z_final_sts=999

call :log "**************************************************"
call :log "Script started..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Determining NetBackup installation path..."

reg query "HKLM\Software\Veritas\NetBackup\CurrentVersion" /v "InstallDir" >"!z_file_tmp!" 2>&1
set z_sts=!errorlevel!
if not !z_sts!==0 (
  call :log "...failed to determine install directory for NetBackup, status `!z_sts!`, script aborting..."
  goto :end
)
for /f "tokens=1,2,* skip=1" %%a in ('type "!z_file_tmp!"') do (set z_installdir=%%c)

call :log "...NetBackup installation path is:  !z_installdir!"
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Checking for `dbbackex` CLI tool..."

set z_dbbackex=!z_installdir!NetBackup\bin\dbbackex.exe

if not exist "!z_dbbackex!" (
  call :log "...unable to locate `!z_dbbackex!` command, script aborting..."
  goto :end
)

call :log "...found dbbackex at `!z_dbbackex!`..."
call :log "...done..."

call :log ""
call :log "Locating SQL `batch` file..."

set z_file_bch=!z_path!!z_name!-!computername!.bch

if not exist "!z_file_bch!" (
  call :log "...unable to locate `!z_file_bch!`, script aborting..."
  goto :end
)

call :log "...found `!z_file_bch!`..."
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Calling dbbackex to start MS SQL Server backup..."

"!z_dbbackex!" -f "!z_file_bch!" -p TEST001 -s back -np >>"!z_file_log!" 2>&1
set z_sts=!errorlevel!
set z_final_sts=!z_sts!

if !z_sts!==0 (
  call :log "...call to dbbackex completed SUCCESSFULLY..."
) else (
  call :log "...call to dbbackex FAILED, status `!z_sts!`..."
)

call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Locating most recent dbclient log..."

set z_dbclient_path=!z_installdir!NetBackup\logs\dbclient\

if not exist "!z_dbclient_path!" (
  call :log "...unable to locate `!z_dbclient_path!`, script aborting..."
  goto :end
) else (
  dir /o:d /t:w /b "!z_dbclient_path!" >"!z_file_tmp!" 2>&1
  set z_sts=!errorlevel!
  if not !z_sts!==0 (
    call :log "...unable to list dbclient log files, status `!z_sts!`, script aborting..."
    goto :end
  )
)

for /f "tokens=*" %%a in ('type "!z_file_tmp!"') do (set z_dbclient_file=%%a)

set z_dbclient_spec=!z_dbclient_path!!z_dbclient_file!

if not exist "!z_dbclient_spec!" (
  call :log "...unexpected unable to locate `!z_dbclient_spec!`, script aborting..."
  goto :end
)

call :log "...most recent dbclient log is:  !z_dbclient_spec!"
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Acquiring trailing PID pair from dbclient log..."

set z_pids=

for /f "tokens=1,2" %%a in ('type "!z_dbclient_spec!"') do (set z_pids=%%b)

if "!z_pids!"=="" (
  call :log "...failed to acquire a trailing PID pair from dbclient log, script aborting..."
  goto :end
)

call :log "...found trailing pid pair of:  !z_pids!"
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Extracting trailing log section from dbclient log..."
call :log "WARNING:"
call :log "WARNING: the following log text, may, or MAY NOT, be relevant to our call to dbbackex..."
call :log "WARNING:"

find /i "!z_pids!" "!z_dbclient_spec!" >"!z_file_lis!" 2>&1
set z_sts=!errorlevel!
if !z_sts!==0 (
  call :log "-----------------------------------------------"
  type "!z_file_lis!"
  type "!z_file_lis!" >>"!z_file_log!"
  call :log "-----------------------------------------------"
) else (
  call :log "...failed to find PID pair in dbclient log, status `!z_sts!`..."
)
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************
REM *** If we get here then we haven't aborted, so cleanup...

if exist "!z_file_lis!"  del "!z_file_lis!"
if exist "!z_file_tmp!"  del "!z_file_tmp!"


REM *********************************************************************************
REM *********************************************************************************
REM *** If/when the script aborts, it can jump here...

:end
call :log ""
call :log "Script exiting with status `!z_final_sts!`..."
echo+
exit /b !z_final_sts!


REM *********************************************************************************
REM *********************************************************************************

:log
(echo !date! !time:~0,8!  %~1)
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
goto :eof

View solution in original post

12 Replies

Might be easier to check the

Might be easier to check the output of

C:\Program Files\Veritas\NetBackup\logs\mssql_backup_failures

You can capture any errors

You can capture any errors (written to what is effectively stderr in Windows DOS batch) by using the construct:

2>&1

...which means... redirect any output on IO channel 2 (stderr) and append it to the IO channel 1 (stdout)...

...i.e. there is no need to use a double chevron, i.e. there is no need to use this:  2>>&1...

...so, add 2>&1 to the end of your call to dbbackex, e.g:

"C:\Program Files\Veritas\NetBackup\bin\dbbackex" -f C:\bcktest.bch -p nopr_bdd_msql_all -s back -np >> C:\backuplog.log 2>&1

.

And/or, do you want to capture the error output and then parse through the text of this 'error output message' to identify the error log file path and name?  If so, then if you could post an example of two things:

1) The output from dbbackex when it works.

2) The output from dbbackex when it fails.

If you can show me the output from both of these, and if one or both of them contain the name of the actual  dbbackex log file, then I should be able to give you a little bit of code to extract that log file name, and then append (or copy) the contents of this 'error log file' to your log file.

Even if the 'stderr' output

Even if the 'stderr' output from dbbackex does not contain a file name, it should still be possible to identify the most recent log file, e.g. if you can also supply the output from these two commands:

dir /o:d /t:w /4 "C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs\"

...and also this:

dir /o:d /t:w /b "C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs\"

...then I'm fairly sure that we can pick up the most recently written log file.

Hi Sdo,  I have tried what

Hi Sdo, 

I have tried what you say and got nothing on my log file. I suppose dbbackex doesn't throw any message. 

When I execute it, as it has the parameter -np (which means no prompt, or something like that Smiley Happy ), it does not throw any message, just finish.  The same happens when it doesn't work. Just finish. 

When i don't specify the parameter -np,  then I recevie this: 

error:

error_output.JPG

success:

success_output.JPG

 

I don't know where the log file name is configured and don't receive any message with it. 

 

Thank you, 

elena

I don't think you're going to

I don't think you're going to be able to do anything other than check the exit status of dbbackex.

The call to dbbackex will write to the 'dbclient' legacy log file if the syntax of the call is valid, but it doesn't write to dbclient log if the command structure passed to dbbackex is bad.  And both end with status 2, so there's no way of knowing whether any trailing log text in the dbclient log is related to a recent to dbbackex just made, or not.  Plus, I can't see a simple way of acquiring the PID of the dbbackex process, so there's no simple way in DOS batch of acquiring dbclient log text for the call to dbbackex.

I could give you some code to pick out the trailing pid pair of the dbclient log, and then search dbclient to acquire all of the log text for one or both of the PIDs, but there's no way of knowing whether that log text is actually for your call to dbbackex or not.

Does anyone know if dbbackex writes any log files elsewhere?

Does it actually write anything here:   ...\NetBackup\logs\user_ops\MsSql\Logs

Hi,  as far as I have been

Hi, 

as far as I have been able to learn, dbbackex writes almost into 3 files: 

..\NetBackup\logs\mssql_backup_failures

it writes here when any backup fails and writes 1 file per day, so it adds each backup information.

..\NetBackup\logs\user_ops\MsSql\Logs

this is the log i'm insterested in. Here it writes status of each execution. Creates 1 file per execution. If the command is right, then there is information here. I'll attach 2 different files to let you know what happens.

..\NetBackup\logs\dbclient

here, it creates 1 file per day and add the information of each backup. Basicaly is the same information that you get on ..\NetBackup\logs\user_ops\MsSql\Logs, but just 1 file per day.

 

If I can only check the exit status and get the log name, should be good enough. If it's not possible to get the file name, then I would write the log path directly and we'll have to look for the correct, log. 

 

Thank you, 

Elena

I don't know why I cannot see

I don't know why I cannot see one of my answers.  Copy the output you requested here, 

dir /o:d /t:w /4 "C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs\"
Directory of C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs
09/12/2013  04:10 PM             6,032 0912113160734-2936-1920-000-000-prg
02/05/2014  05:44 PM               898 0205114164406-6512-8480-000-000-prg
02/05/2014  05:48 PM               898 0205114164826-5912-10740-000-000-prg
02/05/2014  05:52 PM             4,945 0205114165141-1988-10260-000-000-prg
02/05/2014  05:58 PM             2,599 0205114165831-8140-4916-000-000-prg
02/05/2014  06:03 PM             2,598 0205114170319-6816-6016-000-000-prg
02/05/2014  06:07 PM             3,748 0205114170636-13136-6656-000-000-prg
02/05/2014  06:14 PM             1,502 0205114171440-12500-3912-000-000-prg
02/05/2014  06:20 PM             1,502 0205114172038-12224-11212-000-000-prg
02/05/2014  06:33 PM             6,495 0205114173259-9700-6396-000-000-prg


dir /o:d /t:w /b "C:\Program Files\Veritas\NetBackup\logs\user_ops\MsSql\Logs\"
0912113160734-2936-1920-000-000-prg
0205114164406-6512-8480-000-000-prg
0205114164826-5912-10740-000-000-prg
0205114165141-1988-10260-000-000-prg
0205114165831-8140-4916-000-000-prg
0205114170319-6816-6016-000-000-prg
0205114170636-13136-6656-000-000-prg
0205114171440-12500-3912-000-000-prg
0205114172038-12224-11212-000-000-prg
0205114173259-9700-6396-000-000-prg

attach a file with the

attach a file with the content you asked for: 

Accepted Solution!

Ok - I've just had a go at

Ok - I've just had a go at the script below.

I will attempt to take in to consideration your most recent post above, later today... to see if the script can access the logs that you have indicated - but it's not easy for me - as I don't have an SQL client to test with.

Anyway, try the below for now... just curious to see if it works for you - and I will make it use the logs you have highlighted.

@echo off
setlocal enabledelayedexpansion

set z_path=%~dp0
set z_name=%~n0

set z_file_lis=!z_path!!z_name!.lis
set z_file_log=!z_path!!z_name!.log
set z_file_tmp=!z_path!!z_name!.tmp

if exist "!z_file_lis!"  del "!z_file_lis!"
if exist "!z_file_tmp!"  del "!z_file_tmp!"

set z_final_sts=999

call :log "**************************************************"
call :log "Script started..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Determining NetBackup installation path..."

reg query "HKLM\Software\Veritas\NetBackup\CurrentVersion" /v "InstallDir" >"!z_file_tmp!" 2>&1
set z_sts=!errorlevel!
if not !z_sts!==0 (
  call :log "...failed to determine install directory for NetBackup, status `!z_sts!`, script aborting..."
  goto :end
)
for /f "tokens=1,2,* skip=1" %%a in ('type "!z_file_tmp!"') do (set z_installdir=%%c)

call :log "...NetBackup installation path is:  !z_installdir!"
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Checking for `dbbackex` CLI tool..."

set z_dbbackex=!z_installdir!NetBackup\bin\dbbackex.exe

if not exist "!z_dbbackex!" (
  call :log "...unable to locate `!z_dbbackex!` command, script aborting..."
  goto :end
)

call :log "...found dbbackex at `!z_dbbackex!`..."
call :log "...done..."

call :log ""
call :log "Locating SQL `batch` file..."

set z_file_bch=!z_path!!z_name!-!computername!.bch

if not exist "!z_file_bch!" (
  call :log "...unable to locate `!z_file_bch!`, script aborting..."
  goto :end
)

call :log "...found `!z_file_bch!`..."
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Calling dbbackex to start MS SQL Server backup..."

"!z_dbbackex!" -f "!z_file_bch!" -p TEST001 -s back -np >>"!z_file_log!" 2>&1
set z_sts=!errorlevel!
set z_final_sts=!z_sts!

if !z_sts!==0 (
  call :log "...call to dbbackex completed SUCCESSFULLY..."
) else (
  call :log "...call to dbbackex FAILED, status `!z_sts!`..."
)

call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Locating most recent dbclient log..."

set z_dbclient_path=!z_installdir!NetBackup\logs\dbclient\

if not exist "!z_dbclient_path!" (
  call :log "...unable to locate `!z_dbclient_path!`, script aborting..."
  goto :end
) else (
  dir /o:d /t:w /b "!z_dbclient_path!" >"!z_file_tmp!" 2>&1
  set z_sts=!errorlevel!
  if not !z_sts!==0 (
    call :log "...unable to list dbclient log files, status `!z_sts!`, script aborting..."
    goto :end
  )
)

for /f "tokens=*" %%a in ('type "!z_file_tmp!"') do (set z_dbclient_file=%%a)

set z_dbclient_spec=!z_dbclient_path!!z_dbclient_file!

if not exist "!z_dbclient_spec!" (
  call :log "...unexpected unable to locate `!z_dbclient_spec!`, script aborting..."
  goto :end
)

call :log "...most recent dbclient log is:  !z_dbclient_spec!"
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Acquiring trailing PID pair from dbclient log..."

set z_pids=

for /f "tokens=1,2" %%a in ('type "!z_dbclient_spec!"') do (set z_pids=%%b)

if "!z_pids!"=="" (
  call :log "...failed to acquire a trailing PID pair from dbclient log, script aborting..."
  goto :end
)

call :log "...found trailing pid pair of:  !z_pids!"
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************

call :log ""
call :log "Extracting trailing log section from dbclient log..."
call :log "WARNING:"
call :log "WARNING: the following log text, may, or MAY NOT, be relevant to our call to dbbackex..."
call :log "WARNING:"

find /i "!z_pids!" "!z_dbclient_spec!" >"!z_file_lis!" 2>&1
set z_sts=!errorlevel!
if !z_sts!==0 (
  call :log "-----------------------------------------------"
  type "!z_file_lis!"
  type "!z_file_lis!" >>"!z_file_log!"
  call :log "-----------------------------------------------"
) else (
  call :log "...failed to find PID pair in dbclient log, status `!z_sts!`..."
)
call :log "...done..."


REM *********************************************************************************
REM *********************************************************************************
REM *** If we get here then we haven't aborted, so cleanup...

if exist "!z_file_lis!"  del "!z_file_lis!"
if exist "!z_file_tmp!"  del "!z_file_tmp!"


REM *********************************************************************************
REM *********************************************************************************
REM *** If/when the script aborts, it can jump here...

:end
call :log ""
call :log "Script exiting with status `!z_final_sts!`..."
echo+
exit /b !z_final_sts!


REM *********************************************************************************
REM *********************************************************************************

:log
(echo !date! !time:~0,8!  %~1)
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
goto :eof

View solution in original post

Ooops - you'll need to change

Ooops - you'll need to change my policy name TEST001 back to your policy name, and place a copy of your SQL batch 'bch' file in the same folder as the script above.

You're a Genious!!!!! Now I

You're a Genious!!!!!

Now I can do many many things with this!!! (get information from other logs, put my logs where I want, etc.. )

 

Thank you very much for your help !!!!! I'm so happy!!!

 

Elena

 

 

No worries.  Glad it helped.

No worries.  Glad it helped.