Tuesday, June 30, 2015

RMAN Commands

LIST Command

LIST BACKUP; #List all your backup sets.
LIST BACKUPSET; #Lists only backup sets and proxy copies.
LIST COPY; #Lists of Image copies and Archive Logs.
LIST EXPIRED BACKUP; #Backups did not found after crosscheck. That is backup is manually moved or deleted from OS.
LIST EXPIRED BACKUPSET;
LIST RECOVERABLE BACKUPSET;
LIST BACKUP BY FILE; #List backup by Datafile, controlfile, spfile.
LIST BACKUP SUMMARY; #Lists backup sets, proxy copies, and disk copies.
LIST BACKUP OF DATABASE; LIST BACKUP LIKE '/tmp/%'; list backup of datafile 1;
LIST ARCHIVELOG ALL BACKED UP 2 TIMES TO DEVICE TYPE sbt;
LIST COPY OF DATAFILE 2 COMPLETED BETWEEN '17-MAR-2008' AND '22-MAR-2008'; are also available.
LIST INCARNATION; LIST INCARNATION OF DATABASE; to see the incarnations of your database.

ADVICE FAILURE;

REPORT Command

REPORT NEED BACKUP; # Determine which database files need backup under a specific retention policy. #
REPORT UNRECOVERABLE; #Report which database files require backup because they have been affected by some NOLOGGING operation.
REPORT SCHEMA; #Lists and displays information about the database files.
REPORT OBSOLETE; #REPORT OBSOLETE displays the backups that are obsolete according to the current retention policy
REPORT NEED BACKUP RECOVERY WINDOW OF 2 DAYS DATABASE SKIP TABLESPACE data01;
REPORT SCHEMA AT TIME 'SYSDATE-1';

DELETE Command

DELETE BACKUPSET ALL; - Delete all Backup setDELETE COPY ALL; -Delete all image copies
DELETE OBSOLETE; -Delete obsolete Backups
BACKUP ARCHIVELOG ALL DELETE ALL INPUT;
DELETE ARCHIVELOG ALL BACKED UP 1 TIMES TO DEVICE TYPE SBT_TAPE;

CROSSCHECK Command

CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE EXPIRED BACKUP;
DELETE EXPIRED ARCHIVELOG ALL

Expired and Obselete difference -

DELETE removes the physical files from the backup media, deletes the record of the backup from the recovery catalog
(if RMAN is connected to a recovery catalog), and updates the records of these backups in the control file to status DELETED.
in the obsolete case, what helps to clarify the difference between OBSOLETE and EXPIRED is the retention policy.
If a backup item is no longer needed for recovery because it is older than the retention policy
then it is obsolete.

What does DELETE OBSOLETE do?
The RMAN DELETE command supports an OBSOLETE option, which deletes backups that are obsolete, that is, no longer
needed to satisfy specified recoverability requirements. You can delete files obsolete according to the configured
default retention policy, or another retention policy that you specify as an option to the DELETE OBSOLETE command.
As with other forms of the DELETE command, the files deleted are removed from backup media, deleted from the recovery
catalog, and marked as DELETED in the control file.

The next clarification concerns the EXPIRED status. How does an object become expired?
When the CROSSCHECK command is used to determine whether backups recorded in the repository still exist on disk or tape,
if RMAN cannot locate the backups, then it updates their records in the RMAN repository to EXPIRED status. You can then
use the DELETE EXPIRED command to remove records of expired backups from the RMAN repository. If the expired files still
exist, then the DELETE EXPIRED command terminates with an error.

Delete Backup from Disk

ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
CROSSCHECK COPY;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP DEVICE TYPE DISK;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL DEVICE TYPE DISK

Delete Backup from TAPE

ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE SBT;
CROSSCHECK BACKUP; CROSSCHECK COPY;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP DEVICE TYPE SBT;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL DEVICE TYPE SBT;

COMPRESSED BACKUP

BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG DELETE INPUT;

RECOVER SYSTEM DATAFILE

1. startup mount;
2. restore datafile 1;
3. recover datafile 1;
4. alter database open;

RECOVER DATAFILE

1. restore datafile 4;
2. recover datafile 4;
3. sql 'alter tablespace users online' ;

RECOVER CONTROL FILE

1. SET DBID $v_dbid;
2. STARTUP NOMOUNT;
3. RESTORE CONTROLFILE FROM AUTOBACKUP;
4. ALTER DATABASE MOUNT;
5. RECOVER DATABASE;
6. ALTER DATABASE OPEN RESETLOGS;

COMPLETE RECOVERY

1. SET DBID $v_dbid;
2. STARTUP NOMOUNT;
3. RESTORE SPFILE FROM AUTOBACKUP ;
4. STARTUP FORCE NOMOUNT;
5. RESTORE CONTROLFILE FROM AUTOBACKUP;
6. ALTER DATABASE MOUNT;

run { set until sequence $v_seq thread 1;
restore database;
recover database; }
ALTER DATABASE OPEN RESETLOGS;


ENABLE BLOCK TRACKING

CTWR background process is wrting to Change block tracking File at OS level..Not implemented in Our environment
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+fradg';

select FILENAME, STATUS, BYTES from v$block_change_tracking;


PRINT GLOBAL SCRIPTS

RMAN> print global script level0_sapr01_backup;

printing stored global script: level0_sapr01_backup
{set command id to 'rman_sapr01_incrlevel0';
delete noprompt backup completed before 'sysdate-6';
delete noprompt archivelog all completed before 'sysdate-3';
crosscheck backup; crosscheck archivelog all;
backup as compressed backupset incremental level 0 TAG = SAPR01_LEVEL0 database plus archivelog;
report obsolete; delete noprompt backup completed before 'sysdate-6';
report need backup database; resync catalog;}

WINDOWS TO SCHEDULE BACKUP

rman_level0_sapr01_dailybackup.cmd which contains=
c:\oracle\product\10.2.0\db_1\bin\RMAN TARGET sys/alta02sys@sapr01
CATALOG rc/alta0racle@rc
CMDFILE=
CMDFILE=C:\oracle_scripts\sapr01\rman_sapr01_backup\rman_level0_sapr01_backup.rcv LOG=C:\oracle_scripts\sapr01\rman_sapr01_backup\rman_level0_sapr01_backup.log append
rman_level0_sapr01_backup.rcv contains
RUN {EXECUTE GLOBAL SCRIPT level0_sapr01_backup;}

Steps to recover database

RMAN target=/

RMAN> SET DBID 669001291; ### it'is part of the name of autobackup file. So if autobackup file name is 'c-669001291-20070129-03' then DBID is669001291

RMAN> startup force nomount;
and run recovery of SPFILE
RMAN> RESTORE SPFILE FROM AUTOBACKUP;
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
RMAN> STARTUP FORCE NOMOUNT:
RMAN> LIST BACKUP SUMMARY;
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
363 B F A SBT_TAPE 28/09/2011 19:39:04 1 1 NO TAG20110928T193859
368 B A X SBT_TAPE 29/09/2011 12:10:43 1 1 YES TAG20110929T120531
387 B A X SBT_TAPE 29/09/2011 12:56:42 1 1 YES TAG20110929T125641
388 B A X SBT_TAPE 29/09/2011 12:56:42 1 1 YES TAG20110929T125641
390 B F X SBT_TAPE 29/09/2011 13:22:11 1 1 NO TAG20110929T132206
RMAN> LIST BACKUP SET 390;
List of Backup Sets===================BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
390 Full 14.25M SBT_TAPE 00:00:05 29/09/2011 13:22:11 
BP Key: 5105 Status: EXPIRED Compressed: NO Tag: TAG20110929T132206 
Handle: BILIVE.c-3181441601-20110929-01.oraclebi1.controlfile Media: 000327L3 
Control File Included: Ckp SCN: 16039296565 Ckp time: 18/10/2011 20:51:29 
SPFILE Included: Modification time: 26/09/2011 07:00:04 
SPFILE db_unique_name: ABC 
RMAN> RUN { SET UNTIL SCN 16039296565 
RESTORE DATABASE: 
RECOVER DATABASE:} 
RMAN> ALTER DATABASE OPEN RESTLOGS;

RECOVER SP FILE

1. SET DBID $v_dbid; rman < set DBID=12345;
2. STARTUP NOMOUNT FORCE;
3. RESTORE SPFILE FROM AUTOBACKUP; or RESTORE SPFILE FROM 'PATH_OF_BACKUP'

No comments:

Post a Comment