RMAN utility is used to take backup of Oracle Database.
Below are the RMAN utility commands which are useful in a day to day tasks.
1. Backup Database :
- Full Database Backup
RMAN> BACKUP DATABASE;
RMAN> BACKUP DATABASE TAG 'FULL BACKUP'; -- Take full database backup with TAG.- Incremental Level 0 Backup
RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;- Incremental Level 1 Backup
RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;- Backup Database Compressed
RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;- Backup Current Contolfile
RMAN> BACKUP CURRENT CONTROLFILE;- Backup SPFILE
RMAN> BACKUP SPFILE;- Backup Control file to Trace
RMAN> BACKUP CURRENT CONTROLFILE TO TRACE;2. Backup Options
- Backup database and Archive log
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;- Backup Specific Tablespace
RMAN> BACKUP TABLESPACE TABLESPACE1,TABLESPACE2; -- You can take more then one tablespace backup at a time.- Backup data file using datafile number;
RMAN> BACKUP DATAFILE 1,2;- Backup data file at specific location
RMAN> BACKUP AS COPY DATAFILE 1 FORMAT '/storage/datafile1.bkp';3. Archive log Backup
- Backup All Archive logs
RMAN> BACKUP ARCHIVELOG ALL;- Backup Archive logs until specific time.
RMAN> BACKUP ARCHIVELOG ALL UNTIL TIME "TO_DATE('2016-11-21 19:00:00','YYYY-MM-DD HH24:MI:SS')";- Backup Archive logs From..Until Sequence
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 50 UNTIL SEQUENCE 100;- Delete archive log after backup.
RMAN> BACKUP ARCHIVELOG ALL DELETE INPUT;4. Restore Commands.
- Restore database
RMAN> RESTORE DATABASE;- Restore database preview.
RMAN> RESTORE DATABASE PREVIEW;
RMAN> RESTORE DATABASE PREVIEW SUMMARY; -- To generate a summary of a restore operation preview.Note : This operation uses metadata to generate output. It does not scan the backup files
- Restore control file from auto backup.
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;- Restore a specific data file using name or data file number.
RMAN> RESTORE DATAFILE '/u01/app/oracle/oradata/users01.dbf';
RMAN> RESTORE DATAFILE 10; 5. Recover commands.
- Recover Database
RMAN> RECOVER DATABASE;- Recover database until specific time
RMAN> RECOVER DATABASE UNTIL TIME "TO_DATE('2016-11-21 19:00:00','YYYY-MM-DD HH24:MI:SS')";- Recover database until specific sequence.
RMAN> RECOVER DATABASE UNTIL SEQUENCE 100;Note : Above command tells RMAN to apply archived redo logs only up to the specified redo-log sequence boundary, rather than recovering as far forward as possible.
RMAN> RECOVER DATABASE UNTIL TIME "TO_DATE('2016-11-21 19:00:00','YYYY-MM-DD HH24:MI:SS')";- Recover database using backup control file.
RMAN> RECOVER DATABASE USING BACKUP CONTROLFILE;Note : Above RMAN command tells Oracle to perform media recovery using a control file that was restored from a backup, rather than relying on the current control file as the authoritative source for the database’s recovery metadata.
- Recover specific table space.
RMAN> RECOVER TABLESPACE USERS;6. Backup Maintenance.
- Crosscheck all backup.
RMAN> CROSSCHECK BACKUP;- Crosscheck archive logs.
RMAN> CROSSCHECK ARCHIVELOG ALL;- Delete expired backup.
RMAN> DELETE EXPIRED BACKUP;- Delete obsolete backup.
RMAN> DELETE OBSOLETE;- Delete backup by TAG.
RMAN> DELETE BACKUP TAG 'TAG NAME';- Delete backup completed before date.
RMAN> DELETE BACKUP COMPLETED BEFORE 'SYSDATE-15';7. Validate Backups and Viewing backup information.
Note : Validate command does not create a backup piece. Instead, RMAN reads the particular files and validates them.
- Validate database backup
RMAN> BACKUP VALIDATE DATABASE;- Validate tablespace.
RMAN> BACKUP VALIDATE TABLESPACE TEST;- Validate datafile
RMAN> BACKUP VALIDATE DATAFILE 10;- List backup information.
RMAN> LIST BACKUP;- List backup of datafile.
RMAN> LIST BACKUP OF DATAFILE 10;- List Archive log Backup.
RMAN> LIST ARCHIVELOG ALL;