手机版
你好,游客 登录 注册
背景:
阅读新闻

Oracle误删除表空间的恢复

[日期:2014-02-13] 来源:Linux社区  作者:Linux [字体:大 中 小]

二 通过基于表空间的时间点恢复被误删除的表空间


1 创建测试用的表jxc表空间及用户
SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
/Oracle/CRM/CRM/system01.dbf
/oracle/CRM/CRM/sysaux01.dbf
/oracle/CRM/CRM/undotbs01.dbf
/oracle/CRM/CRM/users01.dbf
/oracle/CRM/user01.dbf
/oracle/CRM/erp.dbf
/oracle/CRM/undotbs03.dbf
/oracle/CRM/crm.dbf


8 rows selected.


SQL> create tablespace jxc datafile '/oracle/CRM/jxc.dbf' size 10m;


Tablespace created.


SQL> create user zx identified by dhhzdhhz default tablespace jxc;


User created.

 


SQL> grant resource,connect to zx;


Grant succeeded.


SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@dest ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Mon Feb 10 02:05:25 2014


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

 


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> alter system switch logfile;


System altered.


SQL> alter system switch logfile;


System altered.


SQL> alter system switch logfile;


System altered.


SQL> alter system checkpoint;


System altered.


SQL> /


System altered.


SQL> exit


2 对整个数据库做一次全备份
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@dest ~]$ rman target /


Recovery Manager: Release 11.2.0.2.0 - Production on Mon Feb 10 02:07:05 2014


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


connected to target database: CRM (DBID=3641885733)


RMAN> list backup of database;


using target database control file instead of recovery catalog
specification does not match any backup in the repository


RMAN> run{
2> delete noprompt obsolete;
3> crosscheck backup;
4> delete noprompt expired backup;
5> crosscheck archivelog all;
6> delete noprompt expired archivelog all;
7> backup incremental level=0  database format '/backup/crm/full-%T-%U.bak';
8> backup archivelog all  format '/backup/crm/arch-%T-%U.bak';
9> backup current controlfile format '/backup/crm/ctl-%T-%U.bak';
10> backup spfile format '/backup/crm/spf-%T-%U.bak';
11> delete noprompt archivelog all completed before 'SYSDATE - 7';
12> }


.................备份过程省略.........................................


3 在jxc表空间上创建测试数据


[oracle@dest ~]$ sqlplus zx/dhhzdhhz


SQL*Plus: Release 11.2.0.2.0 Production on Mon Feb 10 02:12:17 2014


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

 


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL>  create table test1(i int); 


Table created.


SQL> begin
  2  for i in 1..20 loop
  3  insert into test1 values(i);
  4  end loop;
  5  commit;
  6  end;
  7  /


PL/SQL procedure successfully completed.


SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@dest ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Mon Feb 10 02:13:35 2014


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

 


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> alter system switch logfile;


System altered.


SQL> alter system switch logfile;


System altered.


SQL> alter system switch logfile;


System altered.


SQL> alter system checkpoint;


System altered.


4 查询当前数据库的时间


SQL> select current_scn,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from v$database;


CURRENT_SCN TO_CHAR(SYSDATE,'YY
----------- -------------------
    3905661 2014-02-10 02:14:23

 


5 删除jxc表空间


SQL> alter system switch logfile;


System altered.


SQL> alter system switch logfile;


System altered.


SQL> alter system checkpoint;


System altered.


SQL> drop tablespace jxc including contents and datafiles;


Tablespace dropped.


SQL> exit


6 执行全自动rman管理的表空间时间点恢复


[oracle@dest ~]$ rman target /


Recovery Manager: Release 11.2.0.2.0 - Production on Mon Feb 10 02:17:40 2014


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


connected to target database: CRM (DBID=3641885733)


RMAN> recover tablespace jxc until time "to_date('2014-02-10 02:14:23','yyyy-mm-dd hh24:mi:ss')" auxiliary destination '/backup';


Starting recover at 2014-02-10 02:20:12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=72 device type=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
Tablespace UNDOTBS3


Creating automatic instance, with SID='DctA'


initialization parameters used for automatic instance:
db_name=CRM
db_unique_name=DctA_tspitr_CRM
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 CRM


Oracle instance started


Total System Global Area    292278272 bytes


Fixed Size                    2225872 bytes
Variable Size                100665648 bytes
Database Buffers            184549376 bytes
Redo Buffers                  4837376 bytes
Automatic instance created

 


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


contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2014-02-10 02:14:23','yyyy-mm-dd 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 2014-02-10 02:20:39
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=81 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/crm/ctl-20140210-1up081kd_1_1.bak
channel ORA_AUX_DISK_1: piece handle=/backup/crm/ctl-20140210-1up081kd_1_1.bak tag=TAG20140210T021020
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/CRM/controlfile/o1_mf_9hhkqsc7_.ctl
Finished restore at 2014-02-10 02:20:42


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('2014-02-10 02:14:23','yyyy-mm-dd hh24:mi:ss')";
# 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  9 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
set newname for datafile  5 to
 "/oracle/CRM/jxc.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 9, 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


executing command: SET NEWNAME


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


Starting restore at 2014-02-10 02:20:49
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/CRM/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /backup/CRM/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /backup/CRM/datafile/o1_mf_undotbs3_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /backup/CRM/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/CRM/jxc.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/crm/full-20140210-1ip081fb_1_1.bak
channel ORA_AUX_DISK_1: piece handle=/backup/crm/full-20140210-1ip081fb_1_1.bak tag=TAG20140210T020739
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:16
Finished restore at 2014-02-10 02:22:05


datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=839125325 file name=/backup/CRM/datafile/o1_mf_system_9hhkr221_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=839125325 file name=/backup/CRM/datafile/o1_mf_undotbs1_9hhkr231_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=7 STAMP=839125325 file name=/backup/CRM/datafile/o1_mf_undotbs3_9hhkr24l_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=839125325 file name=/backup/CRM/datafile/o1_mf_sysaux_9hhkr22c_.dbf


contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2014-02-10 02:14:23','yyyy-mm-dd 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  9 online";
sql clone "alter database datafile  2 online";
sql clone "alter database datafile  5 online";
# recover and open resetlogs
recover clone database tablespace  "JXC", "SYSTEM", "UNDOTBS1", "UNDOTBS3", "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  9 online


sql statement: alter database datafile  2 online


sql statement: alter database datafile  5 online


Starting recover at 2014-02-10 02:22:07
using channel ORA_AUX_DISK_1


starting media recovery


archived log for thread 1 with sequence 9 is already on disk as file /oracle/archivelog/arch_1_9_839098938.arch
archived log for thread 1 with sequence 10 is already on disk as file /oracle/archivelog/arch_1_10_839098938.arch
archived log for thread 1 with sequence 11 is already on disk as file /oracle/archivelog/arch_1_11_839098938.arch
archived log for thread 1 with sequence 12 is already on disk as file /oracle/archivelog/arch_1_12_839098938.arch
archived log for thread 1 with sequence 13 is already on disk as file /oracle/archivelog/arch_1_13_839098938.arch
archived log file name=/oracle/archivelog/arch_1_9_839098938.arch thread=1 sequence=9
archived log file name=/oracle/archivelog/arch_1_10_839098938.arch thread=1 sequence=10
archived log file name=/oracle/archivelog/arch_1_11_839098938.arch thread=1 sequence=11
archived log file name=/oracle/archivelog/arch_1_12_839098938.arch thread=1 sequence=12
archived log file name=/oracle/archivelog/arch_1_13_839098938.arch thread=1 sequence=13
media recovery complete, elapsed time: 00:00:02
Finished recover at 2014-02-10 02:22:15


database opened


contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace  JXC 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  JXC 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_DctA": 
  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_DctA" successfully loaded/unloaded
  EXPDP> ******************************************************************************
  EXPDP> Dump file set for SYS.TSPITR_EXP_DctA is:
  EXPDP>  /backup/tspitr_DctA_28726.dmp
  EXPDP> ******************************************************************************
  EXPDP> Datafiles required for transportable tablespace JXC:
  EXPDP>  /oracle/CRM/jxc.dbf
  EXPDP> Job "SYS"."TSPITR_EXP_DctA" successfully completed at 02:25:39
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_DctA" successfully loaded/unloaded
  IMPDP> Starting "SYS"."TSPITR_IMP_DctA": 
  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_DctA" successfully completed at 02:26:50
Import completed

 


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


sql statement: alter tablespace  JXC read write


sql statement: alter tablespace  JXC offline


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


Removing automatic instance
Automatic instance removed
auxiliary instance file /backup/CRM/datafile/o1_mf_temp_9hhkvg7w_.tmp deleted
auxiliary instance file /backup/CRM/onlinelog/o1_mf_3_9hhkv3mp_.log deleted
auxiliary instance file /backup/CRM/onlinelog/o1_mf_2_9hhktyoc_.log deleted
auxiliary instance file /backup/CRM/onlinelog/o1_mf_1_9hhktqyl_.log deleted
auxiliary instance file /backup/CRM/datafile/o1_mf_sysaux_9hhkr22c_.dbf deleted
auxiliary instance file /backup/CRM/datafile/o1_mf_undotbs3_9hhkr24l_.dbf deleted
auxiliary instance file /backup/CRM/datafile/o1_mf_undotbs1_9hhkr231_.dbf deleted
auxiliary instance file /backup/CRM/datafile/o1_mf_system_9hhkr221_.dbf deleted
auxiliary instance file /backup/CRM/controlfile/o1_mf_9hhkqsc7_.ctl deleted
Finished recover at 2014-02-10 02:27:09


RMAN> exit

 


Recovery Manager complete.


7 online jxc测试表空间


[oracle@dest ~]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Mon Feb 10 02:27:55 2014


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

 


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select tablespace_name,status from dba_tablespaces;


TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                        ONLINE
SYSAUX                        ONLINE
UNDOTBS1                      ONLINE
TEMP                          ONLINE
USERS                          ONLINE
JXC                            OFFLINE
USER01                        ONLINE
ERP                            ONLINE
UNDOTBS3                      ONLINE
CRM                            ONLINE


10 rows selected.


SQL> alter tablespace jxc online;


Tablespace altered.


8 验证测试数据是否恢复


SQL> select * from zx.test1;


        I
----------
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11


        I
----------
        12
        13
        14
        15
        16
        17
        18
        19
        20


20 rows selected.


注意:
1 通过执行基于表空间的时间点恢复,仅仅是回退了要需要恢复的表空        间,这和基于数据库的时间点恢复,回退整个数据库是有区别的。
2 在10g上通过基于表空间的时间点恢复误删除的表空间会报如下错误:
        RMAN-00571: ===========================================================
        RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
        RMAN-00571: ===========================================================
        RMAN-03002: failure of recover command at 02/10/2014 22:25:15
        RMAN-20202: tablespace not found in the recovery catalog
        RMAN-06019: could not translate tablespace name "JXC"

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

 ��     

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款