|
1. 制造逻辑坏块样本:
1.1 PL/SQL Developper以sys用户执行:
- select t.tablespace_name, t.status
- from dba_tablespaces t;
-
- create tablespace tbs1 datafile size 10M nologging;
复制代码 1.2 SQL*PLUS以hr用户执行:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 19:32:09 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> create table t05218( a number , b varchar2(20)) tablespace tbs1;
- Table created.
- SQL> insert into t05218 values ( 179032 ,'seenanything' );
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> create index i05218_a on t05218(a) ;
- Index created.
- SQL> create index i05218_b on t05218(b) ;
- Index created.
- SQL>
复制代码 1.3 RMAN备份:
- [oracle@station90 ~]$ rman target /
- Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 13 19:40:58 2017
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1343950367)
- RMAN> backup tag 'for_logical_broken' tablespace tbs1;
- Starting backup at 13-JUN-17
- using target database control file instead of recovery catalog
- allocated channel: ORA_SBT_TAPE_1
- channel ORA_SBT_TAPE_1: SID=201 device type=SBT_TAPE
- channel ORA_SBT_TAPE_1: Oracle Secure Backup
- allocated channel: ORA_SBT_TAPE_2
- channel ORA_SBT_TAPE_2: SID=13 device type=SBT_TAPE
- channel ORA_SBT_TAPE_2: Oracle Secure Backup
- channel ORA_SBT_TAPE_1: starting full datafile backup set
- channel ORA_SBT_TAPE_1: specifying datafile(s) in backup set
- input datafile file number=00006 name=+DATA/orcl/datafile/tbs1.267.946582309
- channel ORA_SBT_TAPE_1: starting piece 1 at 13-JUN-17
- channel ORA_SBT_TAPE_1: finished piece 1 at 13-JUN-17
- piece handle=17s6ndcm_1_1 tag=FOR_LOGICAL_BROKEN comment=API Version 2.0,MMS Version 10.4.0.4
- channel ORA_SBT_TAPE_1: backup set complete, elapsed time: 00:01:05
- Finished backup at 13-JUN-17
- Starting Control File and SPFILE Autobackup at 13-JUN-17
- piece handle=c-1343950367-20170613-01 comment=API Version 2.0,MMS Version 10.4.0.4
- Finished Control File and SPFILE Autobackup at 13-JUN-17
- RMAN>
复制代码 1.4 检查64进制的小程序:
- #!/bin/sh
- LIST="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /"
- read -p "Pleas input a base64 code: " INPUT
- COUNT=0
- for i in $LIST
- do
- if [ $INPUT == $i ]
- then
- echo $COUNT
- else
- COUNT=$[ $COUNT + 1 ]
- fi
- done
复制代码 1.5 开始逻辑坏块制作:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 19:44:38 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> insert /*+ append */ into t05218 select * from t05218;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> select * from t05218;
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 19:44:38 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> insert /*+ append */ into t05218 select * from t05218;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> select * from t05218;
- A B
- ---------- --------------------
- 179032 seenanything
- 179032 seenanything
- SQL> select a,b, substr(rowid,10,6) from t05218;
- A B SUBSTR(ROWID,10,6)
- ---------- -------------------- ------------------------
- 179032 seenanything AAAACH
- 179032 seenanything AAAACI
- SQL> select a,b, substr(rowid,10,6), dbms_rowid.rowid_block_number(rowid) from t05218;
- A B SUBSTR(ROWID,10,6)
- ---------- -------------------- ------------------------
- DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------------------------------
- 179032 seenanything AAAACH
- 135
- 179032 seenanything AAAACI
- 136
- A B
- ---------- --------------------
- 179032 seenanything
- 179032 seenanything
- SQL> select a,b, substr(rowid,10,6) from t05218;
- A B SUBSTR(ROWID,10,6)
- ---------- -------------------- ------------------------
- 179032 seenanything AAAACH
- 179032 seenanything AAAACI
- SQL> select a,b, substr(rowid,10,6), dbms_rowid.rowid_block_number(rowid) from t05218;
- A B SUBSTR(ROWID,10,6)
- ---------- -------------------- ------------------------
- DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------------------------------
- 179032 seenanything AAAACH
- 135[oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:21:55 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select department_id, dbms_rowid.rowid_block_number(rowid) from departments;
- DEPARTMENT_ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------- ------------------------------------
- 10 175
- 20 175
- 30 175
- 40 175
- 50 175
- 60 175
- 70 175
- 80 175
- 90 175
- 100 175
- 110 175
- DEPARTMENT_ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------- ------------------------------------
- 120 175
- 130 175
- 140 175
- 150 175
- 160 175
- 170 175
- 180 175
- 190 175
- 200 175
- 210 175
- 220 175
- DEPARTMENT_ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------- ------------------------------------
- 230 175
- 240 175
- 250 175
- 260 175
- 270 175
- 27 rows selected.
- SQL>
- 179032 seenanything AAAACI
- 136
复制代码 1.6 破坏这个表空间:
1.7 RMAN恢复(没有日志情况下):
- [oracle@station90 ~]$ rman target /
- Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 13 20:13:01 2017
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1343950367)
- RMAN> restore tablespace tbs1;
- Starting restore at 13-JUN-17
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=138 device type=DISK
- allocated channel: ORA_DISK_2
- channel ORA_DISK_2: SID=201 device type=DISK
- allocated channel: ORA_DISK_3
- channel ORA_DISK_3: SID=11 device type=DISK
- allocated channel: ORA_DISK_4
- channel ORA_DISK_4: SID=75 device type=DISK
- allocated channel: ORA_DISK_5
- channel ORA_DISK_5: SID=140 device type=DISK
- allocated channel: ORA_DISK_6
- channel ORA_DISK_6: SID=198 device type=DISK
- allocated channel: ORA_DISK_7
- channel ORA_DISK_7: SID=16 device type=DISK
- allocated channel: ORA_DISK_8
- channel ORA_DISK_8: SID=74 device type=DISK
- allocated channel: ORA_SBT_TAPE_1
- channel ORA_SBT_TAPE_1: SID=144 device type=SBT_TAPE
- channel ORA_SBT_TAPE_1: Oracle Secure Backup
- allocated channel: ORA_SBT_TAPE_2
- channel ORA_SBT_TAPE_2: SID=18 device type=SBT_TAPE
- channel ORA_SBT_TAPE_2: Oracle Secure Backup
- channel ORA_SBT_TAPE_1: starting datafile backup set restore
- channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
- channel ORA_SBT_TAPE_1: restoring datafile 00006 to +DATA/orcl/datafile/tbs1.267.946582309
- channel ORA_SBT_TAPE_1: reading from backup piece 17s6ndcm_1_1
- channel ORA_SBT_TAPE_1: piece handle=17s6ndcm_1_1 tag=FOR_LOGICAL_BROKEN
- channel ORA_SBT_TAPE_1: restored backup piece 1
- channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:00:35
- Finished restore at 13-JUN-17
- RMAN> recover tablespace tbs1;
- Starting recover at 13-JUN-17
- using channel ORA_DISK_1
- using channel ORA_DISK_2
- using channel ORA_DISK_3
- using channel ORA_DISK_4
- using channel ORA_DISK_5
- using channel ORA_DISK_6
- using channel ORA_DISK_7
- using channel ORA_DISK_8
- using channel ORA_SBT_TAPE_1
- using channel ORA_SBT_TAPE_2
- starting media recovery
- media recovery complete, elapsed time: 00:00:00
- Finished recover at 13-JUN-17
- RMAN>
复制代码 测一下:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:15:25 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select * from t05218;
- ERROR:
- ORA-01578: ORACLE data block corrupted (file # 6, block # 136)
- ORA-01110: data file 6: '+DATA/orcl/datafile/tbs1.267.946582309'
- ORA-26040: Data block was loaded using the NOLOGGING option
- no rows selected
复制代码
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:15:25 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select * from t05218;
- ERROR:
- ORA-01578: ORACLE data block corrupted (file # 6, block # 136)
- ORA-01110: data file 6: '+DATA/orcl/datafile/tbs1.267.946582309'
- ORA-26040: Data block was loaded using the NOLOGGING option
- no rows selected
- SQL> select * from t05218;
- ERROR:
- ORA-01578: ORACLE data block corrupted (file # 6, block # 136)
- ORA-01110: data file 6: '+DATA/orcl/datafile/tbs1.267.946582309'
- ORA-26040: Data block was loaded using the NOLOGGING option
- no rows selected
复制代码 2. 物理坏块制作:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:21:55 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select department_id, dbms_rowid.rowid_block_number(rowid) from departments;
- DEPARTMENT_ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------- ------------------------------------
- 10 175
- 20 175
- 30 175
- 40 175
- 50 175
- 60 175
- 70 175
- 80 175
- 90 175
- 100 175
- 110 175
- DEPARTMENT_ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------- ------------------------------------
- 120 175
- 130 175
- 140 175
- 150 175
- 160 175
- 170 175
- 180 175
- 190 175
- 200 175
- 210 175
- 220 175
- DEPARTMENT_ID DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
- ------------- ------------------------------------
- 230 175
- 240 175
- 250 175
- 260 175
- 270 175
- 27 rows selected.
- SQL>
复制代码 物理坏块脚本physical-block11.2.0.1.sh:
- #!/bin/sh
- v_dbname=orcl
- su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/srvctl stop database -d $v_dbname -o abort"
- su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus /nolog" <<EOF
- conn / as sysdba
- startup mount exclusive
- EOF
- rm -f /home/oracle/example01.dbf 2>/dev/null
- su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target /" <<EOF
- backup as copy datafile 5 format '/home/oracle/example01.dbf';
- EOF
- dd if=/dev/zero of=/home/oracle/example01.dbf bs=8192 count=1 seek=175 conv=notrunc
- su - oracle -c "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid ; export ORACLE_SID=+ASM ; /u01/app/oracle/product/11.2.0/grid/bin/asmcmd" <<EOF
- rm -f +data/$v_dbname/DATAFILE/example*
- EOF
- su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target /" <<EOF
- run {
- set maxcorrupt for datafile 5 to 1;
- backup as copy datafilecopy '/home/oracle/example01.dbf' format '+data';
- }
- EOF
- sleep 3
- su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target /" <<EOF
- delete noprompt datafilecopy '/home/oracle/example01.dbf';
- switch datafile 5 to copy;
- EOF
- su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus /nolog" <<EOF
- conn / as sysdba
- alter database open;
- EOF
复制代码 执行:
- [root@station90 ~]# /home/oracle/physical-block11.2.0.1.sh
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:30:53 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> Connected to an idle instance.
- SQL> ORACLE instance started.
- Total System Global Area 6680915968 bytes
- Fixed Size 2213936 bytes
- Variable Size 3556771792 bytes
- Database Buffers 3087007744 bytes
- Redo Buffers 34922496 bytes
- Database mounted.
- SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
- With the Partitioning, Automatic Storage Management, OLAP, Data Mining
- and Real Application Testing options
- Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 13 20:31:01 2017
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1343950367, not open)
- RMAN>
- Starting backup at 13-JUN-17
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=68 device type=DISK
- allocated channel: ORA_DISK_2
- channel ORA_DISK_2: SID=131 device type=DISK
- allocated channel: ORA_DISK_3
- channel ORA_DISK_3: SID=192 device type=DISK
- allocated channel: ORA_DISK_4
- channel ORA_DISK_4: SID=8 device type=DISK
- allocated channel: ORA_DISK_5
- channel ORA_DISK_5: SID=69 device type=DISK
- allocated channel: ORA_DISK_6
- channel ORA_DISK_6: SID=132 device type=DISK
- allocated channel: ORA_DISK_7
- channel ORA_DISK_7: SID=193 device type=DISK
- allocated channel: ORA_DISK_8
- channel ORA_DISK_8: SID=9 device type=DISK
- channel ORA_DISK_1: starting datafile copy
- input datafile file number=00005 name=+DATA/orcl/datafile/example.265.816169651
- output file name=/home/oracle/example01.dbf tag=TAG20170613T203104 RECID=2 STAMP=946585865
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
- Finished backup at 13-JUN-17
- Starting Control File and SPFILE Autobackup at 13-JUN-17
- piece handle=+FRA/orcl/autobackup/2017_06_13/s_946585768.268.946585867 comment=NONE
- Finished Control File and SPFILE Autobackup at 13-JUN-17
- RMAN>
- Recovery Manager complete.
- 记录了1+0 的读入
- 记录了1+0 的写出
- 8192字节(8.2 kB)已复制,2.293e-05 秒,357 MB/秒
- ASMCMD> ASMCMD> exit
- Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 13 20:31:07 2017
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1343950367, not open)
- RMAN> 2> 3> 4>
- executing command: SET MAX CORRUPT
- using target database control file instead of recovery catalog
- Starting backup at 13-JUN-17
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=68 device type=DISK
- allocated channel: ORA_DISK_2
- channel ORA_DISK_2: SID=131 device type=DISK
- allocated channel: ORA_DISK_3
- channel ORA_DISK_3: SID=193 device type=DISK
- allocated channel: ORA_DISK_4
- channel ORA_DISK_4: SID=8 device type=DISK
- allocated channel: ORA_DISK_5
- channel ORA_DISK_5: SID=69 device type=DISK
- allocated channel: ORA_DISK_6
- channel ORA_DISK_6: SID=132 device type=DISK
- allocated channel: ORA_DISK_7
- channel ORA_DISK_7: SID=191 device type=DISK
- allocated channel: ORA_DISK_8
- channel ORA_DISK_8: SID=7 device type=DISK
- channel ORA_DISK_1: starting datafile copy
- input is copy of datafile 00005: /home/oracle/example01.dbf
- output file name=+DATA/orcl/datafile/example.265.946585871 tag=TAG20170613T203104 RECID=3 STAMP=946585871
- channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
- Finished backup at 13-JUN-17
- Starting Control File and SPFILE Autobackup at 13-JUN-17
- piece handle=+FRA/orcl/autobackup/2017_06_13/s_946585768.269.946585871 comment=NONE
- Finished Control File and SPFILE Autobackup at 13-JUN-17
- RMAN>
- Recovery Manager complete.
- Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 13 20:31:15 2017
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1343950367, not open)
- RMAN>
- using target database control file instead of recovery catalog
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=68 device type=DISK
- allocated channel: ORA_DISK_2
- channel ORA_DISK_2: SID=131 device type=DISK
- allocated channel: ORA_DISK_3
- channel ORA_DISK_3: SID=191 device type=DISK
- allocated channel: ORA_DISK_4
- channel ORA_DISK_4: SID=8 device type=DISK
- allocated channel: ORA_DISK_5
- channel ORA_DISK_5: SID=69 device type=DISK
- allocated channel: ORA_DISK_6
- channel ORA_DISK_6: SID=132 device type=DISK
- allocated channel: ORA_DISK_7
- channel ORA_DISK_7: SID=192 device type=DISK
- allocated channel: ORA_DISK_8
- channel ORA_DISK_8: SID=9 device type=DISK
- List of Datafile Copies
- =======================
- Key File S Completion Time Ckp SCN Ckp Time
- ------- ---- - --------------- ---------- ---------------
- 2 5 A 13-JUN-17 1072330 13-JUN-17
- Name: /home/oracle/example01.dbf
- Tag: TAG20170613T203104
- deleted datafile copy
- datafile copy file name=/home/oracle/example01.dbf RECID=2 STAMP=946585865
- Deleted 1 objects
- RMAN>
- datafile 5 switched to datafile copy "+DATA/orcl/datafile/example.265.946585871"
- RMAN>
- Recovery Manager complete.
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:31:19 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> Connected.
- SQL>
- Database altered.
- SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
- With the Partitioning, Automatic Storage Management, OLAP, Data Mining
- and Real Application Testing options
复制代码- [oracle@station90 ~]$ rman target /
- Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jun 13 20:36:18 2017
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1343950367)
- RMAN> list backup of tablespace example;
- using target database control file instead of recovery catalog
- List of Backup Sets
- ===================
- BS Key Type LV Size Device Type Elapsed Time Completion Time
- ------- ---- -- ---------- ----------- ------------ ---------------
- 35 Incr 0 657.75M SBT_TAPE 00:00:27 18-MAY-17
- BP Key: 35 Status: AVAILABLE Compressed: NO Tag: 0T_INCR0_WHOLE
- Handle: 12s4ih4j_1_1 Media: station90-000001
- List of Datafiles in backup set 35
- File LV Type Ckp SCN Ckp Time Name
- ---- -- ---- ---------- --------- ----
- 5 0 Incr 1057421 18-MAY-17 +DATA/orcl/datafile/example.265.946585871
复制代码- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 13 20:32:32 2017
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select * from departments;
- select * from departments
- *
- ERROR at line 1:
- ORA-01578: ORACLE data block corrupted (file # 5, block # 175)
- ORA-01110: data file 5: '+DATA/orcl/datafile/example.265.946585871'
复制代码
|
|