oracledba.help
RMAN

Maintenance Tasks

Run RMAN Console

$ORACLE_HOME/bin/rman target sys/MyPassword nocatalog

Most common commands:
RMAN> CONFIGURE <parameter> TO <NewValue>;
RMAN> SHOW ALL;
RMAN> @MyScript.rmn
RMAN> @MyScript.rmn debug trace=/tmp/rman/rman.trc

Block Change Tracking

-- Display

SELECT * FROM v$block_change_tracking;

-- Enable

ALTER DATABASE ENABLE BLOCK CHANGE TRACKING
USING FILE 'R:\rman\Blk_Chg_Trk.dat';

-- Disable

ALTER DATABASE disable BLOCK CHANGE TRACKING;

Compression

To configure RMAN to use compression you can use:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;

To configure the different backup algorithms:

CONFIGURE COMPRESSION ALGORITHM '<NONE|BASIC|LOW|MEDIUM|HIGH>';

CONFIGURE COMPRESSION ALGORITHM 'MEDIUM';

Compression Ratio

You can use below query to determine the compression ratio:

COL redid  FORMAT 999999
COL status FORMAT a15
prompt 
prompt +-------------------------+
prompt | RMAN Compression Status |
prompt +-------------------------+
SELECT * FROM
   (
   SELECT recid,
          status,
          round(input_bytes/(1024*1024*1024),2) Read_GB,
          round(output_bytes/(1024*1024*1024),2) Write_GB,
          round(input_bytes/output_bytes,3) Compression_ratio,
          to_char(start_time, 'YYYY-MON-DD HH24:MI:SS') Started
   FROM v$rman_status 
   WHERE operation='BACKUP' 
   AND  output_bytes!=0 
   ORDER BY START_TIME DESC
   )
WHERE rownum <= 25;

Crosscheck and Delete

To ensure that you only have the files on disk that are required to meet your backup policy and conserve disk space.

Traditional Backups

RMAN> CROSSCHECK BACKUP;
RMAN> CROSSCHECK ARCHIVELOG ALL;
RMAN> DELETE FORCE NOPROMPT OBSOLETE;

Incremental Merge Backups

Incremental Merge Backups are generally self maintaining. This may be needed if files are restored from tape to disk before a restore.

RMAN> CROSSCHECK COPY;
RMAN> CROSSCHECK ARCHIVELOG ALL;

Display

Backups

RMAN> list backup;
RMAN> list copy;

Settings

RMAN> show all;

Exclude

Exclude Tablespace

Be careful not to exclude a tablespace that is a DEFAULT TABLESPACE for a schema.
Disable\Clear

RMAN> CONFIGURE EXCLUDE FOR TABLESPACE "X15" CLEAR;

Enable

RMAN> CONFIGURE EXCLUDE FOR TABLESPACE "X15";

Recovery Handling (you must SKIP during recover phase)

RMAN> shutdown abort;
RMAN> startup mount;
RMAN> restore database;
RMAN> recover database SKIP TABLESPACE "X15";
RMAN> alter database open;

-- For multiple tablespaces you can do this:
RMAN> recover database SKIP TABLESPACE "X15","X16";

Show RMAN> SHOW EXCLUDE;

Kill RMAN Backup

Method 1: From Oracle

Get SID and SERIAL#

 SELECT sid, serial#, context, sofar, totalwork,
 ROUND (sofar/totalwork*100, 2) "% Complete"
 FROM V$SESSION_LONGOPS
 WHERE opname LIKE 'RMAN%' AND opname NOT LIKE ''
 AND totalwork != 0 AND sofar <> totalwork;

        SID    SERIAL#    CONTEXT      SOFAR  TOTALWORK % COMPLETE
 ---------- ---------- ---------- ---------- ---------- ----------
       1571      37913          1   34148488  123385088      27.68
        295      41764          1   29391033   44320384      66.31
          7      41529          1   28383963  106530816      26.64

Kill Instances

 SQL> alter system kill session '1571,37913' immediate;
 SQL> alter system kill session '295,41764' immediate;
 SQL> alter system kill session '7,41529' immediate;

Method 2: From OS

 ps -ef | grep rman|grep -v grep
 oracle    9841  9836  0 09:15 ? 00:00:00 /bin/sh -c $SCRIPTS/rmanctl.sh oradb1 > $OUT/rmanctl.out 2>&1 
 oracle    9845  9841  0 09:15 ? 00:00:00 /bin/bash /u01/app/scripts/rmanctl.sh oradb1 
 oracle   10173  9845  0 09:15 ? 00:00:01 rman app/oracle/product/12.1.0.2/dbhome_1/bin/rman target / nocatal 

 kill -9 9841
 kill -9 9845
 kill -9 10173

Purge

You can purge all records out of your control file using the appropriate command below.

Incremental Merge Backup Files/Records

RMAN> CROSSCHECK COPY;
RMAN> DELETE COPY;
      Answer Y to prompt to delete all the records.

Backup Files/Records

RMAN> CROSSCHECK BACKUP;
RMAN> DELETE BACKUPSET;
      Answer Y to prompt to delete all the records.

Purge Just Disk or Tape (SBT) RMAN Files/Records

Do this by specifying device type then issuing the DELETE command.
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE <Disk|SBT_TAPE>;
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt_tape;
RMAN> DELETE FORCE NOPROMPT BACKUP;

Reset RMAN Configuration

The following command resets all the RMAN parameters back to their default values. SQL> execute dbms_backup_restore.resetConfig;

Select Parameters

configure <parameter> clear;

 configure SNAPSHOT CONTROLFILE NAME clear;
 show all; 
 CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/12.1.0.2/dbhome_1/dbs/snapcf_dnat1.f'; #default

Validate

RMAN> run {restore database validate;}

<- RMAN