其他恢复技术总结 —— Logminer, DBPITR, TSPITR(1)

前言:Flashback 技术之外,Oracle 还提供了其他很多有用的恢复工具和方法,本次针对Logminer, DBPITR, TSPITR做一个总结。

//=============================================================
//Point-in-Time Recovery to an Ancestor Incarnation
//=============================================================

To perform. point-in-time recovery to the older incarnation, use the following steps:

1. Determine which incarnation was current at the time of the backup of 2 October.
Use LISTINCARNATION to find the primary key of the incarnation that was
current at the target time:

LIST INCARNATION OF DATABASE trgt;

2. Make sure the database is started but not mounted.

STARTUP FORCE NOMOUNT

3. Reset trgt to the incarnation that was current at the time of the backup of 2
October. Use the value from the Inc Key column to identify the incarnation.


# reset database to old incarnation
RESET DATABASE TO INCARNATION 2;

4. Restore and recover the database, performing the following actions in the RUN
command:

RUN
{
# set target time for all operations in the RUN block
SET UNTIL TIME 'Oct 8 2004 07:55:00';
RESTORE CONTROLFILE ;
# without recovery catalog, use RESTORE CONTROLFILE FROM AUTOBACKUP
ALTER DATABASE MOUNT;
RESTORE DATABASE;
RECOVER DATABASE;
}

5.ALTER DATABASE OPEN RESETLOGS;

//接着我上次Flashback database to undo resetlogs的例子,我本想回到 incarnation 1的SCN=294578078的时候(在FLASHBACK DATABASE那个例子的开始),那个时候是刚刚delete了'Hangzhou'那条记录,只剩下'Beijing'和'Shanghai'。

//可是,苍天啊,我竟然把我之前的所有backup全删除了!!!014.gif做Database Point In Time Recovery,没有备份集,怎么做哦...无奈,只好纪录过程,搞清楚原理,以后碰到也好有个参考~~~

PS:在current incarnation做DBPITR就很简单了:

1.
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;

2.

RUN
{
SET UNTIL SCN 1000;
# Alternatives:
# SET UNTIL TIME 'Nov 15 2004 09:00:00';
# SET UNTIL SEQUENCE 9923;
RESTORE DATABASE;
RECOVER DATABASE;
}

3.

ALTER DATABASE OPEN RESETLOGS;

//===========================================================
//Tablespace point in time recovery.
//===========================================================


You have a few different options available to you:

Fully automated TSPITR--in which you specify an auxiliary destination and let
RMAN manage all aspects of the TSPITR. This is the simplest way to perform
TSPITR, and is recommended unless you specifically need more control over the location of recovery set files after TSPITR or auxiliary set files during TSPITR, or control over the channel configurations or some other aspect of your auxiliary
instance.


Customized TSPITR with an automatic auxiliary instance--in which you base
your TSPITR on the behavior. of fully automated TSPITR, possibly still using an
auxiliary destination, but customize one or more aspects of the behavior, such as the location of auxiliary set or recovery set files, or specifying initialization
parameters or channel configurations for the auxiliary instance created and
managed by RMAN.


TSPITR with your own auxiliary instance--in which you take responsibility for
setting up, starting, stopping and cleaning up the auxiliary instance used in
TSPITR, and possibly also manage the TSPITR process using some of the methods.


//Fully automated TSPITR -- recommended(我只测试了这一种)~~~

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\p485224>set oracle_sid=ora10gbr

C:\Documents and Settings\p485224>sqlplus

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Apr 24 12:33:43 2008

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

Enter user-name: sys as sysdba
Enter password:

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     20
Next log sequence to archive   22
Current log sequence           22
SQL>
SQL> set linesize 200
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------
         1          1         22   52428800          1 NO  CURRENT                 534000 24-APR-08
         2          1         20   52428800          1 YES INACTIVE                429836 22-APR-08
         3          1         21   52428800          1 YES INACTIVE                483703 23-APR-08
SQL>
SQL> conn john/john
Connected.
SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
NAMELIST
TESTVERSION
TESTBIN

SQL> create table tspitr (id number(10),
  2  name varchar2(20));

Table created.

SQL> insert into tspitr values ('1', 'John');

1 row created.

SQL> insert into tspitr values ('2','Gavin');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL>
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------
         1          1         22   52428800          1 YES ACTIVE                  534000 24-APR-08
         2          1         23   52428800          1 NO  CURRENT                 553204 24-APR-08
         3          1         21   52428800          1 YES INACTIVE                483703 23-APR-08

SQL> insert into tspitr values ('3','Jack');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile;

System altered.

SQL> show user;
USER is "JOHN"
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------
         1          1         22   52428800          1 YES ACTIVE                  534000 24-APR-08
         2          1         23   52428800          1 YES ACTIVE                  553204 24-APR-08
         3          1         24   52428800          1 NO  CURRENT                 553282 24-APR-08

SQL>
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------
         1          1         22   52428800          1 YES INACTIVE                534000 24-APR-08
         2          1         23   52428800          1 YES INACTIVE                553204 24-APR-08
         3          1         24   52428800          1 NO  CURRENT                 553282 24-APR-08

SQL> archive log list;
ORA-01031: insufficient privileges
SQL> conn sys/oracle as sysdba
Connected.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     22
Next log sequence to archive   24
Current log sequence           24
SQL>
SQL> conn john/john
Connected.
SQL>
SQL> insert into tspitr values (4,'Jeff');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system switch logfile; //After this action, log 25 becomes current.

System altered.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------
         1          1         25   52428800          1 NO  CURRENT                 554286 24-APR-08
         2          1         23   52428800          1 YES INACTIVE                553204 24-APR-08
         3          1         24   52428800          1 YES ACTIVE                  553282 24-APR-08

SQL>


RMAN> recover tablespace users until sequence 24 thread 1 auxiliary

//汗,其实整个过程也就这一句话...

destination 'D:\ora_bak\RMAN\auxiliary';

Starting recover at 24-APR-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=139 devtype=DISK
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='Eetc'

initialization parameters used for automatic instance:
db_name=ORA10GBR
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_ORA10GBR_Eetc
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=D:\ora_bak\RMAN\auxiliary
control_files=D:\ora_bak\RMAN\auxiliary/cntrl_tspitr_ORA10GBR_Eetc.f


starting up automatic instance ORA10GBR

Oracle instance started

Total System Global Area     205520896 bytes

Fixed Size                     1248092 bytes
Variable Size                146801828 bytes
Database Buffers              50331648 bytes
Redo Buffers                   7139328 bytes
Automatic instance created

contents of Memory Script.:
{
# set the until clause
set until  logseq 24 thread 1;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
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 24-APR-08
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\AUTOBACKUP\2008_04_21\O1_MF_S_652637113_40RLQX02_.BKP
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\AUTOBACKUP\2008_04_21\O1_MF_S_652637113_40RLQX02_.BKP tag=TAG20080421T160620
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=D:\ORA_BAK\RMAN\AUXILIARY\CNTRL_TSPITR_ORA10GBR_EETC.F
Finished restore at 24-APR-08

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
released channel: ORA_DISK_1
released channel: ORA_AUX_DISK_1

contents of Memory Script.:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  logseq 24 thread 1;
plsql <<declare
  sqlstatement       varchar2(512);
  offline_not_needed exception;
  pragma exception_init(offline_not_needed, -01539);
begin
  sqlstatement := 'alter tablespace '||  'USERS' ||' offline for recover';
  krmicd.writeMsg(6162, sqlstatement);
  krmicd.execSql(sqlstatement);
exception
  when offline_not_needed then
    null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile  1 to new;
# set an omf destination filename for restore
set newname for clone datafile  2 to new;
# set an omf destination tempfile
set newname for clone tempfile  1 to new;
# set a destination filename for restore
set newname for datafile  4 to
 "D:\OPT\ORADATA\ORA10GBR\USERS01.DBF";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile  1, 2, 4;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile  1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile  4 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace  "USERS", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
#           datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script

executing command: SET until clause

sql statement: alter tablespace USERS offline for recover

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed temporary file 1 to D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_TEMP_%U_.TMP in control file

Starting restore at 24-APR-08
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=39 devtype=DISK

channel ORA_AUX_DISK_1: restoring datafile 00001
input datafile copy recid=1 stamp=652466762 filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\BACKUPSET\2008_04_19\SYSTEM01.DBF
destination for restore of datafile 00001: D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_SYSTEM_%U_.DBF
channel ORA_AUX_DISK_1: copied datafile copy of datafile 00001
output filename=D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_SYSTEM_4107YX6H_.DBF recid=3 stamp=652888297
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_UNDOTBS1_%U_.DBF
restoring datafile 00004 to D:\OPT\ORADATA\ORA10GBR\USERS01.DBF
channel ORA_AUX_DISK_1: reading from backup piece D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\BACKUPSET\2008_04_19\O1_MF_NNNDF_TAG20080419T163947_40MCYMW5_.BKP
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\BACKUPSET\2008_04_19\O1_MF_NNNDF_TAG20080419T163947_40MCYMW5_.BKP tag=TAG20080419T163947
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
Finished restore at 24-APR-08

datafile 1 switched to datafile copy
input datafile copy recid=6 stamp=652888316 filename=D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_SYSTEM_4107YX6H_.DBF
datafile 2 switched to datafile copy
input datafile copy recid=7 stamp=652888316 filename=D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_UNDOTBS1_4107ZF8F_.DBF

sql statement: alter database datafile  1 online

sql statement: alter database datafile  2 online

sql statement: alter database datafile  4 online

Starting recover at 24-APR-08
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 18 is already on disk as file D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_21\O1_MF_1_18_40QH96OG_.ARC
archive log thread 1 sequence 19 is already on disk as file D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_22\O1_MF_1_19_40SRZM8Z_.ARC
archive log thread 1 sequence 20 is already on disk as file D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_23\O1_MF_1_20_40WVJTKO_.ARC
archive log thread 1 sequence 21 is already on disk as file D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_24\O1_MF_1_21_40Z1THFW_.ARC
archive log thread 1 sequence 22 is already on disk as file D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_24\O1_MF_1_22_4103MF0J_.ARC
archive log thread 1 sequence 23 is already on disk as file D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_24\O1_MF_1_23_4103NO60_.ARC
archive log filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_21\O1_MF_1_18_40QH96OG_.ARC thread=1 sequence=18
archive log filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_22\O1_MF_1_19_40SRZM8Z_.ARC thread=1 sequence=19
archive log filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_23\O1_MF_1_20_40WVJTKO_.ARC thread=1 sequence=20
archive log filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_24\O1_MF_1_21_40Z1THFW_.ARC thread=1 sequence=21
archive log filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_24\O1_MF_1_22_4103MF0J_.ARC thread=1 sequence=22
archive log filename=D:\OPT\FLASH_RECOVERY_AREA\ORA10GBR\ARCHIVELOG\2008_04_24\O1_MF_1_23_4103NO60_.ARC thread=1 sequence=23
media recovery complete, elapsed time: 00:00:16
Finished recover at 24-APR-08

database opened

contents of Memory Script.:
{
# export the tablespaces in the recovery set
host 'exp userid =\"
/@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=oracle)(ARGV0=oracleEetc)(ARGS=^'(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))^')(EN
VS=^'ORACLE_SID=Eetc^'))(CONNECT_DATA=(SID=Eetc))) as sysdba\" point_in_time_recover=y tablespaces=
 USERS file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"/@ as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace  USERS online";
sql "alter tablespace  USERS offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script


Export: Release 10.2.0.1.0 - Production on Thu Apr 24 13:52:25 2008

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: table data (rows) will not be exported

About to export Tablespace Point-in-time Recovery objects...
For tablespace USERS ...
. exporting cluster definitions
. exporting table definitions
. . exporting table                       NAMELIST
. . exporting table                        TESTBIN
. . exporting table                    TESTVERSION
. . exporting table                         TSPITR
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings.
host command complete

database closed
database dismounted
Oracle instance shut down


Import: Release 10.2.0.1.0 - Production on Thu Apr 24 13:52:40 2008

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


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing JOHN's objects into JOHN
. . importing table                     "NAMELIST"
. . importing table                      "TESTBIN"
. . importing table                  "TESTVERSION"
. . importing table                       "TSPITR"
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete

sql statement: alter tablespace  USERS online

sql statement: alter tablespace  USERS offline

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

Removing automatic instance
Automatic instance removed
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\CNTRL_TSPITR_ORA10GBR_EETC.F deleted
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_SYSTEM_4107YX6H_.DBF deleted
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_UNDOTBS1_4107ZF8F_.DBF deleted
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\DATAFILE\O1_MF_TEMP_41080MYC_.TMP deleted
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\ONLINELOG\O1_MF_1_41080HG7_.LOG deleted
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\ONLINELOG\O1_MF_2_41080JGQ_.LOG deleted
auxiliary instance file D:\ORA_BAK\RMAN\AUXILIARY\TSPITR_O\ONLINELOG\O1_MF_3_41080KCS_.LOG deleted
Finished recover at 24-APR-08

RMAN>

//到此为止都是auto的~~~不过了解整个过程oracle都做了些什么还是很有帮助的哦:)

SQL> select * from tspitr;
select * from tspitr
              *
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: 'D:\OPT\ORADATA\ORA10GBR\USERS01.DBF'

SQL> select tablespace_name , status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
UNDOTBS1                       ONLINE
SYSAUX                         ONLINE
TEMP                           ONLINE
USERS                          OFFLINE

SQL> alter tablespace users online; //Actually, before taking the tablespace online, you should backup it:)  'BACKUP TABLESPACE users;'

Tablespace altered.

SQL> select * from tspitr;

        ID NAME
---------- --------------------
         1 John
         2 Gavin
         3 Jack
//From the result we can see that until sequence 24 means not include log 24!!!

[To be continued...]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9765498/viewspace-259933/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9765498/viewspace-259933/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值