rman commands with examples

rman commands with examples | In this post, we will discuss Important RMAN commands for Oracle database. We are using these rman commands to manage the Oracle Database. Below is the various RMAN commands list that will help it more for daily dba jobs.

rman commands
RMAN commands

Some rman commands with examples

Below are some rman commands which will help to manage Backup and Recovery.

SHOW COMMAND.

 
1) Shows all configurations.
 
RMAN> show all;
 
 
2) Show retention policy for db_unique_name.
 
RMAN> SHOW RETENTION POLICY FOR DB_UNIQUE_NAME ALL;
3) Shows the current retention policy for rman backup.
 
RMAN> show retention policy;
 
4) Shows the current snapshot control filename and configuration.
 
RMAN> show snapshot controlfile name;
 
 
5) Shows the archivelog deletion policy.
 
RMAN> show archivelog deletion policy;
 
6) Shows the number of archivelog backup copies
 
RMAN> show archivelog backup copies;
 
7) Shows the auxiliary database.
 
RMAN> show auxname;
 
8) Shows whether optimization is enable.
 
RMAN> show backup optimization;
 
9) Shows how the which channel are configured.
 
RMAN> show channel;
 
10) Shows the characteristics of the channel.
 
RMAN> show channel for device type [disk | <media device>;
 
11) Shows control file autobackup is on or off.
 
RMAN> show controlfile autobackup;
 
12) Shows the format of the autobackup control file.
 
RMAN> show controlfile autobackup format;
 
13) Shows the number of datafile backup copies.
 
RMAN> show datafile backup copies;
 
14) Shows the default type (disk or tape).
 
RMAN> show default device type;
 
 
15) Shows the encryption algorithm currently in use.
 
RMAN> show encryption algorithm;
 
16) Shows the encryption for the database and  tablespace.
 
RMAN> show encryption for [database | tablespace];
 
17) Shows the database objects excluded from the backup.
 
RMAN> show exclude;
 
18) Shows the maximum size for backup sets.
 
RMAN> show maxsetsize;
 
19) Shows the compression algorithm.
 
RMAN> show compression algorithm;
 
20) Shows the Device type configuration.
 
RMAN> SHOW DEVICE TYPE;
21) Show Default Device Type configuration.
 
RMAN> SHOW DEFAULT DEVICE TYPE;
 
 

Best BACKUP COMMAND In Oracle.

 

Backup Database command.

 
 
1)To Backup complete database.
 
RMAN> BACKUP DATABASE;
 
2) To Backup database with TAG.
 
RMAN> BACKUP DATABASE TAG=’test backup’;
 
3) To Backup complete database with comment.
 
RMAN> BACKUP DATABASE COMMENT=’full backup’;
 
4) To Backup complete database with backup piece size 10M.
 
RMAN> BACKUP TAG ‘weekly_full_db_bkup’ DATABASE MAXSETSIZE 10M;
 
5) To Backup completed database with max backup piece as 500M plus archivelog.
 
RMAN> BACKUP MAXSETSIZE 500M DATABASE PLUS ARCHIVELOG;
 
6)To restrict rman backup session time as 60,30 and 45 minutes accordingly.
 
RMAN> BACKUP DURATION 00:60 DATABASE;
RMAN> BACKUP DURATION 00:30 MINIMIZE TIME DATABASE;
RMAN> BACKUP DURATION 00:45 MINIMIZE LOAD DATABASE;
 
7) To Backup the complete database plus archivelog.

RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
 
8) To Keep Backup retention forever.  Backup will never be obsolete .
 
RMAN> BACKUP DATABASE KEEP FOREVER;
RMAN> BACKUP DATABASE KEEP UNTIL TIME=’SYSDATE+30’;
RMAN> BACKUP DATABASE UNTIL ‘SYSDATE+365’ NOLOGS;
 
9) To exclude the database object while running rman backup.
 
RMAN> BACKUP DATABASE NOEXCLUDE;
RMAN> BACKUP DATABASE NOEXCLUDE KEEP FOREVER TAG=’abc’;
 
10) To skip the read only object , offline and inaccessible.
 
 
RMAN> BACKUP DATABASE SKIP READONLY;

RMAN> BACKUP DATABASE SKIP OFFLINE;

RMAN> BACKUP DATABASE SKIP INACCESSIBLE;

RMAN> BACKUP DATABASE SKIP READONLY SKIP OFFLINE SKIP INACCESSIBLE;
 
11) To Backup read only database object forcefully.
 
RMAN> BACKUP DATABASE FORCE; — backup read only database also
 
 
12) To Backup those object that still not backuped up.
 
RMAN> BACKUP DATABASE NOT BACKED UP;

RMAN> BACKUP DATABASE NOT BACKED UP SINCE TIME=’SYSDATE–3’;

RMAN> BACKUP NOT BACKED UP SINCE TIME ‘SYSDATE-10’ 
MAXSETSIZE 500M DATABASE PLUS ARCHIVELOG;
 
13) To backup entire database having two copies.

RMAN> BACKUP DATABASE COPIES=2;
 
14) To backup database with specific format.
 
RMAN> BACKUP DATABASE FORMAT ‘/backups/db_%U.bkp’
TAG quarterly KEEP UNTIL TIME ‘SYSDATE+365’ RESTORE POINT Q1FY12;
 

 

Backup DEVICE Commands: –

 
15) To Backup database in Disk and Backup media like tape Drive.
 
RMAN> BACKUP DEVICE TYPE DISK DATABASE;

RMAN> BACKUP DEVICE TYPE sbt DATABASE PLUS ARCHIVELOG;

RMAN> BACKUP DEVICE TYPE sbt DATAFILECOPY FROM TAG ‘latest’ FORMAT ‘df%f_%d’;

RMAN> BACKUP DEVICE TYPE sbt ARCHIVELOG LIKE ‘/disk%arc%’ DELETE ALL INPUT;

RMAN> BACKUP DEVICE TYPE sbt BACKUPSET COMPLETED BEFORE ‘SYSDATE-14’DELETE INPUT;
 
 
 
 
16)To check the datafiles for any physical or logical corruption. These commands isnot doing backup but checking the database for corruption.

RMAN> BACKUP CHECK LOGICAL DATABASE;
RMAN> BACKUP VALIDATE CHECK LOGICAL DATABASE;
RMAN> BACKUP VALIDATE DATABASE;
RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;
 
17) To Backup tablespace.

RMAN> BACKUP TABLESPACE test;

RMAN> BACKUP TABLESPACE system, users, tools;
RMAN> BACKUP TABLESPACE 4;
RMAN> BACKUP TABLESPACE gld PLUS ARCHIVELOG;
RMAN> BACKUP TABLESPACE invd INCLUDE CURRENT CONTROLFILE;
RMAN> BACKUP TABLESPACE appsd INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG;
RMAN> BACKUP TABLESPACE dwh SECTION SIZE 100M;
RMAN> BACKUP SECTION SIZE 250M TABLESPACE datamart;
 
18) To Backup datafile.

RMAN> BACKUP DATAFILE 1;

RMAN> BACKUP DATAFILE 3, 2, 14;
RMAN> BACKUP DATAFILE ‘/u01/data/…’;
RMAN> BACKUP DATAFILE 1 PLUS ARCHIVELOG;
RMAN> BACKUP KEEP FOREVER FORMAT ‘?/dbs/%U_longterm.cpy’ TAG longterm_bck DATAFILE 1 DATAFILE 2;
RMAN> BACKUP SECTION SIZE 500M DATAFILE 6;

19) To Backup archivelog.
 
RMAN> BACKUP ARCHIVELOG ALL;
RMAN> BACKUP ARCHIVELOG ALL DELETE INPUT;
RMAN> BACKUP ARCHIVELOG LIKE ‘/arch%’ DELETE ALL INPUT;
RMAN> BACKUP ARCHIVELOG FROM TIME ‘SYSDATE–3’;
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 100;
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 999 DELETE INPUT;
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 123 DELETE ALL INPUT;
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 21531 UNTIL SEQUENCE 21590 FORMAT ‘/tmp/archive_backup.bkp’;
RMAN> BACKUP ARCHIVELOG ALL FROM SEQUENCE 1200 DELETE ALL INPUT;
RMAN> BACKUP ARCHIVELOG NOT BACKED UP 2 TIMES;
RMAN> BACKUP ARCHIVELOG COMPLETION TIME BETWEEN ‘SYSDATE-28’ AND ‘SYSDATE-7’;
RMAN> BACKUP FORMAT=’AL_%d/%t/%s/%p’ ARCHIVELOG LIKE ‘%arc_dest%’;

20)To Backup control files.
RMAN> BACKUP CURRENT CONTROLFILE;
OR
RMAN> SQL “ALTER DATABASE BACKUP CONTROLFILE TO ’’/u01/ …/bkctl.ctl’’ “;

RMAN> BACKUP CURRENT CONTROLFILE TO ‘/backup/cntrlfile.copy’;
RMAN> BACKUP CONTROLFILE COPY ‘/u10/backup/control.bkp’;
21) To Backup Spfile and archivelog.
RMAN> BACKUP SPFILE;
RMAN> BACKUP DEVICE TYPE sbt SPFILE ARCHIVELOG ALL;
RMAN> BACKUP DEVICE TYPE sbt DATAFILECOPY ALL NODUPLICATES;

RMAN> BACKUP RECOVERY FILES;
 
…. BACKUP set command…..

RMAN> BACKUP BACKUPSET ALL;

RMAN> BACKUP BACKUPSET ALL FORMAT = ‘/u01/backup_%u.bak’;
RMAN> BACKUP BACKUPSET COMPLETED BEFORE ‘SYSDATE-3’ DELETE INPUT;
RMAN> BACKUP DEVICE TYPE sbt BACKUPSET COMPLETED BEFORE ‘SYSDATE-14’ DELETE INPUT;
RMAN> BACKUP COPIES 2 DEVICE TYPE sbt BACKUPSET ALL;
RMAN> BACKUP AS COMPRESSED BACKUPSET DEVICE TYPE DISK COPIES 2 DATABASE FORMAT ‘/disk1/db_%U’, ‘/disk2/db_%U’;
RMAN> BACKUP AS COMPRESSED BACKUPSET;
RMAN> BACKUP AS COMPRESSED BACKUPSET INCREMENTAL FROM SCN 7181140667 DATABASE TAG ‘RMAN_RECOVERY’;
RMAN> BACKUP AS BACKUPSET DATAFILE ‘$ORACLE_HOME/ora11/users01.dbf’,’$ORACLE_HOME/ora11/users02.dbf’;
RMAN> BACKUP AS BACKUPSET DATAFILECOPY ALL;
RMAN> BACKUP AS BACKUPSET DATAFILECOPY ALL NODUPLICATES;


……Incremental backups……….
 
RMAN> BACKUP INCREMENTAL LEVEL=0 DATABASE;
RMAN> BACKUP INCREMENTAL LEVEL=1 DATABASE;
RMAN> BACKUP INCREMENTAL LEVEL=0 DATABASE PLUS ARCHIVELOG;
RMAN> BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG ‘incr’ DATABASE;
RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE SKIP INACCESSIBLE DATABASE;
RMAN> BACKUP DEVICE TYPE DISK INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG ‘daily’ DATABASE;

RMAN> BACKUP DEVICE TYPE DISK INCREMENTAL FROM SCN 5343434 DATABASE FORMAT ‘/tmp/incr_stand_%f’;
RMAN> BACKUP INCREMENTAL FROM SCN 444544 DATAFILE 5 FORMAT ‘/tmp/ForStand_%d’ TAG ‘FORSTANDBYdatabase’;
 
……..IMAGE copy………
 
RMAN> BACKUP AS COPY DATABASE;
RMAN> BACKUP AS COPY COPY OF DATABASE FROM TAG ‘weekly’ CHECK LOGICAL TAG ‘prod’;
RMAN> BACKUP AS COPY TABLESPACE 10;
RMAN> BACKUP AS COPY TABLESPACE users;
RMAN> BACKUP AS COPY TABLESPACE system, tools, users,apex;
RMAN> BACKUP AS COPY DATAFILE 4;
RMAN> BACKUP AS COPY DATAFILE 5 FORMAT ‘/backup/df2.cpy’ TAG daily_backup;
RMAN> BACKUP AS COPY CURRENT CONTROLFILE;
RMAN> BACKUP AS COPY CURRENT CONTROLFILE FORMAT ‘/backup/controlfilebkp.bkp’;
RMAN> BACKUP AS COPY ARCHIVELOG ALL;
RMAN> BACKUP AS COPY KEEP FOREVER NOLOGS CURRENT CONTROLFILE FORMAT ‘/backup/controlfl.cp’, DATAFILE 11 FORMAT ‘/backup/long.cp’, DATAFILE 4 FORMAT ‘/backup/long.cp’;
RMAN> BACKUP AS COPY DATAFILECOPY ‘prod_fl’ FORMAT ‘/—-‘;
RMAN> BACKUP AS COPY DATAFILECOPY ‘/backup/dfc.cp’ FORMAT ‘/backup1/dfb.cp’;
 
 

Rman LIST command

 
 
RMAN> LIST DB_UNIQUE_NAME ALL;
RMAN> LIST DB_UNIQUE_NAME OF DATABASE;
RMAN> LIST INCARNATION;
RMAN> LIST INCARNATION OF DATABASE;
RMAN> LIST INCARNATION OF DATABASE PROD;
RMAN> LIST BACKUP;
RMAN> LIST BACKUP SUMMARY;
RMAN> LIST BACKUP BY FILE;
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP OF DATABASE BY BACKUP;
RMAN> LIST BACKUP OF TABLESPACE users SUMMARY;
RMAN> LIST BACKUP OF DATAFILE 200;
RMAN> LIST BACKUP OF DATAFILE 43 SUMMARY;
RMAN> LIST BACKUP OF CONTROLFILE;
RMAN> LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 2332;
RMAN> LIST BACKUP OF ARCHIVELOG FROM TIME ‘sysdate-4’;
RMAN> LIST BACKUP OF ARCHIVELOG ALL COMPLETED BEFORE ‘sysdate-4’;
RMAN> LIST BACKUP RECOVERABLE;
RMAN> LIST EXPIRED BACKUP;

RMAN> LIST EXPIRED BACKUP OF ARCHIVELOG ALL SUMMARY;
RMAN> LIST COPY;

RMAN> LIST COPY OF DATABASE ARCHIVELOG ALL;
RMAN> LIST COPY OF TABLESPACE appl_idx;
RMAN> LIST COPY OF DATAFILE 13,4,56;
RMAN> LIST COPY OF CONTROLFILE;
RMAN> LIST EXPIRED COPY;
RMAN> LIST BACKUPSET SUMMARY;
RMAN> LIST BACKUPSET 87;
RMAN> LIST BACKUPSET OF DATAFILE 88;
RMAN> LIST ARCHIVELOG;
RMAN> LIST ARCHIVELOG ALL LIKE ‘%5515%’;
RMAN> LIST CONTROLFILECOPY “/tmp/cntrlfile.copy”;
RMAN> LIST SCRIPT NAMES;

RMAN> LIST ALL SCRIPT NAMES;
RMAN> LIST GLOBAL SCRIPT NAMES;
RMAN> LIST FAILURE;

RMAN> LIST FAILURE 343 DETAIL;
RMAN> LIST FAILURE ALL;
RMAN> LIST RESTORE POINT ALL;
 
 

RMAN REPORT commands 

 

RMAN> REPORT SCHEMA;
RMAN> REPORT OBSOLETE;
RMAN> REPORT NEED BACKUP;
RMAN> REPORT NEED BACKUP REDUNDANCY=4;
RMAN> REPORT NEED BACKUP RECOVERY WINDOW OF 4 DAYS;
RMAN> REPORT NEED BACKUP DAYS=5;
RMAN> REPORT NEED BACKUP DATABASE;
RMAN> REPORT NEED BACKUP INCREMENTAL 1;
RMAN> REPORT UNRECOVERABLE;
 

 

CHANGE commands.

 

To Update the status of a backup in the RMAN repository.

RMAN> CHANGE BACKUPSET 78788 KEEP FOREVER;

RMAN> CHANGE BACKUPSET 332 KEEP FOREVER NOLOGS;
RMAN> CHANGE BACKUP TAG ‘cold_db_bkup’ KEEP FOREVER;
RMAN> CHANGE BACKUP TAG ‘cold_db_bkup’ DATABASE KEEP FOREVER;
RMAN> CHANGE BACKUP TAG ‘cold_db_bkup’ KEEP FOREVER NOLOGS;
RMAN> CHANGE BACKUP TAG ‘cold_db_bkup’ NOKEEP;
RMAN> CHANGE BACKUPSET 5443 UNAVAILABLE;
RMAN> CHANGE BACKUPSET 142 NOKEEP;
RMAN> CHANGE BACKUPSET 233,4540,3334,34223 UNCATALOG;
RMAN> CHANGE BACKUP OF DATABASE TAG=’daily’ UNAVAILABLE;

RMAN> CHANGE BACKUP OF DATABASE DEVICE TYPE DISK UNAVAILABLE;
RMAN> CHANGE COPY OF DATABASE CONTROLFILE NOKEEP;
RMAN> CHANGE BACKUP OF SPFILE COMPLETED BEFORE ‘SYSDATE-3’ UNAVAILABLE;
RMAN> CHANGE ARCHIVELOG ALL UNCATALOG;

RMAN> CHANGE CONTROLFILECOPY ‘/tmp/controlfl.cp’ UNCATALOG;
RMAN> CHANGE FAILURE 4 PRIORITY LOW;
RMAN> CHANGE BACKUP FOR DB_UNIQUE_NAME standby1 RESET DB_UNIQUE_NAME;
RMAN> CHANGE BACKUP FOR DB_UNIQUE_NAME standby3 RESET DB_UNIQUE_NAME TO standby2;
RMAN> CHANGE DB_UNIQUE_NAME FROM prod TO test;
 
 

RMAN CROSSCHECK command.



RMAN> CROSSCHECK BACKUP;

RMAN> CROSSCHECK BACKUP TAG=’Daily_bkp’;
RMAN> CROSSCHECK BACKUP COMPLETED BETWEEN ‘SYSDATE-5’ AND ‘SYSDATE–1’;
RMAN> CROSSCHECK BACKUP COMPLETED BETWEEN ’03-MAY-17′ AND ’13-AUG-17′;
RMAN> CROSSCHECK BACKUP DEVICE TYPE sbt COMPLETED BETWEEN ’01-AUG-17′ AND ’10-SEP-17′;
RMAN> CROSSCHECK BACKUP DEVICE TYPE DISK COMPLETED BETWEEN ’01-JUN-16′ AND ’23-MAR-17′;
RMAN> CROSSCHECK BACKUP OF DATABASE;

RMAN> CROSSCHECK BACKUP OF TABLESPACE systems;
RMAN> CROSSCHECK BACKUP OF TABLESPACE users COMPLETED BEFORE ‘SYSDATE-7’;
RMAN> CROSSCHECK BACKUP OF TABLESPACES users,tools,apex;

RMAN> CROSSCHECK BACKUP OF DATAFILE 55;
RMAN> CROSSCHECK BACKUP OF DATAFILE 45 COMPLETED AFTER ‘SYSDATE-7’;
RMAN> CROSSCHECK BACKUP OF DATAFILE “/backup/system12.dbf” COMPLETED AFTER ‘SYSDATE-7’;
RMAN> CROSSCHECK BACKUP OF CONTROLFILE;
RMAN> CROSSCHECK BACKUP OF SPFILE;
RMAN> CROSSCHECK BACKUP OF ARCHIVELOG ALL;
RMAN> CROSSCHECK BACKUP OF ARCHIVELOG ALL SPFILE;
RMAN> CROSSCHECK COPY;

RMAN> CROSSCHECK COPY OF DATABASE;
RMAN> CROSSCHECK DATAFILECOPY 11,15,45;
RMAN> CROSSCHECK CONTROLFILECOPY ‘/tmp/control01.ctl’;
RMAN> CROSSCHECK ARCHIVELOG ALL;
RMAN> CROSSCHECK BACKUPSET;
RMAN> CROSSCHECK BACKUPSET 12232,12533,23324;
RMAN> CROSSCHECK BACKUPPIECE TAG = ‘weekly_backup’;
RMAN> CROSSCHECK PROXY 754;
 
 

RMAN SQL command.

 

Execute a SQL statement from within RMAN prompt.
RMAN> SQL “ALTER SYSTEM ARCHIVE LOG CURRENT”;
RMAN> SQL “ALTER SYSTEM SWITCH LOGFILE”;
RMAN> SQL ‘ALTER TABLESPACE users ONLINE’;

RMAN> SQL ‘ALTER DATABASE DATAFILE 23 OFFLINE’;
RMAN> SQL “ALTER DATABASE BACKUP CONTROLFILE TO TRACE”;
RMAN> SQL “ALTER TABLESPACE users ADD DATAFILE ”/data01/users01.dbf” SIZE 100K AUTOEXTEND ON NEXT 10K MAXSIZE 400K”;
 
 
 

RMAN RESTORE command.

 

RMAN> RESTORE DATABASE;
RMAN> RESTORE CONTROLFILE;
RMAN> RESTORE DATABASE VALIDATE;
RMAN> RESTORE DATABASE PREVIEW;
RMAN> RESTORE DATABASE PREVIEW SUMMARY;
RMAN> RESTORE DATABASE SKIP TABLESPACE temp, history;
RMAN> RESTORE DATABASE UNTIL SCN 887655;
RMAN> RESTORE TABLESPACE users;

RMAN> RESTORE TABLESPACE apex,systems,apps01;
RMAN> RESTORE TABLESPACE tbs1 PREVIEW;
RMAN> RESTORE TABLESPACE users VALIDATE;
RMAN> RESTORE DATAFILE 88;

RMAN> RESTORE DATAFILE 98 PREVIEW;
RMAN> RESTORE DATAFILE 33 VALIDATE;
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

RMAN> RESTORE CONTROLFILE FROM TAG ‘Daily_backup’;
RMAN> RESTORE CONTROLFILE FROM ‘/backup/control01.bkp’;
RMAN> RESTORE CONTROLFILE VALIDATE;
RMAN> RESTORE CONTROLFILE TO ‘/tmp/autobkp.dbf’ FROM AUTOBACKUP MAXSEQ 20 MAXDAYS 200;
RMAN> RESTORE SPFILE;

RMAN> RESTORE SPFILE FROM AUTOBACKUP;
RMAN> RESTORE ARCHIVELOG ALL VALIDATE;
RMAN> RESTORE ARCHIVELOG ALL PREVIEW;
RMAN> RESTORE ARCHIVELOG ALL PREVIEW RECALL;
RMAN> RESTORE ARCHIVELOG ALL DEVICE TYPE sbt PREVIEW;
RMAN> RESTORE ARCHIVELOG LOW LOGSEQ 9878 HIGH LOGSEQ 998283 THREAD 1 ALL;
RMAN> RESTORE ARCHIVELOG FROM LOGSEQ=21531 UNTIL LOGSEQ=22590;
RMAN> RESTORE STANDBY CONTROLFILE FROM TAG ‘for_standby’;
RMAN> RESTORE CLONE CONTROLFILE TO ‘/data03/pord/control01.ctl’ FROM ‘/data1/prod/control01.ctl’;
 

RMAN RECOVER command.

 

RMAN> RECOVER DATABASE;

RMAN> RECOVER DATABASE NOREDO;
RMAN> RECOVER DATABASE SKIP TABLESPACE temp;
RMAN> RECOVER DATABASE SKIP FOREVER TABLESPACE exam;
RMAN> RECOVER DATABASE UNTIL SCN 355334;

RMAN> RECOVER TABLESPACE apex;

RMAN> RECOVER TABLESPACE tools DELETE ARCHIVELOG MAXSIZE 5M;
RMAN> RECOVER DATAFILE 454;
RMAN> RECOVER DATAFILE 54 BLOCK 554 DATAFILE 44 BLOCK 45;
RMAN> RECOVER DATAFILE 432 BLOCK 204 DATAFILE 43 BLOCK 443 FROM TAG=’Weelky’;
RMAN> RECOVER DATAFILECOPY ‘/backup/datafile.df’ UNTIL TIME ‘SYSDATE-5’;
RMAN> RECOVER COPY OF DATABASE WITH TAG ‘incr_monday’;
RMAN> RECOVER COPY OF DATABASE WITH TAG ‘incr_tuesday’ UNTIL TIME ‘SYSDATE – 6’;
RMAN> RECOVER CORRUPTION LIST;
RMAN> RECOVER TABLESPACE users;
 
 

RMAN DELETE command. 

 

RMAN> DELETE EXPIRED BACKUP;
RMAN> DELETE OBSOLETE;

RMAN> DELETE NOPROMPT OBSOLETE;
RMAN> DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF 8 DAYS;
RMAN> DELETE EXPIRED BACKUP DEVICE TYPE sbt;
RMAN> DELETE BACKUP OF DATABASE LIKE ‘/tmp%’;
RMAN> DELETE NOPROMPT EXPIRED BACKUP OF TABLESPACE users COMPLETED BEFORE ‘SYSDATE-7’;
RMAN> DELETE BACKUP OF SPFILE TABLESPACE users DEVICE TYPE SBT;
RMAN> DELETE COPY;
RMAN> DELETE EXPIRED COPY;
RMAN> DELETE COPY TAG ‘Cold’;
RMAN> DELETE ARCHIVELOG ALL;
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE ‘sysdate-7’;
RMAN> DELETE ARCHIVELOG ALL BACKED UP 2 TIMES TO DEVICE TYPE SBT;
RMAN> DELETE ARCHIVELOG ALL LIKE ‘%343322%’;
RMAN> DELETE ARCHIVELOG UNTIL SEQUENCE=34334;
RMAN> DELETE FORCE ARCHIVELOG ALL COMPLETED BEFORE ‘sysdate-1’;
RMAN> DELETE FORCE ARCHIVELOG UNTIL SEQUENCE=22322;
RMAN> DELETE NOPROMPT ARCHIVELOG UNTIL SEQUENCE = 99898;
RMAN> DELETE EXPIRED ARCHIVELOG ALL;
RMAN> DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
RMAN> DELETE BACKUPSET 23,24,25;
RMAN> DELETE NOPROMPT BACKUPSET TAG ‘Daily_bkp’;
RMAN> DELETE FORCE NOPROMPT BACKUPSET TAG weekly_bkp;
RMAN> DELETE DATAFILECOPY “/backup01/datafile/system01.cp”;
RMAN> DELETE CONTROLFILECOPY ‘/tmp/cntrlfile.cp’;

RMAN> DELETE BACKUP DEVICE TYPE SBT;
RMAN> DELETE BACKUP DEVICE TYPE DISK;
 
 
 

RMAN DROP DATABASE command.


Delete the target database.


RMAN> DROP DATABASE;
RMAN> DROP DATABASE NOPROMPT;
RMAN> DROP DATABASE INCLUDING BACKUPS;
RMAN> DROP DATABASE INCLUDING BACKUPS NOPROMPT;
 

rman commands with examples related to DUPLICATE command.

 
 
 
 
RMAN> DUPLICATE TARGET DATABASE;
RMAN> DUPLICATE TARGET DATABASE TO prod;
RMAN> DUPLICATE TARGET DATABASE TO dev PFILE=/data04/initDEV.ora;

RMAN> DUPLICATE TARGET DATABASE TO devdb NOFILENAMECHECK;
RMAN> DUPLICATE DATABASE ‘prod’ DBID 1232323 TO ‘dev’ NOFILENAMECHECK;
RMAN> DUPLICATE DATABASE TO “dprod” NOFILENAMECHECK BACKUP LOCATION ‘/oracle/backup’;
RMAN> DUPLICATE TARGET DATABASE TO dup FROM ACTIVE DATABASE NOFILENAMECHECK PASSWORD FILE SPFILE;

RMAN> DUPLICATE TARGET DATABASE TO dprod

  LOGFILE GROUP 1 (‘?/dbs/dprod_log01.f’,’?/dbs/dprod_log02.f’) SIZE 300K, GROUP 2 (‘?/dbs/dprod_log_2_3.f’,’?/dbs/dprod_log_2_2.f’) SIZE 400K REUSE;
RMAN> DUPLICATE TARGET DATABASE TO dup FOR STANDBY FROM ACTIVE DATABASE PASSWORD FILE SPFILE PARAMETER_VALUE_CONVERT ‘/data01’, ‘/ddata02’
  SET DB_FILE_NAME_CONVERT ‘/data01′,’/data02’
  SET LOG_FILE_NAME_CONVERT ‘/data01′,’/data02’
  SET SGA_MAX_SIZE 200M SET SGA_TARGET 100M;

RMAN> DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE;
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE NOFILENAMECHECK;
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE
  SPFILE PARAMETER_VALUE_CONVERT ‘/data01/’,’/data02/’
  SET “DB_UNIQUE_NAME”=”prod”
  SET LOG_FILE_NAME_CONVERT ‘/data01/’,’/data02/’
  SET DB_FILE_NAME_CONVERT ‘/data01/’,’/data02/’
  DORECOVER;
RMAN> DUPLICATE DATABASE TO dprod
  UNTIL RESTORE POINT rstr01
  DB_FILE_NAME_CONVERT=’/prod1/dbfiles/’,’/proddb/dbfiles’
  PFILE = ‘/proddb/admin/init.ora’;
 
 

rman commands with examples for SWITCH command.

 
 
RMAN> SWITCH DATAFILE ALL;
RMAN> SWITCH DATABASE TO COPY;
RMAN> SWITCH TABLESPACE users TO COPY;
RMAN> SWITCH DATAFILE ‘/data03/tools.dbf’ TO DATAFILECOPY ‘/data05/tools.copy’;
RMAN> SWITCH DATAFILE “/db/datafile/sysaux.dbf” TO COPY;
RMAN> SWITCH TEMPFILE 1;

RMAN> SWITCH TEMPFILE 1 TO ‘/oracle/dbs/temp1.f’;
RMAN> SWITCH TEMPFILE ALL; 
RMAN> SWITCH CLONE DATAFILE ALL;
 

RMAN CATALOG command .

 
RMAN> CATALOG DATAFILECOPY ‘/data01/prod/user01.dbf’;
RMAN> CATALOG CONTROLFILECOPY ‘/backup/ctrl.bkp’;
RMAN> CATALOG ARCHIVELOG ‘/backup/arch1_123.dbf’, ‘/backup02/arch1_543.dbf’;

RMAN> CATALOG BACKUPPIECE ‘/backup/dailybkp_0199832’;
RMAN> CATALOG LIKE ‘/backup02’;
RMAN> CATALOG START WITH ‘/backup/prod/’;
RMAN> CATALOG START WITH ‘+dg1’;
RMAN> CATALOG RECOVERY AREA;
 
 
 

rman commands with examples for ALLOCATE command.


RMAN> ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
RMAN> ALLOCATE CHANNEL ch DEVICE TYPE DISK FORMAT ‘/backup/DB_U%’;
RMAN> ALLOCATE CHANNEL t1 DEVICE TYPE DISK CONNECT ‘sys/***@bksrv’;
RMAN> ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS ‘ENV=(OB_MEDIA_FAMILY=fullbkp_mf)’;
RMAN> ALLOCATE CHANNEL t1 DEVICE TYPE sbt PARMS ‘ENV=(OB_DEVICE_1=tape1, OB_DEVICE_2=tape4)’;
RMAN> ALLOCATE CHANNEL t1 TYPE ‘sbt_tape’ PARMS=’SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so.1′;
RMAN> ALLOCATE CHANNEL t1 TYPE ‘sbt_tape’ SEND “NB_ORA_CLIENT=CLIENT_MACHINE_NAME”;
RMAN> ALLOCATE CHANNEL ‘dev1’ TYPE ‘sbt_tape’ PARMS ‘ENV=OB2BARTYPE=ORACLE8, OB2APPNAME=ORCL, OB2BARLIST=MACHINENAME_ORCL_ARCHLOGS)’;

RMAN> ALLOCATE CHANNEL y1 TYPE DISK RATE 70M;
RMAN> ALLOCATE AUXILIARY CHANNEL ac1 TYPE DISK;
RMAN> ALLOCATE AUXILIARY CHANNEL ac2 DEVICE TYPE sbt;

ALLOCATE CHANNEL FOR MAINTENANCE – allocate a channel in preparation for issuing maintenance commands such as DELETE.

 
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK FORMAT “/backup2/%U”;

RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK CONNECT ‘@test1’;
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt;
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt PARMS ‘SBT_LIBRARY=/usr/local/oracle/backup/lib/libobk.so, ENV=(OB_DEVICE_1=tape2)’;
 

RMAN RELEASE CHANNEL command. 

 

RMAN> RELEASE CHANNEL;
RMAN> RELEASE CHANNEL c1;
 
 
 

RMAN BLOCKRECOVER command. 

 
 
RMAN> BLOCKRECOVER CORRUPTION LIST;
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 22;
RMAN> BLOCKRECOVER DATAFILE 7 BLOCK 233,235 DATAFILE 4 BLOCK 101;
RMAN> BLOCKRECOVER DATAFILE 2 BLOCK 12,13 DATAFILE 3 BLOCK 34345 DATAFILE 4 BLOCK 19;
RMAN> BLOCKRECOVER DATAFILE 3 BLOCK 2,4,5 TABLESPACE sales DBA 23232,412 FROM DATAFILECOPY;
RMAN> BLOCKRECOVER TABLESPACE dwh DBA 4194404,4194405 FROM TAG “weekly”;
RMAN> BLOCKRECOVER TABLESPACE dwh DBA 94404 RESTORE UNTIL TIME ‘SYSDATE-2’;
 

RMAN ADVISE FAILURE command.


RMAN> ADVISE FAILURE;
RMAN> ADVISE FAILURE 555, 242;
RMAN> ADVISE FAILURE ALL;
RMAN> ADVISE FAILURE CRITICAL;
RMAN> ADVISE FAILURE HIGH;
RMAN> ADVISE FAILURE LOW;
RMAN> ADVISE FAILURE HIGH EXCLUDE FAILURE 625;

 

REPAIR FAILURE command

 

Repair one or more failures recorded in the automated diagnostic repository.
 
RMAN> REPAIR FAILURE;
RMAN> REPAIR FAILURE PREVIEW;
RMAN> REPAIR FAILURE NOPROMPT;
RMAN> REPAIR FAILURE USING ADVISE OPTION integer;
 

SPOOL command.

 
To Write RMAN output.

RMAN> SPOOL LOG TO ‘/tmp/spool.log’;
RMAN> SPOOL LOG TO ‘/tmp/backup.log’ APPEND;
RMAN> SPOOL LOG OFF;
 

RMAN VALIDATE command.

 

RMAN> VALIDATE BACKUPSET 776;
RMAN> VALIDATE BACKUPSET 9987, 9998;
RMAN> VALIDATE DATABASE;
RMAN> VALIDATE CHECK LOGICAL DATABASE;
RMAN> VALIDATE SKIP INACCESSIBLE DATABASE;
RMAN> VALIDATE COPY OF DATABASE;
RMAN> VALIDATE TABLESPACE users;
RMAN> VALIDATE COPY OF TABLESPACE users;
RMAN> VALIDATE DATAFILE 23;
RMAN> VALIDATE DATAFILE 4,8;
RMAN> VALIDATE DATAFILE 4 BLOCK 56;
RMAN> VALIDATE DATAFILE 8 SECTION SIZE = 200M;
RMAN> VALIDATE CURRENT CONTROLFILE;
RMAN> VALIDATE SPFILE;
RMAN> VALIDATE RECOVERY FILES;
RMAN> VALIDATE RECOVERY AREA;
RMAN> VALIDATE DB_RECOVERY_FILE_DEST;
 

RMAN RUN command.

 

rman commands with examples To Execute one or more RMAN commands.
 
RMAN> run {
ALLOCATE CHANNEL c1 TYPE DISK FORMAT ‘/backup01/%U’;
BACKUP TABLESPACE users;
}
RMAN> run {
  ALLOCATE CHANNEL c1 TYPE DISK FORMAT ‘/backup4/%U’;
  BACKUP TABLESPACE users;
}
RMAN> run
{
  ALLOCATE CHANNEL dev1 DEVICE TYPE DISK FORMAT ‘/backup05/%U’;
  ALLOCATE CHANNEL dev2 DEVICE TYPE DISK FORMAT ‘/backup06/%U’; 
  BACKUP(TABLESPACE system,fin,mark FILESPERSET 20) (DATAFILE 23,53,65);
}
 

RMAN CREATE SCRIPT command. 

 

Create a stored script within recovery catalog.

RMAN> CREATE SCRIPT backup_full

COMMENT “Full backup of whole database and archived redo log files”
{BACKUP INCREMENTAL LEVEL 0 TAG backup_full FORMAT “backup/%U” DATABASE PLUS ARCHIVELOG;}

RMAN> CREATE SCRIPT backup_ts_tools

COMMENT ‘tablespace users backup’
{ALLOCATE CHANNEL c1 TYPE DISK FORMAT ‘/backup/%U’;
BACKUP TABLESPACE users;}
RMAN> CREATE SCRIPT backup_ts_apex FROM FILE ‘backup_apex.rman’;
RMAN> CREATE GLOBAL SCRIPT gl_prod_bkp {BACKUP DATABASE PLUS ARCHIVELOG;}
RMAN> CREATE GLOBAL SCRIPT backup_prod_db

COMMENT “backup database”
{BACKUP DATABASE;}

 

RMAN PRINT SCRIPT command.

 

To Display a stored script.
 
RMAN> PRINT SCRIPT backup_prod_db;
RMAN> PRINT GLOBAL SCRIPT backup_prod_db;
RMAN> PRINT GLOBAL SCRIPT gl_prod_bkp TO FILE “/tmp/gl_prod_bkp.rman”;

RMAN REPLACE SCRIPT command.

Replace an existing script stored rman recovery catalog.


RMAN> REPLACE SCRIPT backup_prod_db {BACKUP DATABASE PLUS ARCHIVELOG;}
RMAN> REPLACE SCRIPT df {BACKUP DATAFILE &1 TAG &2.1 FORMAT ‘&3_%U’;}
RMAN> REPLACE GLOBAL SCRIPT backup_prod_db {BACKUP DATABASE PLUS ARCHIVELOG;}
RMAN> REPLACE GLOBAL SCRIPT gl_full_bkp FROM FILE ‘/tmp/script_file.txt’;

RMAN EXECUTE SCRIPT command.

Execute an RMAN stored script.


RMAN> RUN {EXECUTE SCRIPT backup_full;}
RMAN> RUN {EXECUTE SCRIPT backup_ts_any USING ‘example’;}
RMAN> RUN {EXECUTE SCRIPT backup_proddb_bkp USING 3 test_backup df3;}
RMAN> RUN {EXECUTE GLOBAL SCRIPT gl_backup_db;}
 
 
 
 

RMAN DELETE SCRIPT command. 

 

To Delete a stored script from rman recovery catalog.
 
RMAN> DELETE SCRIPT backup_prod_db;
RMAN> DELETE GLOBAL SCRIPT gl_backup_db;

 

RMAN FLASHBACK DATABASE command.

To Return the database to a past time or SCN.

 
RMAN> FLASHBACK DATABASE TO SCN 34223;
RMAN> FLASHBACK DATABASE TO RESTORE POINT ‘restore_233’;

RMAN TRANSPORT TABLESPACE command.

 

Transportable tablespaces permit the copying or moving of a tablespace from one Oracle database to another.
 
 
RMAN> TRANSPORT TABLESPACE example, tools
TABLESPACE DESTINATION ‘/data01/prod’ AUXILIARY DESTINATION ‘/data04/aux’ UNTIL TIME ‘SYSDATE-14/1434’;
RMAN> TRANSPORT TABLESPACE apex
TABLESPACE DESTINATION ‘/data95/transport’ AUXILIARY DESTINATION ‘/data09/aux’ DATAPUMP DIRECTORY dpdirectory DUMP FILE ‘dmpfiles.dmp’ IMPORT SCRIPT ‘impscripts.sql’ EXPORT LOG ‘explogs.log’;

EXIT or QUIT Command. 

 
 
To Exit from RMAN console.

RMAN> exit;

RMAN> quit;

———————————————————————————————————–

Multitenant Environment RMAN Command. —> Coming soon.

 

 

2 thoughts on “rman commands with examples”

Leave a Comment