RMAN intro

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

 

Schedule backup via cron

5  *  *  *  * /home/oracle/scripts/remove_arch_logs.sh

* * * * * command to be executed
 - - - - -
 | | | | |
 | | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
 | | | ------- Month (1 - 12)
 | | --------- Day of month (1 - 31)
 | ----------- Hour (0 - 23)
 ------------- Minute (0 - 59)

/etc/cron.d/       /etc/cron.*/       /var/spool/cron/

Show cron tasks

crontab -l

Edit cron tasks

crontab -e

 

Show backup list

RMAN> rman target /
RMAN> list backup of database summary;

Key - unique ID key 
 TY - type of the backup: backup set (B) or copy (P).
 LV - F - file; A - Archivelogs.
 S - backup status: A (available), U (unavailable), or X (all backup pieces in set expired). Refer to the CHANGE, CROSSCHECK, and DELETE commands for an explanation of each status

Set all backups as obsolete, excluding the last one

RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 1;

Ask RMAN to delete all old (obsolete) backups without confirmation

RMAN> delete noprompt obsolete;
RMAN> list backup of database summary;

Show schema report for database

RMAN> report schema;

Hot backup

$ mkdir -p /u02/oracle/oradata/${ORACLE_SID}/scripts
$ cd /u02/oracle/oradata/${ORACLE_SID}/scripts
$ vi rmanscript.rman
RUN {
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;
BACKUP FULL DATABASE TAG "FULL_DATABASE" PLUS ARCHIVELOG TAG "FULL_DATABASE_ARCHIVELOGS";
}

Check syntax of the created script file

$ rman CHECKSYNTAX @rmanscript.rman

Run backup script

$ rman target / @rmanscript.rman

 

RMAN BACKUP SCRIPT TO THE FRA. Example 1

Note: The database in the ARCHIVELOG mode

$ mkdir -p $ORACLE_HOME/scripts
$ cd $ORACLE_HOME/scripts
$ cd /u02/oracle/oradata/${ORACLE_SID}/scripts
$ vi backup-rman-script.rman
RUN {
ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;
BACKUP FULL DATABASE TAG "FULL_DATABASE_DATAFILES";
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL TAG "FULL_DATABASE_ARCHIVELOGS";
BACKUP CURRENT CONTROLFILE TAG "FULL_DATABASE_CONTROLFILE";
BACKUP SPFILE TAG "FULL_DATABASE_SPFILE";
DELETE NOPROMPT OBSOLETE;
CONFIGURE RETENTION POLICY CLEAR;
CONFIGURE BACKUP OPTIMIZATION CLEAR;
CONFIGURE DEVICE TYPE DISK CLEAR;
RELEASE CHANNEL c1;
}

Check syntax of the created script file

$ rman CHECKSYNTAX @backup-rman-script.rman

To run backup script

$ rman target / @backup-rman-script.rman

If Oracle Catalog is using, the command may look like this

$ rman target / catalog rman/rman123@rman12 @backup-rman-script.rman
RMAN> LIST BACKUPSET TAG="FULL_DATABASE_DATAFILES";
RMAN> LIST BACKUP SUMMARY;
RMAN> list backupset summary;

 

RMAN BACKUP SCRIPT TO THE CATALOG. Example 2 

Oracle 12c works in the ARCHIVELOG mode

$ mkdir -p /tmp/backups/ORCL12/{DATAFILE,ARCHIVELOG,CONTROLFILE,PARAMETERFILE}
$ mkdir -p $ORACLE_HOME/scripts
$ cd $ORACLE_HOME/scripts
$ vi backup-to-folder-rman-script.rman
RUN {
ALLOCATE CHANNEL c1 DEVICE TYPE DISK;
BACKUP AS COMPRESSED BACKUPSET FULL DATABASE TAG "FULL_DATABASE_DATAFILES" FORMAT '/tmp/backups/ORCL12/DATAFILE/bkp_%D_%T_%s_%p_DATA';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL FORMAT '/tmp/backups/ORCL12/ARCHIVELOG/bkp_%D_%T_%s_%p_ARCHIVELOG' TAG "FULL_DATABASE_ARCHIVELOGS";
BACKUP SPFILE FORMAT '/tmp/backups/ORCL12/PARAMETERFILE/bkp_%D_%T_%s_%p_PARAM' TAG "FULL_DATABASE_SPFILE";
SQL 'CREATE PFILE = /tmp/backups/ORCL12/PARAMETERFILE/pfile.txt from SPFILE';
BACKUP CURRENT CONTROLFILE FORMAT '/tmp/backups/ORCL12/CONTROLFILE/bkp_%D_%T_%s_%p_CONTROL' TAG "FULL_DATABASE_CONTROLFILE";
SQL 'ALTER DATABASE BACKUP CONTROLFILE TO TRACE as /tmp/backups/ORCL12/CONTROLFILE/controlfile.txt';
RELEASE CHANNEL c1;
}

%t = 4 bytes time stamp
%s = backup set number
%p = backup piece number
 

Check syntax of the created script file

$ rman CHECKSYNTAX @$ORACLE_HOME/scripts/backup-to-folder-rman-script.rman

 To run backup script

$ rman target / @$ORACLE_HOME/scripts/backup-to-folder-rman-script.rman

To check max sequence

SQL> select max(sequence#) from v$archived_log;	MAX(SEQUENCE#)
	--------------
	      35

 To check max sequence of RAC nodes

SQL> select thread#, max(sequence#) from v$log group by thread# order by thread#;	THREAD# MAX(SEQUENCE#)
	---------- --------------
	1     5891
	2     5854
	3     6009
	4     6206
	5     5875
	6     5857
$ cd /tmp/backups/
$ tar -cvzpf ORCL12.tar.gz ./ORCL12

CREATE INCREMENTAL COPY OF THE DATABASE USING RMAN

RMAN>
RUN { CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET; BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG TAG "LEVEL 0"; BACKUP CURRENT CONTROLFILE SPFILE; } BACKUP INCREMENTAL LEVEL 1 DATABASE PLUS ARCHIVELOG TAG "LEVEL 1";

CREATE CUMULATIVE (including changes in the incremental backups) BACKUP WITH LEVEL 1

RMAN> backup incremental level 1 cumulative database;

Reset database to incarnation 3

You use RESTORE or RECOVER to return the database to an SCN before the current RESETLOGS timestamp
You use FLASHBACK DATABASE to rewind the database to an orphaned database incarnation

Warning, danger! Read manual before run it

RMAN> reset database to incarnation 3;

Newsletter

Enter your email to join our mailing list

Quick Contact