Tuesday, August 14, 2007

Flash Recovery Practice

Flash Recovery Practice
=========================
Env: Oracle 10gR2

1. Display init.ora parameter

sys@TOY10G> show parameter db_recover

NAME TYPE VALUE
------------------------------------ -----------
------------------------------
db_recovery_file_dest string
/ora01/orabkup/GENQ/.temp_toy1

0g/ora01/orarcv/TOY10G
db_recovery_file_dest_size big integer 2G

2. Connect to target database

dfsdb1:TOY10G: /ora01/orabkup/GENQ/.temp_toy10g/oracle/admin/TOY10G >
rman

Recovery Manager: Release 10.2.0.3.0 - Production on Tue Aug 14
08:54:08 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

RMAN> connect target

connected to target database: TOY10G (DBID=3330944552)

RMAN>

3. Check default backup location is same as db_recovery_file_dest
RMAN> show all;

RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';
# default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; #
default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; #
default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT
'/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/%rec_area_%s_%p.ba
k';
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/oracle/product/10.2.0/db_1/dbs/snapcf_TOY10G.f'; # default


4. Create a dummy table t1 from all_objects

scott@TOY10G> create table t1 as select * from all_objects;

Table created.

scott@TOY10G> select count(*) from t1;

COUNT(*)
----------
9531


5. Perform a backup of target database

RMAN> backup as copy database;
Starting backup at 14-AUG-2007 09:25:12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=30 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001
name=/ora01/orabkup/GENQ/.temp_toy10g/ora01/oradata/TOY10G/system01.dbf
output
filename=/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/%rec_area_
33_1.bak tag=TAG20070814T092512 recid=21 stamp=630581119
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003
name=/ora01/orabkup/GENQ/.temp_toy10g/ora01/oradata/TOY10G/sysaux01.dbf
output
filename=/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/%rec_area_
34_1.bak tag=TAG20070814T092512 recid=22 stamp=630581126
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004
name=/ora01/orabkup/GENQ/.temp_toy10g/ora01/oradata/TOY10G/users01.dbf
output
filename=/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/%rec_area_
35_1.bak tag=TAG20070814T092512 recid=23 stamp=630581127
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005
name=/ora01/orabkup/GENQ/.temp_toy10g/ora01/oradata/TOY10G/indx01.dbf
output
filename=/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/%rec_area_
36_1.bak tag=TAG20070814T092512 recid=24 stamp=630581128
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002
name=/ora01/orabkup/GENQ/.temp_toy10g/ora01/oradata/TOY10G/undotbs01.dbf
output
filename=/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/%rec_area_
37_1.bak tag=TAG20070814T092512 recid=25 stamp=630581129
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 14-AUG-2007 09:25:30

Starting Control File and SPFILE Autobackup at 14-AUG-2007 09:25:30
piece
handle=/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G/TOY10G/autob
ackup/2007_08_14/o1_mf_s_630581130_3d3gttsp_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 14-AUG-2007 09:25:32

6. Query the V$RECOVERY_FILE_DEST to determine if the SPACE_USED column
(verify we have backups)

sys@TOY10G> select * from v$recovery_file_dest;

NAME

------------------------------------------------------------------------
----------------------------
SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
----------- ---------- ----------------- ---------------
/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G
2147483648 44187648 37781504 7

sys@TOY10G> ho ls -lh
/ora01/orabkup/GENQ/.temp_toy10g/ora01/orarcv/TOY10G
total 2215666
-rw-r----- 1 oracle dba 500M Aug 14 09:25
%rec_area_33_1.bak
-rw-r----- 1 oracle dba 500M Aug 14 09:25
%rec_area_34_1.bak
-rw-r----- 1 oracle dba 46M Aug 14 09:25
%rec_area_35_1.bak
-rw-r----- 1 oracle dba 25M Aug 14 09:25
%rec_area_36_1.bak
-rw-r----- 1 oracle dba 10M Aug 14 09:25
%rec_area_37_1.bak
drwxr-x--- 3 oracle dba 512 Jun 12 11:04 TOY10G

7. Enable flash back feature

sys@TOY10G> select flashback_on from v$database;

FLASHBACK_ON
------------------
NO

7.1 Start the database in MOUNT mode:
7.2 Set the DB_FLASHBACK_RETENTION_TARGET parameter to the desired value
(in min).
sys@TOY10G> show parameter db_flash

NAME TYPE VALUE
------------------------------------ -----------
------------------------------
db_flashback_retention_target integer 1440

sys@TOY10G> alter system set db_flashback_retention_target=1445;

7.3. Enable the flashback capability:
sys@TOY10G> alter database flashback on;

7.4 Now the database can be opened for normal use:

sys@TOY10G> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES

8. Drop table t1 in SCOTT schema

scott@TOY10G> drop table t1;

Table dropped.

9. performing a Flashback Database recovery to a SCN
9.1 Query the V$FLASHBACK_DATABASE_LOG view to retrieve the
OLDEST_FLASHBACK_SCN:
Login as SYS

sys@TOY10G> select oldest_flashback_scn, oldest_flashback_time from
v$flashback_database_log;

OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIM
-------------------- --------------------
4235495 14-AUG-2007 09:45:02

9.2 shut down and start the database in MOUNT mode

9.3 issue the Flashback Database recovery from RMAN:
RMAN> connect target

connected to target database: TOY10G (DBID=3330944552, not open)

RMAN> flashback database to scn=4235495;

Starting flashback at 14-AUG-2007 10:19:48
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=45 devtype=DISK


starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished flashback at 14-AUG-2007 10:19:52

9.4 Open the database with the RESETLOGS option, because you recovered
to a time prior to the current database:
sys@TOY10G> alter database open resetlogs;

Database altered.

10. Check table t1 now:

scott@TOY10G> select count(*) from t1;

COUNT(*)
----------
9531

No comments: