We can use RMAN to backup all the parts of the oracle database. RMAN backup commands can be used backs up Oracle database files, copies of database files, archived logs, or backup sets.
Here is the general syntax for RMAN backup command
Syntax: BACKUP FULL Options BACKUP FULL AS (COPY | BACKUPSET) Options BACKUP INCREMENTAL LEVEL [=] integer Options BACKUP INCREMENTAL LEVEL [=] integer AS (COPY | BACKUPSET) Options BACKUP AS (COPY | BACKUPSET) Options BACKUP AS (COPY | BACKUPSET) (FULL | INCREMENTAL LEVEL [=] integer) Options Options: [backupOperand [backupOperand]...] backupSpec [backupSpec]... [PLUS ARCHIVELOG [backupSpecOperand [backupSpecOperand]...]]; backupOperand::= { FORMAT [=] 'format_string' [, 'format_string']... | CHANNEL ['] channel_id ['] | CUMULATIVE | MAXSETSIZE [=] integer [ K | M | G ] | TAG [=] ['] tag_name ['] | keepOption | SKIP { OFFLINE | READONLY | INACCESSIBLE } | VALIDATE | NOT BACKED UP [SINCE TIME [=] 'date_string'] | COPIES [=] integer | DEVICE TYPE deviceSpecifier . . . } backupSpec::= [(] { BACKUPSET { {ALL | completedTimeSpec } | primary_key) [, primary_key]... } | COPY OF { DATABASE | TABLESPACE ['] tablespace_name ['] [, ['] tablespace_name [']]... | DATAFILE datafileSpec [, datafileSpec]... } | DATAFILE datafileSpec [, datafileSpec]... | DATAFILECOPY 'filename' [, 'filename']... | DATAFILECOPY FROM TAG [=] ['] tag_name ['] [, ['] tag_name [']]... | DATAFILECOPY { ALL | LIKE 'string_pattern' } | TABLESPACE ['] tablespace_name ['] [, ['] tablespace_name [']]... | DATABASE | archivelogRecordSpecifier | CURRENT CONTROLFILE [FOR STANDBY] | CONTROLFILECOPY 'filename' | SPFILE } [backupSpecOperand [backupSpecOperand]...] backupSpecOperand::= { FORMAT [=] 'format_string' [, 'format_string']... | CHANNEL ['] channel_id ['] | CUMULATIVE | MAXSETSIZE [=] integer [ K | M | G ] | TAG [=] ['] tag_name ['] | keepOption | SKIP { OFFLINE | READONLY | INACCESSIBLE } | NOT BACKED UP [ SINCE TIME [=] 'date_string' | integer TIMES ] | DELETE [ALL] INPUT . . . } .
You should configure default devices and channels in advance of running RMAN Backup.
For disk RUN { ALLOCATE CHANNEL disk01 TYPE disk ; ALLOCATE CHANNEL disk02 TYPE disk ; ALLOCATE CHANNEL disk03 TYPE disk ; BACKUP DATABASE FORMAT '${ORACLE_SID}-%U'; } For tape RUN { ALLOCATE CHANNEL tape01 TYPE 'SBT_TAPE' ; ALLOCATE CHANNEL tape02 TYPE 'SBT_TAPE' ; ALLOCATE CHANNEL tape03 TYPE 'SBT_TAPE' ; BACKUP DATABASE FORMAT '${ORACLE_SID}-%U'; } or RUN { ALLOCATE CHANNEL tape01 TYPE sbt ; ALLOCATE CHANNEL tape02 TYPE sbt ; ALLOCATE CHANNEL tape03 TYPE sbt ; BACKUP DATABASE FORMAT '${ORACLE_SID}-%U'; }
RMAN put the backup in flash recovery area in case device type is disk and you have not specified any format
Here is comprehensive listing of the RMAN backup commands
RMAN BACKUP database command
RMAN> BACKUP DATABASE; RMAN> BACKUP DATABASE TAG=’test backup’; RMAN> BACKUP DATABASE COMMENT=’full backup’; RMAN> BACKUP TAG 'weekly_full_db_bkup' DATABASE MAXSETSIZE 10M; RMAN> BACKUP MAXSETSIZE 500M DATABASE PLUS ARCHIVELOG; RMAN> BACKUP DURATION 00:60 DATABASE; RMAN> BACKUP DURATION 00:30 MINIMIZE TIME DATABASE; RMAN> BACKUP DURATION 00:45 MINIMIZE LOAD DATABASE;
You can backup database and archivelog at the same time using the below command
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
It performs below steps to have a consistent backup
a.Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command.
b.Runs BACKUP ARCHIVELOG ALL. Note that if backup optimization is enabled, then RMAN skips logs that it has already backed up to the specified device.
c.Backs up the rest of the files specified in BACKUP command.
d. Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command.
d. Backs up any remaining archived logs generated during the backup.
This guarantees that datafile backups taken during the command are recoverable to a consistent state.
RMAN> BACKUP DATABASE KEEP FOREVER; RMAN> BACKUP DATABASE KEEP UNTIL TIME=’SYSDATE+30’; RMAN> BACKUP DATABASE UNTIL 'SYSDATE+365' NOLOGS; RMAN> BACKUP DATABASE NOEXCLUDE; RMAN> BACKUP DATABASE NOEXCLUDE KEEP FOREVER TAG=’abc’; RMAN> BACKUP DATABASE SKIP READONLY; RMAN> BACKUP DATABASE SKIP OFFLINE; RMAN> BACKUP DATABASE SKIP INACCESSIBLE; RMAN> BACKUP DATABASE SKIP READONLY SKIP OFFLINE SKIP INACCESSIBLE; RMAN> BACKUP DATABASE FORCE; -- backup read only database also 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;
RMAN> BACKUP DATABASE COPIES=2;
Here are some format you can use for backup
RMAN> BACKUP DATABASE FORMAT '/disk1/backups/db_%U.bck' RUN { ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/disk1/%d_backups/%U'; ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/disk2/%d_backups/%U'; ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT '/disk3/%d_backups/%U'; BACKUP AS COPY DATABASE; } 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; RMAN> BACKUP CHECK LOGICAL DATABASE; RMAN> BACKUP VALIDATE CHECK LOGICAL DATABASE; RMAN> BACKUP VALIDATE DATABASE; RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;
RMAN Backup Tablespace command
RMAN> BACKUP TABLESPACE test; RMAN> BACKUP TABLESPACE system, users, tools; RMAN> BACKUP TABLESPACE 4; RMAN> BACKUP TABLESPACE USERS PLUS ARCHIVELOG; RMAN> BACKUP TABLESPACE USERS INCLUDE CURRENT CONTROLFILE; RMAN> BACKUP TABLESPACE USERS INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG; RMAN> BACKUP TABLESPACE USERS SECTION SIZE 100M; RMAN> BACKUP SECTION SIZE 250M TABLESPACE USERS;
RMAN backup datafile command
RMAN> BACKUP DATAFILE 9; 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;
RMAN backup archive log command
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%';
RMAN backup control file command
RMAN> BACKUP CURRENT CONTROLFILE TO '/backup/cntrlfile.copy'; RMAN> BACKUP CONTROLFILE COPY ‘/u10/backup/control.bkp’;
RMAN backup spfile command
RMAN> BACKUP SPFILE; RMAN> BACKUP DEVICE TYPE sbt SPFILE ARCHIVELOG ALL; RMAN> BACKUP DEVICE TYPE sbt DATAFILECOPY ALL NODUPLICATES; RMAN> BACKUP RECOVERY FILES;
RMAN backup pluggable database command
RMAN>BACKUP PLUGGABLE DATABASE PDB1, PDB2;
BACKUP set
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; RMAN> BACKUP AS COMPRESSED BACKUPSET DEVICE TYPE DISK COPIES 2 DATABASE FORMAT '/disk1/db_%U', '/disk2/db_%U'; RMAN> BACKUP AS COMPRESSED BACKUPSET INCREMENTAL FROM SCN 4111140000000 DATABASE TAG 'RMAN_RECOVERY'; RMAN> BACKUP AS BACKUPSET DATAFILE '$ORACLE_HOME/oradata/users01.dbf','$ORACLE_HOME/oradata/tools01.dbf'; RMAN> BACKUP AS BACKUPSET DATAFILECOPY ALL; RMAN> BACKUP AS BACKUPSET DATAFILECOPY ALL NODUPLICATES;
RMAN backup as copy or IMAGE copy command
RMAN> BACKUP AS COPY DATABASE; RMAN> BACKUP AS COPY COPY OF DATABASE FROM TAG 'test' CHECK LOGICAL TAG 'duptest'; RMAN> BACKUP AS COPY TABLESPACE 8; RMAN> BACKUP AS COPY TABLESPACE test; RMAN> BACKUP AS COPY TABLESPACE system, tools, users, undotbs; RMAN> BACKUP AS COPY DATAFILE 1; RMAN> BACKUP AS COPY DATAFILE 2 FORMAT '/disk2/df2.cpy' TAG my_tag; RMAN> BACKUP AS COPY CURRENT CONTROLFILE; RMAN> BACKUP AS COPY CURRENT CONTROLFILE FORMAT ‘/....’; RMAN> BACKUP AS COPY ARCHIVELOG ALL; RMAN> BACKUP AS COPY KEEP FOREVER NOLOGS CURRENT CONTROLFILE FORMAT '?/oradata/cf_longterm.cpy', DATAFILE 1 FORMAT '?/oradata/df1_longterm.cpy', DATAFILE 2 FORMAT '?/oradata/df2_longterm.cpy'; RMAN> BACKUP AS COPY DATAFILECOPY 'bar' FORMAT 'foobar'; RMAN> BACKUP AS COPY DATAFILECOPY '/disk2/df2.cpy' FORMAT '/disk1/df2.cpy'; RMAN> BACKUP AS COPY REUSE TARGETFILE '/u01/oracle/11.2.0.2/dbs/orapwcrd' AUXILIARY FORMAT '/u01/oracle/11.2.0.2/dbs/orapwcrd'; RMAN> BACKUP AS COPY CURRENT CONTROLFILE FOR STANDBY AUXILIARY format '+DATA/crd/data1/control01.ctl';
RMAN 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 CUMULATIVE SKIP INACCESSIBLE DATABASE; RMAN> BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'incr' DATABASE; RMAN> BACKUP DEVICE TYPE DISK INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'oltp' DATABASE; RMAN> BACKUP DEVICE TYPE DISK INCREMENTAL FROM SCN 351986 DATABASE FORMAT '/tmp/incr_standby_%U'; RMAN> BACKUP INCREMENTAL FROM SCN 629184 DATAFILE 5 FORMAT '/tmp/ForStandby_%U' TAG 'FORSTANDBY'; RMAN> BACKUP INCREMENTAL LEVEL = --- tablespace/datafile
Related Articles
RMAN List backup commands : RMAN List backup commands are used to list the backup taken using RMAN ,Date and Time and many other details are included
RMAN connection decoded
Oracle RMAN commands cheatsheet : Download the RMAN cheatsheet for the various command on backup and recovery
recover database using RMAN : How to recover database using RMAN, restore and recover command, parallelism
How to debug Oracle RMAN session : How to debug RMAN session for error and hang
RMAN-06059 : Check out how to resolve the RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
RMAN-20004 : RMAN-20004 happens when a Database has been cloned and a connection made from the clone to Catalog using rman with out changing the DBID of the clone,
ORA-00245 : Snapshot controlfile is a new feature in RMAN for resynchronizing. Important changes with it from 11gR2 and how to resolve the error ORA-00245
Nice article. Thanks for sharing such useful information.