CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters...

33
CHAPTER 19 RMAN Restore and Recovery

Transcript of CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters...

Page 1: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

CHAPTER 19RMAN Restore and Recovery

Page 2: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Introduction to RMAN Restore and Recovery

• Prior two chapters prepares you to be able to perform perhaps the most critical DBA tasks: restore and recovery of a damaged mission critical database.

• Good news is that RMAN automates much of the restore and recovery process.

Page 3: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Determining Media Recovery Required

• Media recovery error is thrown when Oracle can’t read or write to a critical database file:

ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

ORA-01110: data file 1: '/u02/oracle/oradata/E64208/system01.dbf'

Page 4: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Performing Media Recovery

1. Determine what files need to be restored.

2. Depending on the damage, set your database mode to nomount, mount, or open.

3. Use the RESTORE command to retrieve files from RMAN backups.

4. Use the RECOVER command for datafiles requiring recovery.

5. Open your database.

Page 5: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Using Data Recovery Advisor• Listing failures:

RMAN> list failure;

• Suggesting corrective action:

RMAN> advise failure 665;

• Running commands to repair failures:

RMAN> repair failure;

Page 6: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Using RMAN to Shutdown/Startup • You can use RMAN to shutdown and startup your

database.• Many times during a restore and recovery scenario, it’s

easier to use RMAN top stop/start your database.

RMAN> shutdown immediate;

RMAN> .....

RMAN> startup;

Page 7: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Previewing Backups Used for Recovery

• Use the RESTORE...PREVIEW command to list the backups and archive redo log files that RMAN will use to restore and recover database datafiles.

• The RESTORE...PREVIEW does not actually restore any files.

RMAN> restore database preview;

RMAN> restore database preview summary;

Page 8: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Validating Backup Files Before Restoring

• Instruct RMAN to verify that the files exist and check the file headers, the use the RESTORE...VALIDATE HEADER command like so:

•  

RMAN> restore database validate header;

• Further instruct RMAN to verify the integrity of blocks within backup files required to restore the database datafiles via the RESTORE...VALIDATE command:

RMAN> restore database validate;

Page 9: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Testing Media Recovery• Instruct RMAN to verify the recovery process via the

RECOVER...TEST command:

RMAN> connect target /

RMAN> startup mount;

RMAN> restore tablespace users;

RMAN> recover tablespace users test;

Page 10: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Entire Database Using Current Control File• This example assumes that you haven’t lost the control

files as part of the media failure:

RMAN> connect target /

RMAN> startup mount;

RMAN> restore database;

RMAN> recover database;

RMAN> alter database open;

Page 11: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Entire Database Using Backup Control File• This example assumes that you have lost the current

control files as part of the media failure:

RMAN> connect target /

RMAN> startup nomount;

RMAN> restore controlfile from autobackup;

RMAN> alter database mount;

RMAN> restore database;

RMAN> recover database;

RMAN> alter database open resetlogs;

Page 12: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Tablespace While Database is Open

• Do this is you have an isolated tablespace that needs its datafiles to be restored and recovered:

RMAN> connect target /

RMAN> sql 'alter tablespace users offline immediate';

RMAN> restore tablespace users;

RMAN> recover tablespace users;

RMAN> sql 'alter tablespace users online';

Page 13: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Tablespace While Database in Mount Mode• You can also restore tablespace datafiles while the

database is in mount mode:

RMAN> connect target /

RMAN> shutdown immediate;

RMAN> startup mount;

RMAN> restore tablespace system;

RMAN> recover tablespace system;

RMAN> alter database open;

Page 14: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Read-Only Tablespaces• RMAN will restore read-only tablespaces along with the

rest of the database when you issue a RESTORE DATABASE command:

RMAN> restore database;

• This is different in versions prior to 11g where you had to specify that read-only tablespaces were restored.

Page 15: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Temporary Tablespaces• RMAN doesn’t backup temporary tablespaces.• Starting with Oracle Database 10g, you don’t have to

restore or re-create missing locally managed temporary tablespace tempfiles.

• When you open your database for use, Oracle automatically detects and re-creates locally managed temporary tablespace tempfiles.

Page 16: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Datafile While Database Is Open

• Use the RESTORE DATAFILE and RECOVER DATAFILE commands to restore and recover at the datafile level.

• When your database is open, you’re required to take offline any datafiles you’re attempting to restore and recover.

RMAN> sql 'alter database datafile 32, 33 offline';

RMAN> restore datafile 32, 33;

RMAN> recover datafile 32, 33;

RMAN> sql 'alter database datafile 32, 33 online';

Page 17: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Datafile While Database Is Not Open

• You can only restore the system datafile while the database is not open:

RMAN> connect target /

RMAN> shutdown abort;

RMAN> startup mount;

RMAN> restore datafile 1;

RMAN> recover datafile 1;

RMAN> alter database open;

Page 18: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Datafiles to Non-Default Locations

• Sometimes a failure will occur that renders the disks associated with a mount point inoperable.

• In situations like this, you will need to restore and recover the datafiles to a different location from where they originally resided.

RMAN> connect target /

RMAN> startup mount;

RMAN> run{

2> set newname for datafile 32 to '/ora02/dbfile/O11R2/mvdata01.dbf';

3> set newname for datafile 33 to '/ora02/dbfile/O11R2/mvindex01.dbf';

4> restore datafile 32, 33;

5> switch datafile all; # Updates repository with new datafile location.

6> recover datafile 32, 33;

7> alter database open;

8> }

Page 19: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Performing Block Level Recovery• Block-level corruption is rare and is usually caused by

some sort of I/O error.• However, if you do have an isolated corrupt block within a

large datafile, it’s nice to have the option of performing a block-level recovery.

• Block-level recovery is useful when a small number of blocks are corrupt within a datafile.

• Block recovery is not appropriate if the entire datafile needs media recovery.

RMAN> recover datafile 5 block 20;

Page 20: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Archive Redo Logs to the Default Location• RMAN will automatically restore any archived redo log

files that it needs during a recovery process.• You normally don't need to manually restore archived redo

log files. • However, if you need to, you can restore all via:

RMAN> restore archivelog all;

Page 21: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring Archive Redo Logs to the Non-Default Location• Sometimes the default location may not be available (due

to media failure) or it may not have enough room.• Use SET ARCHIVELOG DESTINATION

RMAN> run{

2> set archivelog destination to '/ora01/archtemp';

3> restore archivelog from sequence 68 force;

4> }

Page 22: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring the Spfile• RMAN allows you to restore the spfile• You may have one of the following scenarios:

• You accidentally set a value in the spfile that keeps your instance from starting.

• You accidentally deleted the spfile.• You are required to see what it looked like at some time in the past.

• If you are using a recovery catalog, it’s a fairly simple procedure to restore the spfile:

RMAN> connect target /

RMAN> connect catalog rmancat/foo@rcat

RMAN> startup nomount;

RMAN> restore spfile;

Page 23: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring a Control File Using a Recovery Catalog• If you lose all of your control files, then you’ll need to

restore one from a backup:

RMAN> connect target /

RMAN> connect catalog rcat/rcat@recov

RMAN> startup nomount;

RMAN> list backup of controlfile;

Page 24: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring a Control File Using an Autobackup Restore• If you’re using the autobackup of the control file feature,

it’s fairly simple to restore a control file:

RMAN> connect target /

RMAN> startup nomount;

RMAN> restore controlfile from autobackup;

Page 25: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Performing Time-Based Recovery Incomplete Recovery• Time based is appropriate when you have a specific time

in the past you’d like to reset the database to:

RMAN> connect target /

RMAN> startup mount;

RMAN> restore database until time

2> "to_date('04-sep-2010 14:00:00', 'dd-mon-rrrr hh24:mi:ss')";

RMAN> recover database until time

2> "to_date('04-sep-2010 14:00:00', 'dd-mon-rrrr hh24:mi:ss')";

RMAN> alter database open resetlogs;

Page 26: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Performing Log Sequenced-Based Recovery Incomplete Recovery• Use this type of incomplete recovery when you’re missing

an archive log or required online redo log:

RMAN> connect target /

RMAN> startup mount;

RMAN> restore database until sequence 45;

RMAN> recover database until sequence 45;

RMAN> alter database open resetlogs;

Page 27: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Performing Change/SCN-Based Incomplete Recovery• If you know the SCN number to which you’d like to restore

to in the past, then use SCN-based incomplete recovery:

RMAN> connect target /

RMAN> startup mount;

RMAN> restore database until scn 95019865425;

RMAN> recover database until scn 95019865425;

RMAN> alter database open resetlogs;

Page 28: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring to a Restore Point• RMAN also allows you to restore back to a restore point:

RMAN> connect target /

RMAN> startup mount;

RMAN> restore database until restore point MY_RP;

RMAN> recover database until restore point MY_RP;

RMAN> alter database open resetlogs;

Page 29: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Table Level Restore• New in Oracle Database 12c, table level restore• Allows you to use RMAN to restore a table based on

SCN, time, or log sequence number• Consider using flashback table to restore a table instead

of RMAN table level restore

Page 30: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Flashing Back a Table• Flashback to before drop (uses recyclebin)• Flashback to prior point in time (uses undo)

Page 31: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Flashback Database• Another form of incomplete recovery• Often used as a mechanism to set a database back to a

prior state• Prior to an application upgrade, create a restore point, if

the application upgrade goes bad, flashback database to the restore point

Page 32: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Restoring and Recovering to Different Server

1. Create an RMAN backup on the originating database.

2. Copy RMAN backup to the destination server. All steps after this step are performed on the destination database server.

3. Ensure that Oracle is installed.

4. Source the required OS variables.

5. Create an init.ora file for the database to be restored.

6. Create any required directories for datafiles, control files, and dump/trace files.

7. Startup the database in NOMOUNT mode.

8. Restore a control file from the RMAN backup.

9. Startup the database in MOUNT mode.

10. Make the control file aware of the location of the RMAN backups.

11. Rename and restore the datafiles to reflect new directory locations.

12. Recover the database.

13. Set the new location for the online redo logs.

14. Open the database.

15. Add tempfile.

16. Rename the database.

Page 33: CHAPTER 19 RMAN Restore and Recovery. Introduction to RMAN Restore and Recovery Prior two chapters prepares you to be able to perform perhaps the most.

Summary• RMAN automates most of the restore and recovery tasks.• Very flexible in ways to perform complete and incomplete

recovery.• Arguably restore and recovery are the most critical skills a

DBA can posses.