RMAN is a backup and recovery manager supplied for Oracle databases created by the Oracle Corporation. It provides database backup, restores, and recovery capabilities addressing high availability and disaster recovery concerns. RMAN can also help in-migration from on-prem to cloud.
Below are some of the basic RMAN commands, useful for daily usage.
Index
RMAN show all Command
RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ELPISYS are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/d01/oracle/product/v.19.13.0.0/dbs/snapcf_ELPISYS.f'; # default
Delete expired archive logs
RMAN> crosscheck archivelog all;
RMAN> delete noprompt expired archivelog all;
Delete archive logs keeping n no of days archive logs
run{
allocate channel C1 type disk;
delete noprompt archivelog until time 'SYSDATE-n'; (n should be replaced by an integer, for which days you want to retain the archive logs)
release channel C1;
}
RMAN backup using SCN
connect target /
BACKUP DEVICE TYPE DISK INCREMENTAL FROM SCN 1828103625 DATABASE FORMAT '/RMAN/backup/bkup_%U';
Restore archive logs from sequence
run
{
ALLOCATE CHANNEL c1 DEVICE TYPE SBT_TAPE PARMS 'ENV=(NB_ORA_POLICY=,NB_ORA_CLIENT=),BLKSIZE=524288';
SET ARCHIVELOG DESTINATION TO '/RMAN/arch';
restore archivelog from logseq=196735 until logseq=196749 thread=1;
}
Note – NB_ORA_POLICY and NB_ORA_CLIENT are environment-specific details that you can get from the configuration files.
Query to check RMAN job details
set line 200
set pages 2000
col start_time for a25
col end_time for a25
col status for a30
select SESSION_KEY, INPUT_TYPE, STATUS, to_char(START_TIME,'mm/dd/yy hh24:mi') start_time, to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,elapsed_seconds/3600 hrs from V$RMAN_BACKUP_JOB_DETAILS order by session_key;
Views: 186