@@header
set term off
/*
*
*  Author     : Vishal Gupta
*  Purpose    : Display RMAN backup size from catalog
*  Parameters : 1 - Database Name
*               2 - Device type (Disk, tape)
*               3 - No of days of history.
*
*  Revision History:
*  ===================
*  Date       Author        Description
*  ---------  ------------  -----------------------------------------
*  23-Jun-08  Vishal Gupta  First Draft
*/
set term on

TTITLE LEFT "R M A N    B A C K U P    S I Z E S"  
PROMPT

DEFINE database_name=%="&&1"%
DEFINE output_device_type=%&2%
DEFINE days="&&3"


DEFINE star=4
COLUMN UsageGraphWidth NOPRINT old_value UGWidth
SET FEED OFF
SELECT (100/&star+2) UsageGraphWidth
FROM   DUAL;
SET FEED ON




COLUMN start_Time         FORMAT a9
COLUMN output_device_Type FORMAT a8           HEADING "Media"
COLUMN input_mb_sum       FORMAT 9,999,999.99 HEADING "Input|(MB)"
COLUMN output_mb_sum      FORMAT 9,999,999.99 HEADING "Output|(MB)"
COLUMN percent_compress   FORMAT 990.99       HEADING "Compression (%)"
COLUMN input_graph        FORMAT a27          HEADING "Input Graph"
COLUMN output_graph       FORMAT a27          HEADING "Output Graph"



SELECT a.db_name
     , a.start_time
     , a.output_device_type
     , a.input_mb_sum
     , a.output_mb_sum
     , '|' || RPAD(LPAD(' ',CEIL( (a.input_mb_sum *100 /  a.input_output_mb_sum_max  ) /&star) ,'*'),100/&star) || '|'  input_graph
     , '|' || RPAD(LPAD(' ',CEIL( (a.output_mb_sum *100 /  a.input_output_mb_sum_max  ) /&star) ,'*'),100/&star) || '|'  output_graph
FROM
(
SELECT s.db_name
     , To_char(TRUNC(s.start_time),'DD-MON-YY') start_time
     , s.output_device_type
     , ROUND(sum(s.input_bytes)/1024/1024,2) input_mb_sum
     , ROUND(sum(s.output_bytes)/1024/1024,2) output_mb_sum
     , ROUND( (sum(s.input_bytes) - sum(s.output_bytes)) * 100 / sum(s.input_bytes),2)  percent_compress
     , max(input_output_mb_sum_max) input_output_mb_sum_max
  FROM rc_rman_status s
     , (SELECT GREATEST(MAX(ROUND(sum(input_bytes)/1024/1024,2))
                      , MAX(ROUND(sum(output_bytes)/1024/1024,2)) 
                       ) input_output_mb_sum_max
         FROM rc_rman_status 
        WHERE output_device_type IS NOT NULL -- ignore connection entries
          AND db_name like UPPER('&&database_name')
          AND output_device_type like UPPER('&&output_device_type')
          AND start_time > sysdate - &days
        GROUP by db_name
               , TRUNC(start_time)
               , output_device_type
        ) m
 WHERE s.output_device_type IS NOT NULL -- ignore connection entries
   AND s.db_name like UPPER('&&database_name')
   AND s.output_device_type like UPPER('&&output_device_type')
   AND s.start_time > sysdate - &days
 GROUP by s.db_name
        , TRUNC(s.start_time)
        , s.output_device_type
ORDER BY db_name
        , TRUNC(s.start_time)
        , s.output_device_type
) a
ORDER BY A.START_TIME 
;

@@footer
