您的位置:首页 > 运维架构

rman基于TSPITR恢复drop掉的表空间

2013-11-24 21:40 555 查看

rman基于TSPITR恢复drop掉的表空间

  今天是2013-11-24,在11.2之前无法使用tspitr技术恢复drop掉的表空间,但是到了11.2这个限制已经没有了。
测试如下:
SQL> select file_name from dba_data_files;

FILE_NAME

--------------------------------------------------------------------------------

/opt/app/oracle/oradata/RHYS/users01.dbf

/opt/app/oracle/oradata/RHYS/undotbs01.dbf

/opt/app/oracle/oradata/RHYS/sysaux01.dbf

/opt/app/oracle/oradata/RHYS/system01.dbf

/*创建表空间*/

SQL> create tablespace test datafile '/opt/app/oracle/oradata/RHYS/test.dbf' size 10M;

Tablespace created.

SQL> create user Amy identified by Rhys default tablespace test;

User created.

SQL> grant resource,create session to Amy;

Grant succeeded.

SQL> create table t as select * from scott.emp;

Table created.

SQL> commit;

Commit complete.
SQL> select sequence#,status from v$log where status='CURRENT';

 SEQUENCE# STATUS

---------- ----------------

        44 CURRENT

SQL> r

  1* insert into t select * from t

14336 rows created.

SQL> r

  1* insert into t select * from t

28672 rows created.

SQL> r

  1* insert into t select * from t

57344 rows created.

SQL> select count(*) from dba_objects;

  COUNT(*)

----------

     86369

SQL>

SQL> alter system switch logfile;

System altered.

SQL> r

  1* alter system switch logfile

System altered.
SQL> select sequence#,status from v$log where status='CURRENT';

 SEQUENCE# STATUS

---------- ----------------

        47 CURRENT

SQL>

/*备份数据库*/
[oracle@oracle-one ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Sun Nov 24 21:14:46 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: RHYS (DBID=2743302915)

RMAN> backup database include current controlfile plus archivelog delete input;

Starting backup at 24-NOV-13

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=44 device type=DISK

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=44 RECID=1 STAMP=832367526

input archived log thread=1 sequence=45 RECID=2 STAMP=832367599

input archived log thread=1 sequence=46 RECID=3 STAMP=832367602

input archived log thread=1 sequence=47 RECID=4 STAMP=832367712

channel ORA_DISK_1: starting piece 1 at 24-NOV-13

channel ORA_DISK_1: finished piece 1 at 24-NOV-13

piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_annnn_TAG20131124T211513_993yz1ph_.bkp tag=TAG20131124T211513 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/opt/app/oracle/fast_recovery_area/RHYS/archivelog/2013_11_24/o1_mf_1_44_993ys65q_.arc RECID=1 STAMP=832367526

archived log file name=/opt/app/oracle/fast_recovery_area/RHYS/archivelog/2013_11_24/o1_mf_1_45_993yvhpg_.arc RECID=2 STAMP=832367599

archived log file name=/opt/app/oracle/fast_recovery_area/RHYS/archivelog/2013_11_24/o1_mf_1_46_993yvl5d_.arc RECID=3 STAMP=832367602

archived log file name=/opt/app/oracle/fast_recovery_area/RHYS/archivelog/2013_11_24/o1_mf_1_47_993yz004_.arc RECID=4 STAMP=832367712

Finished backup at 24-NOV-13

Starting backup at 24-NOV-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/opt/app/oracle/oradata/RHYS/system01.dbf

input datafile file number=00004 name=/opt/app/oracle/oradata/RHYS/users01.dbf

input datafile file number=00002 name=/opt/app/oracle/oradata/RHYS/sysaux01.dbf

input datafile file number=00003 name=/opt/app/oracle/oradata/RHYS/undotbs01.dbf

input datafile file number=00005 name=/opt/app/oracle/oradata/RHYS/test.dbf

channel ORA_DISK_1: starting piece 1 at 24-NOV-13

channel ORA_DISK_1: finished piece 1 at 24-NOV-13

piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_nnndf_TAG20131124T211515_993yz4b0_.bkp tag=TAG20131124T211515 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 24-NOV-13

channel ORA_DISK_1: finished piece 1 at 24-NOV-13

piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_ncsnf_TAG20131124T211515_993z16f9_.bkp tag=TAG20131124T211515 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 24-NOV-13

Starting backup at 24-NOV-13

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=48 RECID=5 STAMP=832367783

channel ORA_DISK_1: starting piece 1 at 24-NOV-13

channel ORA_DISK_1: finished piece 1 at 24-NOV-13

piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_annnn_TAG20131124T211623_993z1821_.bkp tag=TAG20131124T211623 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: deleting archived log(s)

archived log file name=/opt/app/oracle/fast_recovery_area/RHYS/archivelog/2013_11_24/o1_mf_1_48_993z17qs_.arc RECID=5 STAMP=832367783

Finished backup at 24-NOV-13

RMAN>

/*删除表空间*/
[oracle@oracle-one ~]$ sqlplus / as sysdba

sel

SQL*Plus: Release 11.2.0.4.0 Production on Sun Nov 24 21:18:14 2013

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

e

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

S     

SQL> set linesize 200

SQL> select sequence#,status from v$log where status='CURRENT';

 SEQUENCE# STATUS

---------- ----------------

        49 CURRENT

SQL> drop tablespace test including contents and datafiles;

Tablespace dropped.

SQL> exit

/*恢复表空间*/
RMAN> recover tablespace 'TEST' until logseq 49 auxiliary destination '/opt/app/oracle/oradata/RHYS/';

Starting recover at 24-NOV-13

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='zvvn'

initialization parameters used for automatic instance:

db_name=RHYS

db_unique_name=zvvn_tspitr_RHYS

compatible=11.2.0.4.0

db_block_size=8192

db_files=230

sga_target=1G

processes=80

db_create_file_dest=/opt/app/oracle/oradata/RHYS/

log_archive_dest_1='location=/opt/app/oracle/oradata/RHYS/'

#No auxiliary parameter file used

starting up automatic instance RHYS

Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes

Variable Size                281019272 bytes

Database Buffers             780140544 bytes

Redo Buffers                   5517312 bytes

Automatic instance created

List of tablespaces that have been dropped from the target database:

Tablespace TEST

contents of Memory Script:

{

# set requested point in time

set until  logseq 49 thread 1;

# 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 24-NOV-13

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=18 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 /opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_ncsnf_TAG20131124T211515_993z16f9_.bkp

channel ORA_AUX_DISK_1: piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_ncsnf_TAG20131124T211515_993z16f9_.bkp tag=TAG20131124T211515

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

output file name=/opt/app/oracle/oradata/RHYS/RHYS/controlfile/o1_mf_993zzf1q_.ctl

Finished restore at 24-NOV-13

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  logseq 49 thread 1;

# 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

 "/opt/app/oracle/oradata/RHYS/test.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

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 24-NOV-13

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 /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_system_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00003 to /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_undotbs1_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00002 to /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_sysaux_%u_.dbf

channel ORA_AUX_DISK_1: restoring datafile 00005 to /opt/app/oracle/oradata/RHYS/test.dbf

channel ORA_AUX_DISK_1: reading from backup piece /opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_nnndf_TAG20131124T211515_993yz4b0_.bkp

channel ORA_AUX_DISK_1: piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_nnndf_TAG20131124T211515_993yz4b0_.bkp tag=TAG20131124T211515

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05

Finished restore at 24-NOV-13

datafile 1 switched to datafile copy

input datafile copy RECID=4 STAMP=832368822 file name=/opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_system_993zznww_.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=5 STAMP=832368822 file name=/opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_undotbs1_993zzo02_.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=6 STAMP=832368822 file name=/opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_sysaux_993zzny8_.dbf

contents of Memory Script:

{

# set requested point in time

set until  logseq 49 thread 1;

# 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  "TEST", "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 24-NOV-13

using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archived log restore to default destination

channel ORA_AUX_DISK_1: restoring archived log

archived log thread=1 sequence=48

channel ORA_AUX_DISK_1: reading from backup piece /opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_annnn_TAG20131124T211623_993z1821_.bkp

channel ORA_AUX_DISK_1: piece handle=/opt/app/oracle/fast_recovery_area/RHYS/backupset/2013_11_24/o1_mf_annnn_TAG20131124T211623_993z1821_.bkp tag=TAG20131124T211623

channel ORA_AUX_DISK_1: restored backup piece 1

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/opt/app/oracle/oradata/RHYS/1_48_830895689.dbf thread=1 sequence=48

channel clone_default: deleting archived log(s)

archived log file name=/opt/app/oracle/oradata/RHYS/1_48_830895689.dbf RECID=5 STAMP=832368825

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

Finished recover at 24-NOV-13

database opened

contents of Memory Script:

{

# make read only the tablespace that will be exported

sql clone 'alter tablespace  "TEST" read only';

# create directory for datapump import

sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''

/opt/app/oracle/oradata/RHYS/''";

# create directory for datapump export

sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''

/opt/app/oracle/oradata/RHYS/''";

}

executing Memory Script

sql statement: alter tablespace  "TEST" read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/opt/app/oracle/oradata/RHYS/''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/opt/app/oracle/oradata/RHYS/''

Performing export of metadata...

   EXPDP> Starting "SYS"."TSPITR_EXP_zvvn": 

   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_zvvn" successfully loaded/unloaded

   EXPDP> ******************************************************************************

   EXPDP> Dump file set for SYS.TSPITR_EXP_zvvn is:

   EXPDP>   /opt/app/oracle/oradata/RHYS/tspitr_zvvn_20255.dmp

   EXPDP> ******************************************************************************

   EXPDP> Datafiles required for transportable tablespace TEST:

   EXPDP>   /opt/app/oracle/oradata/RHYS/test.dbf

   EXPDP> Job "SYS"."TSPITR_EXP_zvvn" successfully completed at Sun Nov 24 21:36:50 2013 elapsed 0 00:02:10

Export completed

contents of Memory Script:

{

# shutdown clone before import

shutdown clone immediate

}

executing Memory Script

database closed

database dismounted

Oracle instance shut down

Performing import of metadata...

   IMPDP> Master table "SYS"."TSPITR_IMP_zvvn" successfully loaded/unloaded

   IMPDP> Starting "SYS"."TSPITR_IMP_zvvn": 

   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_zvvn" successfully completed at Sun Nov 24 21:37:54 2013 elapsed 0 00:00:18

Import completed

contents of Memory Script:

{

# make read write and offline the imported tablespaces

sql 'alter tablespace  "TEST" read write';

sql 'alter tablespace  "TEST" offline';

# enable autobackups after TSPITR is finished

sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';

}

executing Memory Script

sql statement: alter tablespace  "TEST" read write

sql statement: alter tablespace  "TEST" offline

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

Removing automatic instance

Automatic instance removed

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_temp_994021n7_.tmp deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/onlinelog/o1_mf_3_99401yg6_.log deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/onlinelog/o1_mf_2_99401x7v_.log deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/onlinelog/o1_mf_1_99401vk0_.log deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_sysaux_993zzny8_.dbf deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_undotbs1_993zzo02_.dbf deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/datafile/o1_mf_system_993zznww_.dbf deleted

auxiliary instance file /opt/app/oracle/oradata/RHYS/RHYS/controlfile/o1_mf_993zzf1q_.ctl deleted

Finished recover at 24-NOV-13

RMAN>

进行验证:

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sun Nov 24 21:38:59 2013

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> conn Amy/Rhys

Connected.

SQL> select count(*) from t; 

select count(*) from t

                     *

ERROR at line 1:

ORA-00376: file 5 cannot be read at this time

ORA-01110: data file 5: '/opt/app/oracle/oradata/RHYS/test.dbf'

SQL> select tablespace_name,status,plugged_in from dba_tablespaces;

TABLESPACE_NAME                STATUS    PLU

------------------------------ --------- ---

SYSTEM                         ONLINE    NO

SYSAUX                         ONLINE    NO

UNDOTBS1                       ONLINE    NO

TEMP                           ONLINE    NO

USERS                          ONLINE    NO

TEST                           OFFLINE   YES

6 rows selected.

SQL> alter tablespace test online;

Tablespace altered.

SQL> select tablespace_name,status,plugged_in from dba_tablespaces;

TABLESPACE_NAME                STATUS    PLU

------------------------------ --------- ---

SYSTEM                         ONLINE    NO

SYSAUX                         ONLINE    NO

UNDOTBS1                       ONLINE    NO

TEMP                           ONLINE    NO

USERS                          ONLINE    NO

TEST                           ONLINE    YES

6 rows selected.

SQL> select count(*) from t;

  COUNT(*)

----------

    114688

SQL> select count(*) from dba_objects;

  COUNT(*)

----------

     86366

SQL>

 

 

That‘s all!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: