cancel
Showing results for 
Search instead for 
Did you mean: 
sdo
Moderator
Moderator
Partner    VIP    Certified

Hope this helps others.
Please read the notes at the top of the script before using - as it needs to reside in path which does not have spaces at any point in the folder path specification.
The script will detect where the NetBackup binaries are installed, and will detect the output path of the nbdeployutil --gather stage and use this as input into the two nbdeployutil reporting stages.

The script follows for quick viewing, and is also attached for download.

@echo off
setlocal enabledelayedexpansion

REM ************************************************************************************************
REM *    File:        capacity-stats.bat
REM *    Location:    X:\NBU-SCRIPTS\capacity-stats\
REM *    Purpose:    To run nbdeployutil twice, once as capacity model, then again as traditional.
REM *
REM *    Vers    Date        Who    Description
REM *    ----    ----        ---    -----------
REM *    v0.01    15-May-2015    sdo    Original version.
REM ************************************************************************************************
REM *    Disclaimer
REM *    ----------
REM *    This script was developed and tested using:
REM *        - Windows 2008 R2 SP1
REM *        - NetBackup Server v7.6.0.4
REM *
REM *    This script is not endorsed, nor has it been tested, by Symantec.  Neither the author, nor
REM *    Symantec, shall accept any liability from any harm, loss, or damage caused by the use
REM *    and/or mis-use of this script, either in its original form, or in a modified form.  Use of
REM *    this script in its original, or modified, form is entirely at the end user's own risk.
REM *    This script is furnished on an example basis only, and may not be suitable for any given
REM *    environment.  
REM ************************************************************************************************
REM *    Sharing
REM *    -------
REM *    This script is free to share and modify, as long as this entire header section is kept with
REM *    the script, and maintained and updated appropriately as any changes are made.
REM ************************************************************************************************
REM *    Notes
REM *    -----
REM *    1) This script is based on an idea by Jon Warfield to combine the process of running a
REM *       gather and then two reports, via nbdeployutil, and to also collect an image list.
REM *       However, this script was completely re-written to detect NetBackup binaries paths
REM *       and to avoid requiring the end user having to enter any details, and to detect the
REM *       the gather output folder path, and to use extensive error handling.
REM *    2) The nbdeployutil does not cope with spaces in the --output=path, nor does it support a
REM *       quote encapsulated path, thus this script must reside in a path which does not use any
REM *       spaces - hence the check for a space in the script location.
REM *    3) The nbdeployutil defaults to 2160 hours (i.e. 90 days), and for consistency, this same
REM *       value is used to create the backup image list, and so a variable 'z_hoursago' is used
REM *       below, to ensure that the bpimagelist and the nbdeployutil gather use the same value.
REM ************************************************************************************************

set z_script_started=!date! !time:~0,8!

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

set z_hoursago=2160


REM ************************************************************************************************
REM ************************************************************************************************
REM ***    Build some file names for use by this script...

set z_file_cap=!z_path!!z_name!.cap
set z_file_gat=!z_path!!z_name!.gat
set z_file_log=!z_path!!z_name!.log
set z_file_tmp=!z_path!!z_name!.tmp
set z_file_trd=!z_path!!z_name!.trd

    if exist "!z_file_cap!"  del "!z_file_cap!"
    if exist "!z_file_gat!"  del "!z_file_gat!"
    if exist "!z_file_log!"  del "!z_file_log!"
    if exist "!z_file_tmp!"  del "!z_file_tmp!"
    if exist "!z_file_trd!"  del "!z_file_trd!"


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

call :log ""
call :log ""
call :log "Script started:   !z_script_started!"
call :log "...hostname:      !computername!"
call :log "...username:      !username!"


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

call :log ""
call :log "Checking script path for spaces..."

(echo !z_path!)>"!z_file_tmp!"

set z_path_has_spaces=n

for /f "tokens=1,2" %%a in ('type "!z_file_tmp!"') do (
  if not "%%b"==""  set z_path_has_spaces=y
)

if "!z_path_has_spaces!"=="n" (
  call :log "...script path does NOT have a space, script continuing..."
) else (
  call :log "...script path has a space, cannot continue..."
  call :log "...place this script in a path location which does not have any spaces, and retry..."
  call :log "...script aborting..."
  goto :end
)

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


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

call :log ""
call :log "Ensuring holding folders exist..."

set z_gather_path=!z_path!gather\
set z_report_path=!z_path!report\

if not exist "!z_gather_path!"  mkdir "!z_gather_path!"
if not exist "!z_report_path!"  mkdir "!z_report_path!"

call :log "...gather path:   !z_gather_path!"
call :log "...report path:   !z_report_path!"
call :log "...done..."


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

call :log ""
call :log "Checking for presence of NetBackup..."

reg query HKLM\Software\Veritas\NetBackup\CurrentVersion\Config /v "client_name" >"!z_file_tmp!" 2>&1
set z_sts=!errorlevel!
if not !z_sts!==0 (
  call :log "...NetBackup does not appear to be installed on this server, script aborting..."
  goto :end
)
for /f "tokens=1,2,3 skip=1" %%a in ('type "!z_file_tmp!"') do (
  set z_client_name=%%c
)

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 "...cannot locate `InstallDir` registry value, script aborting..."
  goto :end
)
for /f "tokens=1,2,* skip=1" %%a in ('type "!z_file_tmp!"') do (
  set z_install_dir=%%c
)

reg query HKLM\Software\Veritas\NetBackup\CurrentVersion /v "Install Type" >"!z_file_tmp!" 2>&1
set z_sts=!errorlevel!
if not !z_sts!==0 (
  call :log "...cannot locate `Install Type` registry value, script aborting..."
  goto :end
)
for /f "tokens=1,2,3,* skip=1" %%a in ('type "!z_file_tmp!"') do (
  set z_install_type=%%d
)
if /i not "!z_install_type!"=="NetBackup Master Server" (
  if /i not "!z_install_type!"=="NetBackup Media Server" (
    if /i not "!z_install_type!"=="NetBackup Administration Console" (
      call :log "...this script cannot be run on NetBackup installation of `!z_install_type!`, script aborting..."
      goto :end
    )
  )
)

set z_netbackup_bin=!z_install_dir!NetBackup\bin
if not exist "!z_netbackup_bin!" (
  call :log "...unable to locate NetBackup binaries folder `!z_netbackup_bin!`, script aborting..."
  goto :end
)

set z_bpclntcmd=!z_netbackup_bin!\bpclntcmd.exe
set z_bpimagelist=!z_netbackup_bin!\admincmd\bpimagelist.exe
set z_nbdeployutil=!z_netbackup_bin!\admincmd\nbdeployutil.exe

if not exist "!z_bpclntcmd!" (
  call :log "...unable to find bpclntcmd at `!z_bpclntcmd!`, script aborting..."
  goto :end
)

if not exist "!z_bpimagelist!" (
  call :log "...unable to find bpimagelist at `!z_bpimagelist!`, script aborting..."
  goto :end
)

if not exist "!z_nbdeployutil!" (
  call :log "...unable to find nbdeployutil at `!z_nbdeployutil!`, script aborting..."
  goto :end
)

call :log "...NetBackup client name:   !z_client_name!"
call :log "...NetBackup type:          !z_install_type!"
call :log "...NetBackup path:          !z_install_dir!"
call :log "...done..."


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

call :log ""
call :log "Determining master server name..."

"!z_bpclntcmd!" -pn >"!z_file_tmp!" 2>&1

set z_sts=!errorlevel!

if not !z_sts!==0 (
  call :log "...call to bpclntcmd failed, status `!z_sts!`, script aborting..."
  goto :end
)

for /f "tokens=1,2,3,4,5" %%a in ('type "!z_file_tmp!"') do (
  if /i "%%a %%b %%c %%d"=="expecting response from server" (
    set z_master=%%e
  )
)

call :log "...master server is:   !z_master!"
call :log "...done..."


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

call :log ""
call :log "Collecting backup image list..."

call :log "...calling bpimagelist..."

"!z_bpimagelist!" -l -hoursago !z_hoursago! >"!z_report_path!\!z_master!-bpimagelist.txt" 2>&1

set z_sts=!errorlevel!

if !z_sts!==227 (
  call :log "...no images were found..."
) else (
  if not !z_sts!==0 (
    call :log "...call to bpimagelist failed, status `!z_sts!`, script aborting..."
    goto :end
  )
)

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


call :log ""
call :log "Calling nbdeployutil gather..."

call :log "...gather path was:  !z_gather_path!"

"!z_nbdeployutil!" --gather --hoursago !z_hoursago! --output=!z_gather_path! >"!z_file_gat!" 2>&1

set z_sts=!errorlevel!

if not !z_sts!==0 (
  call :log "...call to nbdeployutil `gather` failed, status `!z_sts!`, script aborting..."
  goto :end
)

for /f "tokens=1,2,3,4,5,6,7" %%a in ('type "!z_file_gat!"') do (
  if /i "%%a %%b"=="Output for"  set z_gather_path=%%e
)

call :log "...gather path now:  !z_gather_path!"

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


call :log ""
call :log "Calling nbdeployutil report capacity..."

"!z_nbdeployutil!" --report --capacity "!z_gather_path!" --output=!z_report_path! >"!z_file_cap!" 2>&1

set z_sts=!errorlevel!

if not !z_sts!==0 (
  call :log "...call to nbdeployutil `report capacity` failed, status `!z_sts!`, script aborting..."
  goto :end
)

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


call :log ""
call :log "Calling nbdeployutil report traditional..."

"!z_nbdeployutil!" --report --traditional "!z_gather_path!" --output=!z_report_path! >"!z_file_trd!" 2>&1

set z_sts=!errorlevel!

if not !z_sts!==0 (
  call :log "...call to nbdeployutil `report traditional` failed, status `!z_sts!`, script aborting..."
  goto :end
)

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


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

call :log ""
call :log "List of folders:"
call :log "...gather path:   !z_gather_path!"
call :log "...report path:   !z_report_path!"
call :log "...done..."

call :log ""
call :log ""
call :log "*****************************************************************************************"
call :log "The latest files in the 'report path' noted above can be used as input in to a"
call :log "license renewal process."
call :log ""
call :log "N.B: Special care must be taken when working with the output of this script from"
call :log "multiple NetBackup Master Servers, especially if the NetBackup environments utilise"
call :log "NetBackup AIR replication, as this can lead to 'backup foot print' being counted twice,"
call :log "therefore additional steps will very likely be required to adjust the reporting."
call :log "*****************************************************************************************"


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

:end

set z_script_finished=!date! !time:~0,8!

call :log ""
call :log "Script started:     !z_script_started!"
call :log "Script completed:   !z_script_finished!"

echo+
pause
exit /b


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

:log
(echo !date! !time:~0,8!  %~1)
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
goto :eof
Comments
Dollypee
Moderator
Moderator
   VIP    Certified

Hi Sdo,

Great post. But since default is 90days prior, would there be away one can manually imput date range in this script? For example, say 30days ago or between 8/1/2015 - 8/31/2015 ( This is US date format  :)  . something like that.

 

Thanks

Version history
Last update:
‎05-15-2015 09:57 AM
Updated by:
Moderator