@@header

set term off
/*
*
*  Author  : Vishal Gupta
*  Purpose : Display RMAN Backup size for a database
*  Arguments : 1 - Database name
* 
*  Revision History:
*  ===================
*  Date       Author        Description
*  ---------  ------------  -----------------------------------------
*  01-Aug-08  Vishal Gupta  First Draft
*/
set term on

DEFINE database="%&&1%" 


COLUMN dbid                         HEADING "DB Id"              FORMAT 9999999999
COLUMN resetlogs_time               HEADING "ResetLogs Time"     FORMAT a18
COLUMN sum_mb_of_disk_control_file  HEADING "Disk|Control|(MB)"  FORMAT 99,999
COLUMN sum_mb_of_disk_arch          HEADING "Disk|Arch|(MB)"     FORMAT 99,999,999 
COLUMN sum_mb_of_disk_full          HEADING "Disk|Full|(MB)"     FORMAT 99,999,999
COLUMN sum_mb_of_disk_IncLevel1     HEADING "Disk|Inc 1|(MB)"    FORMAT 99,999,999        
COLUMN sum_mb_of_disk_IncLevel2     HEADING "Disk|Inc 2|(MB)"    FORMAT 99,999,999
COLUMN sum_mb_of_disk_others        HEADING "Disk|Others|(MB)"   FORMAT 999,999 JUSTIFY RIGHT
COLUMN sum_mb_of_disk_total         HEADING "Disk|Total|(MB)"    FORMAT 99,999,999

COLUMN sum_mb_of_tape_control_file  HEADING "Tape|Control|(MB)"  FORMAT 999,999
COLUMN sum_mb_of_tape_arch          HEADING "Tape|Arch|(MB)"     FORMAT 99,999,999
COLUMN sum_mb_of_tape_full          HEADING "Tape|Full|(MB)"     FORMAT 99,999,999  
COLUMN sum_mb_of_tape_IncLevel1     HEADING "Tape|Inc 1|(MB)"    FORMAT 99,999,999      
COLUMN sum_mb_of_tape_IncLevel2     HEADING "Tape|Inc 2|(MB)"    FORMAT 99,999,999
COLUMN sum_mb_of_tape_others        HEADING "Tape|Others|(MB)"   FORMAT 999,999
COLUMN sum_mb_of_tape_total         HEADING "Tape|Total|(MB)"    FORMAT 99,999,999



BREAK ON REPORT

COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_control_file   FORMAT 9,999         ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_arch           FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_full           FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_IncLevel1      FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_IncLevel2      FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_others         FORMAT 999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_disk_total          FORMAT 9,999,999,999    ON REPORT


COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_control_file   FORMAT 99,999        ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_arch           FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_full           FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_IncLevel1      FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_IncLevel2      FORMAT 99,999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_others         FORMAT 999,999    ON REPORT
COMPUTE SUM LABEL 'Total'   OF sum_mb_of_tape_total          FORMAT 9,999,999,999    ON REPORT


SELECT a.name
     , a.dbid
--     , a.resetlogs_time
     , ROUND(SUM(DECODE(a.device_type, 'DISK', DECODE(a.backup_type,'ControlFile' ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_disk_control_file
     , ROUND(SUM(DECODE(a.device_type, 'DISK', DECODE(a.backup_type,'Arch'        ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_disk_arch
     , ROUND(SUM(DECODE(a.device_type, 'DISK', DECODE(a.backup_type,'Full'        ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_disk_full
     , ROUND(SUM(DECODE(a.device_type, 'DISK', DECODE(a.backup_type,'IncLevel1'   ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_disk_IncLevel1
     , ROUND(SUM(DECODE(a.device_type, 'DISK', DECODE(a.backup_type,'IncLevel2'   ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_disk_IncLevel2
     , ROUND(SUM(CASE WHEN (device_type = 'DISK'  AND backup_type IN ('ControlFile','Arch','Full','IncLevel1','IncLevel2') ) THEN 0
                      WHEN device_type = 'SBT_TAPE' THEN 0
                      ELSE a.bytes                                                    
                 END)/1024/1024)  sum_mb_of_disk_others
     , ROUND(SUM(CASE WHEN (device_type = 'DISK') THEN a.bytes
                      ELSE 0                                                    
                 END)/1024/1024)  sum_mb_of_disk_total
     , ROUND(SUM(DECODE(a.device_type, 'SBT_TAPE', DECODE(a.backup_type,'ControlFile' ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_tape_control_file
     , ROUND(SUM(DECODE(a.device_type, 'SBT_TAPE', DECODE(a.backup_type,'Arch'        ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_tape_arch
     , ROUND(SUM(DECODE(a.device_type, 'SBT_TAPE', DECODE(a.backup_type,'Full'        ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_tape_full
     , ROUND(SUM(DECODE(a.device_type, 'SBT_TAPE', DECODE(a.backup_type,'IncLevel1'   ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_tape_IncLevel1
     , ROUND(SUM(DECODE(a.device_type, 'SBT_TAPE', DECODE(a.backup_type,'IncLevel2'   ,a.bytes,0)  ,0) )/1024/1024) sum_mb_of_tape_IncLevel2
     , ROUND(SUM(CASE WHEN (device_type = 'SBT_TAPE' AND backup_type IN ('ControlFile','Arch','Full','IncLevel1','IncLevel2') ) THEN 0
                      WHEN device_type = 'DISK' THEN 0
                      ELSE a.bytes                                                    
                 END)/1024/1024)  sum_mb_of_tape_others
     , ROUND(SUM(CASE WHEN (device_type = 'SBT_TAPE') THEN a.bytes
                 ELSE 0                                                    
                 END)/1024/1024)  sum_mb_of_tape_total
FROM  (SELECT d.NAME
           , d.dbid
           , d.resetlogs_time
           , bp.START_TIME
           , bp.device_type
           , DECODE(bp.backup_type
                     ,'L','Arch'
                     ,'D', DECODE(NVL(bp.incremental_level,-1)
                                   ,0,'Full'
                                   ,-1,'ControlFile'
                                   ,bp.incremental_level 
                                 )
                     ,'I', DECODE(bp.incremental_level                                   
                                   ,0,'Full'
                                   ,'IncLevel' ||bp.incremental_level 
                                 )
                     ,bp.backup_type
                    ) backup_type
           , bp.bytes
           , bp.incremental_level
      FROM rc_backup_piece bp
         , rc_database d
     WHERE d.db_key = bp.db_key 
       AND d.name like '&database'
) a
group by a.NAME, a.dbid, a.resetlogs_time
ORDER BY a.NAME, a.resetlogs_time;


@@footer

