Skip to content

Simple Steps to Getting Started with RMAN in Oracle 19c

    RMAN in Oracle 19c supports backing up CDBs and PDBs and performing both complete and point-in-time recovery of entire CDBs or individual PDBs. 

    Setting The Environment

    Update my environment variables to include “NLS_DATE_FORMAT”.  By setting this environment variable, the dates being displayed will be in a more readable format, including the time, not just the date. Add this variable to my Unix account .bash_profile.

    For example, just add the following two lines to the oracle .bash_profile:

    NLS_DATE_FORMAT=”DD/MM/YYYY HH24:MI:SS”
    export NLS_DATE_FORMAT
    

    To give you an idea what effect this parameter has, if I executed a “list backup” command to show known backups, I see the following: Without NLS_DATE_FORMAT:

      List of Archived Logs in backup set 12
      Thrd Seq     Low SCN Low Time  Next SCN Next Time
      ---- ------- ---------- --------- ---------- ---------
      1    21   1406347   19-MAR-20 1585517    15-APR-20
      1    22   1585517   15-APR-20 1587391    15-APR-20
      1    23   1587391   15-APR-20 1587456    15-APR-20
      1    24   1587456   15-APR-20 1588071    15-APR-20
      1    25   1588071   15-APR-20 1588079    15-APR-20

    With NLS_DATE_FORMAT set:

      List of Archived Logs in backup set 12
      Thrd Seq     Low SCN Low Time            Next SCN Next Time
      ---- ------- ---------- ------------------- ---------- ---------
      1    21   1406347   19/03/2020:11:27:14 1585517    15/04/2020:15:26:44
      1    22   1585517   15/04/2020:15:26:44 1587391    15/04/2020:15:37:40
      1    23   1587391   15/04/2020:15:37:40 1587456    15/04/2020:15:39:33
      1    24   1587456   15/04/2020:15:39:33 1588071    15/04/2020:15:44:58
      1    25   1588071   15/04/2020:15:44:58 1588079    15/04/2020:15:44:58
    

    As you can see above, the dates are showing the time as well when this parameter is set. In my scripts, I usually have a small function setting the environment and this is one variable that I always set.

    Default RMAN Configuration

    To see the default values you can execute the “show all” command when connected to your database. Below is an example:

    [[email protected] ~]$ rman
    Recovery Manager: Release 19.0.0.0.0 - Production on Wed Apr 15 15:29:56 2020
    Version 19.6.0.0.0
    Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
    
    RMAN> connect target /
    connected to target database: DEV (DBID=4113794352)
    
    RMAN> show all;
    using target database control file instead of recovery catalog
    RMAN configuration parameters for database with db_unique_name DEV are:
    CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
    CONFIGURE BACKUP OPTIMIZATION OFF;
    CONFIGURE DEFAULT DEVICE TYPE TO DISK;
    CONFIGURE CONTROLFILE AUTOBACKUP ON;
    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';
    CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
    CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
    CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
    CONFIGURE MAXSETSIZE TO UNLIMITED;
    CONFIGURE ENCRYPTION FOR DATABASE OFF;
    CONFIGURE ENCRYPTION ALGORITHM 'AES128';
    CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE;
    CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS;
    CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
    CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/19.0.0/dbhome_1/dbs/snapcf_DEV.f'; # default
    RMAN>
    

    Note: do not just update these values without doing a full review and understanding the implications of altering these values. One of the most important values you might want to specify is to enable auto backup of the controlfile, which by default is set to OFF in earlier database versions, but in 19c it is ON which is perfect. When you update this to ON, RMAN will automatically backup the control file at the end of every backup.

    RMAN> configure controlfile autobackup on;

    Following the above, I update the controlfile autobackup location. As I am using local disk based backups, I am updating the configuration to create the control file backup in my backup location which in my example is: /backups/DEV/.  To do this I execute the following command:

    RMAN> configure controlfile autobackup format for device type disk to '/backups/DEV/%F';

    To configure RMAN to make use of a specific location for my disk based backups, I can update the default channel configuration to include the disk location where the backups should be stored. In my example I am using /backups/DEV as my backup destination. I will update the default RMAN configuration to reflect this:

    RMAN> configure channel device type disk format '/backups/DEV/%U';

    Configuring the use of compressed backup sets when using disk based backups can be done with the following command:

    RMAN> configure device type disk backup type to compressed backupset;

    Once this is done:

    RMAN> show all;
    
    RMAN configuration parameters for database with db_unique_name DEV are:
    CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
    CONFIGURE BACKUP OPTIMIZATION OFF;
    CONFIGURE DEFAULT DEVICE TYPE TO DISK;
    CONFIGURE CONTROLFILE AUTOBACKUP ON;
    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backups/DEV/%F';
    CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1;
    CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
    CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
    CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/backups/DEV/%U';
    CONFIGURE MAXSETSIZE TO UNLIMITED;
    CONFIGURE ENCRYPTION FOR DATABASE OFF;
    CONFIGURE ENCRYPTION ALGORITHM 'AES128';
    CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE;
    CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS;
    CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
    CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/19.0.0/dbhome_1/dbs/snapcf_DEV.f'; # default
    RMAN>
    

    Creating A Backup

    With default configuration as described in place, you can just execute a one-line set of commands to backup the database.

    RMAN> backup database plus archivelog;
    
    Starting backup at 15/04/2020:15:37:40
    current log archived
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=262 device type=DISK
    channel ORA_DISK_1: starting compressed archived log backup set
    channel ORA_DISK_1: specifying archived log(s) in backup set
    input archived log thread=1 sequence=21 RECID=1 STAMP=1037806005
    input archived log thread=1 sequence=22 RECID=2 STAMP=1037806660
    channel ORA_DISK_1: starting piece 1 at 15/04/2020:15:37:41
    channel ORA_DISK_1: finished piece 1 at 15/04/2020:15:37:48
    piece handle=/backups/DEV/02utnb25_1_1 tag=TAG20200415T153741 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
    Finished backup at 15/04/2020:15:37:48
    
    Starting backup at 15/04/2020:15:37:48
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting compressed full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    input datafile file number=00001 name=/u01/app/oracle/oradata/DEV/datafile/o1_mf_system_h754v3kb_.dbf
    input datafile file number=00003 name=/u01/app/oracle/oradata/DEV/datafile/o1_mf_sysaux_h754v8xy_.dbf
    input datafile file number=00005 name=/u01/app/oracle/oradata/DEV/datafile/o1_mf_undotbs1_h754vcpg_.dbf
    input datafile file number=00007 name=/u01/app/oracle/oradata/DEV/datafile/o1_mf_users_h754vwdz_.dbf
    channel ORA_DISK_1: starting piece 1 at 15/04/2020:15:37:48
    channel ORA_DISK_1: finished piece 1 at 15/04/2020:15:38:33
    piece handle=/backups/DEV/03utnb2c_1_1 tag=TAG20200415T153748 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
    channel ORA_DISK_1: starting compressed full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    input datafile file number=00010 name=/u01/app/oracle/oradata/DEV/A129A5525C601CCFE053020011AC6470/datafile/o1_mf_undotbs1_h758gd4m_.dbf
    input datafile file number=00008 name=/u01/app/oracle/oradata/DEV/A129A5525C601CCFE053020011AC6470/datafile/o1_mf_system_h758gd48_.dbf
    input datafile file number=00009 name=/u01/app/oracle/oradata/DEV/A129A5525C601CCFE053020011AC6470/datafile/o1_mf_sysaux_h758gd4l_.dbf
    input datafile file number=00011 name=/u01/app/oracle/oradata/DEV/A129A5525C601CCFE053020011AC6470/datafile/o1_mf_users_h758gr5q_.dbf
    channel ORA_DISK_1: starting piece 1 at 15/04/2020:15:38:33
    channel ORA_DISK_1: finished piece 1 at 15/04/2020:15:38:58
    piece handle=/backups/DEV/04utnb3p_1_1 tag=TAG20200415T153748 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
    channel ORA_DISK_1: starting compressed full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    input datafile file number=00006 name=/u01/app/oracle/oradata/DEV/A128C9760B650223E053020011AC71F3/datafile/o1_mf_undotbs1_h754vdc8_.dbf
    input datafile file number=00002 name=/u01/app/oracle/oradata/DEV/A128C9760B650223E053020011AC71F3/datafile/o1_mf_system_h754v5vh_.dbf
    input datafile file number=00004 name=/u01/app/oracle/oradata/DEV/A128C9760B650223E053020011AC71F3/datafile/o1_mf_sysaux_h754vbmt_.dbf
    channel ORA_DISK_1: starting piece 1 at 15/04/2020:15:38:58
    channel ORA_DISK_1: finished piece 1 at 15/04/2020:15:39:33
    piece handle=/backups/DEV/05utnb4i_1_1 tag=TAG20200415T153748 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
    Finished backup at 15/04/2020:15:39:33
    Starting backup at 15/04/2020:15:39:33
    current log archived
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting compressed archived log backup set
    channel ORA_DISK_1: specifying archived log(s) in backup set
    input archived log thread=1 sequence=23 RECID=3 STAMP=1037806773
    channel ORA_DISK_1: starting piece 1 at 15/04/2020:15:39:34
    channel ORA_DISK_1: finished piece 1 at 15/04/2020:15:39:35
    piece handle=/backups/DEV/06utnb5m_1_1 tag=TAG20200415T153934 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    Finished backup at 15/04/2020:15:39:35
    Starting Control File and SPFILE Autobackup at 15/04/2020:15:39:35
    piece handle=/backups/DEV/c-4113794352-20200415-01 comment=NONE
    Finished Control File and SPFILE Autobackup at 15/04/2020:15:39:36
    RMAN>

    Now let’s look at the size of the backups:

    [[email protected] ~]$ ls -l /backups/DEV/
    total 802540
    -rw-r----- 1 oracle oinstall  43122176 Apr 15 15:37 02utnb25_1_1
    -rw-r----- 1 oracle oinstall 368041984 Apr 15 15:38 03utnb2c_1_1
    -rw-r----- 1 oracle oinstall 204496896 Apr 15 15:38 04utnb3p_1_1
    -rw-r----- 1 oracle oinstall 205004800 Apr 15 15:39 05utnb4i_1_1
    -rw-r----- 1 oracle oinstall     12800 Apr 15 15:39 06utnb5m_1_1
    -rw-r----- 1 oracle oinstall   1114112 Apr 15 15:39 c-4113794352-20200415-01

    A quick and easy script, taking into account the default values set as above:

    RMAN> run {
               backup database filesperset 5;
               sql 'alter system archive log current';
               backup archivelog all filesperset 50;
        }

    If you did not configure the default RMAN Config values, you can achieve similar results by running the following backup script:

    RMAN> run {
     backup as compressed backupset filesperset 5 database format '/backups/DEV/dbf-%U';
     sql 'alter system archive log current';
     backup as compressed backupset filesperset 50 archivelog all format '/backups/DEV/arc-%U';
     backup current controlfile format '/backups/DEV/cf-%U';
    }

    Some useful tips:

    • I recommend that if you are not using a recovery catalog when doing RMAN backups to increase the database parameter controlfile_record_keep_time from the default value of 7 (days) to a higher value. For example, 30 is a good starting point.
    • For Oracle 11g RAC environments if you are getting an ORA-00245 error when backing up the controlfile, you have to update the default configuration of RMAN to place the snapshot controlfile on shared storage.
    RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO '<shared_disk>/snapcf_<DBNAME>.f';

    Also See:

    Oracle RMAN

    RMAN Changes in Oracle 19c