13 Aralık 2012 Perşembe

              
              Tablespace Point-in-time Recovery(TSPITR)

      TSPITR ile sistemde  zarar görmüş tablespace istenilen zamana a recover edilebilir.Recover işleminde istenilen zaman  için database scn veya istenilen zaman kullanılabilinir.Bunu yaparken diğer tablespace ve objeler bu durumdan etkilenmez.

Ne zaman TSPITR:
1)Yanlışlıkla truncate table uygulandığında
2)Logical corruptionlar yaşandığında.
3)Logical bir sechemayı belli bir zamana recover etmek istediğimizde
NOT:Eğer archive log dosyalarına sahip değilsek TSPITR yapamayız.Yani noarchileog modda olan bir database de TSPITR uygulanamaz.


TSPITR Kısıtlamaları:
1)Drop edilen table recover edilemez.
2)Yeniden adlandırılmış bir tablespace adlandırmadan önceki bir  zamana recover edilemez.Eğer bunu gerçekleştirmeyi denersek backup repository tablespace için yeni adıyla bakacağından dolayı doğru backup bulamayacaktır ve fail olacaktır.
3)Bir tabloyu kendisine bağlı bağlı tablolar olmadan recovery edemeyiz.
4)TSPITR ile bir tabloyu recover etmek istediğimiz zaman o tablonun bulunduğu tüm table space kullanırız.
5)Undo ve roolback segmentlerini içeren tablespace recover edemeyiz.


 Tablespace Point in Time Recovery:

1)En başta herhangi bir işlem yapmadan database backup aldım.
   Rman>backup database plus archivelog:

2)Test için bir table space ve default tablespace bu tablespace olan bir user create ettim.
  SQL>create tablespace staff datafile '/u01/app/oracle/oradata/company/staffinf.dbf' size 100M;
  SQL>create user yasin identified by oracle default tablespace staff;


3)Bu schemda tablolarımı oluşturdum. Tablolarımı oluşturduktan sonra işlemin zamanına bakmalıyım. Çünkü tablespace recover ederken bu süre benim time-in-recovery belirtecek(current scn numarasına da bakılabilir.)
SQL>create table foo_1 (v varchar2(15));
SQL>create table foo_2 (v varchar2(15));
SQL>insert into foo_1 values ('lorem');
SQL>insert into foo_1 values ('ipsum');
SQL>insert into foo_1 values ('dolor');
SQL>insert into foo_1 values ('sit');
SQL>insert into foo_1 values ('amet');
SQL>insert into foo_2 values ('nonummy');
SQL>insert into foo_2 values ('nibh');
SQL>insert into foo_2 values ('euismod');
SQL>insert into foo_2 values ('tincidunt');
SQL>insert into foo_2 values ('ut');


4)Sonra foo_1 ve foo_2 tablosunda bulunan data yı sildim.
   SQL>truncate table foo_1;
   SQL>truncate table foo_2; 


5)Daha sonra revocer işlemimi gerçekleştirdim.
  Rman>recover tablespace staff until time "to_date('20-SEP-2012 10:22:00', 'DD-MON-YYYY HH24:MI:SS')" auxiliary destination='/backup';-->Bu komutla staff tablespace istenilen zaman daki haline recover edilir.

Starting recover at 20-SEP-12
using channel ORA_DISK_1
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1

Creating automatic instance, with SID='iqks'

initialization parameters used for automatic instance:
db_name=COMPANY
db_unique_name=iqks_tspitr_COMPANY
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/backup
log_archive_dest_1='location=/backup'
#No auxiliary parameter file used


starting up automatic instance COMPANY

Oracle instance started

Total System Global Area     292278272 bytes

Fixed Size                     2212736 bytes
Variable Size                100666496 bytes
Database Buffers             184549376 bytes
Redo Buffers                   4849664 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('20-SEP-2012 10:22:00', 'DD-MON-YYYY HH24:MI:SS')";
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 20-SEP-12
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /backup/COMPANY/backupset/2012_09_20/o1_mf_ncsnf_TAG20120920T101957_85ojyp1h_.bkp
channel ORA_AUX_DISK_1: piece handle=/backup/COMPANY/backupset/2012_09_20/o1_mf_ncsnf_TAG20120920T101957_85ojyp1h_.bkp tag=TAG20120920T101957
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/backup/COMPANY/controlfile/o1_mf_85okp1c3_.ctl
Finished restore at 20-SEP-12

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('20-SEP-2012 10:22:00', 'DD-MON-YYYY HH24:MI:SS')";
plsql <<<-- br="br" tspitr_2="tspitr_2">declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'STAFF' ||' offline immediate';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
set newname for datafile  5 to
 "/u01/app/oracle/oradata/company/staffinf.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2, 5;
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace STAFF offline immediate

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /backup/COMPANY/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 20-SEP-12
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /backup/COMPANY/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /backup/COMPANY/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /backup/COMPANY/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/company/staffinf.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/COMPANY/backupset/2012_09_20/o1_mf_nnndf_TAG20120920T101957_85ojwyk1_.bkp
channel ORA_AUX_DISK_1: piece handle=/backup/COMPANY/backupset/2012_09_20/o1_mf_nnndf_TAG20120920T101957_85ojwyk1_.bkp tag=TAG20120920T101957
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 20-SEP-12

datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=794486052 file name=/backup/COMPANY/datafile/o1_mf_system_85okp7kd_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=794486052 file name=/backup/COMPANY/datafile/o1_mf_undotbs1_85okp7o6_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=794486052 file name=/backup/COMPANY/datafile/o1_mf_sysaux_85okp7l7_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('20-SEP-2012 10:22:00', 'DD-MON-YYYY HH24:MI:SS')";
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
sql clone "alter database datafile  5 online";
# recover and open resetlogs
recover clone database tablespace  "STAFF", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  5 online

Starting recover at 20-SEP-12
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 4 is already on disk as file /backup/COMPANY/archivelog/2012_09_20/o1_mf_1_4_85ojyq8k_.arc
archived log for thread 1 with sequence 5 is already on disk as file /backup/COMPANY/archivelog/2012_09_20/o1_mf_1_5_85ok5wcx_.arc
archived log file name=/backup/COMPANY/archivelog/2012_09_20/o1_mf_1_4_85ojyq8k_.arc thread=1 sequence=4
archived log file name=/backup/COMPANY/archivelog/2012_09_20/o1_mf_1_5_85ok5wcx_.arc thread=1 sequence=5
media recovery complete, elapsed time: 00:00:01
Finished recover at 20-SEP-12

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace  STAFF read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/backup''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/backup''";
}
executing Memory Script

sql statement: alter tablespace  STAFF read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/backup''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/backup''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_iqks": 
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_iqks" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_iqks is:
   EXPDP>   /backup/tspitr_iqks_27958.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace STAFF:
   EXPDP>   /u01/app/oracle/oradata/company/staffinf.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_iqks" successfully completed at 10:35:21
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace  STAFF including contents keep datafiles';
}
executing Memory Script

database closed
database dismounted
Oracle instance shut down

sql statement: drop tablespace  STAFF including contents keep datafiles

Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_iqks" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_iqks": 
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_iqks" successfully completed at 10:35:38
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace  STAFF read write';
sql 'alter tablespace  STAFF offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace  STAFF read write

sql statement: alter tablespace  STAFF offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /backup/COMPANY/datafile/o1_mf_temp_85okqtw4_.tmp deleted
auxiliary instance file /backup/COMPANY/onlinelog/o1_mf_3_85okqrn9_.log deleted
auxiliary instance file /backup/COMPANY/onlinelog/o1_mf_2_85okqq57_.log deleted
auxiliary instance file /backup/COMPANY/onlinelog/o1_mf_1_85okqp9r_.log deleted
auxiliary instance file /backup/COMPANY/datafile/o1_mf_sysaux_85okp7l7_.dbf deleted
auxiliary instance file /backup/COMPANY/datafile/o1_mf_undotbs1_85okp7o6_.dbf deleted
auxiliary instance file /backup/COMPANY/datafile/o1_mf_system_85okp7kd_.dbf deleted
auxiliary instance file /backup/COMPANY/controlfile/o1_mf_85okp1c3_.ctl deleted
Finished recover at 20-SEP-12


6)Recovery  işleminden sonra recover ettiğimiz datafile  offline olarak görülür.Recovery edilen data okunmak istendiğinde hata verecektir. Bu işlemden önce tablespace online yapmalıyız.
 SQL>select name,status from v$datafile;
 NAME                                                STATUS 
--------------------------------------------------- ---------- 
/u01/app/oracle/oradata/company/system01.dbf           SYSTEM 
/u01/app/oracle/oradata/company/undotbs01.dbf          ONLINE 
/u01/app/oracle/oradata/company/sysaux01.dbf           ONLINE 
/u01/app/oracle/oradata/company/users01.dbf            ONLINE 
/u01/app/oracle/oradata/company/company.dbf             OFFLINE

SQL>alter tablespace staff online;
SQL>select name,status from v$datafile;
 NAME                                                STATUS 
--------------------------------------------------- ---------- 
/u01/app/oracle/oradata/company/system01.dbf           SYSTEM 
/u01/app/oracle/oradata/company/undotbs01.dbf          ONLINE 
/u01/app/oracle/oradata/company/sysaux01.dbf           ONLINE 
/u01/app/oracle/oradata/company/users01.dbf            ONLINE 
/u01/app/oracle/oradata/company/company.dbf            ONLINE





Hiç yorum yok: