【RMAN】rm -rf 誤操作的恢復過程

Appleses發表於2016-01-30

RMANrm -rf 誤操作的恢復過程

----資料庫在無備份且open情況下的恢復


 

wps76CC.tmp 

本文地址URL: http://blog.itpub.net/26736162/viewspace-1623938/

 

 

很多一定對深惡痛絕吧,沒準哪天自己一個犯迷糊就把資料庫給消滅了,然後,就沒有然後了……那萬一……真的發生了這樣的不幸,是否真的就無藥可救了嗎?未必,還是有解決方法的,也許某天當你不幸遇到,就可以用來救自己了。這裡做恢復操作的前提是沒有可用的備份,或者資料庫冷備份等,也就是說,沒有任何備份

 

 

1  登入SQLPLUS檢視基本資訊

先建立一個測試庫,在測試庫上來練習:

[oracle@orcltest ~]$ dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname oratest -sid oratest -sysPassword lhr -systemPassword lhr -responseFile NO_VALUE -datafileDestination /u02/app/oracle/oradata/ -redoLogFileSize 50 -recoveryAreaDestination /u02/app/oracle/flash_recovery_area -storageType FS -characterSet ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema true -memoryPercentage 30 -totalMemory 200 -databaseType OLTP -emConfiguration NONE  -automaticMemoryManagement true

Copying database files

1% complete

3% complete

10% complete

17% complete

24% complete

35% complete

Creating and starting Oracle instance

37% complete

42% complete

47% complete

52% complete

53% complete

56% complete

58% complete

Registering database with Oracle Restart

64% complete

Completing Database Creation

68% complete

71% complete

75% complete

85% complete

96% complete

100% complete

Look at the log file "/u02/app/oracle/cfgtoollogs/dbca/oratest/oratest.log" for further details.

 

[oracle@orcltest ~]$ ORACLE_SID=oratest

[oracle@orcltest ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Tue May 5 13:42:00 2015

 

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

 

 

Connected to:

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

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

 

SQL> show parameter name

 

NAME                                 TYPE        VALUE

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

db_file_name_convert                 string

db_name                              string      oratest

db_unique_name                       string      oratest

global_names                         boolean     FALSE

instance_name                        string      oratest

lock_name_space                      string

log_file_name_convert                string

processor_group_name                 string

service_names                        string      oratest

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     4

Next log sequence to archive   6

Current log sequence           6

SQL>

 

SQL> select status from v$instance;

 

STATUS

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

OPEN

 

SQL> set line 9999 pagesize 9999

SQL> col FILE_NAME format a60

SQL> select 'datafile' file_type, file#,name FILE_NAME,status,enabled from v$datafile

  2  union all

  3  select 'tempfile',file#,name FILE_NAME,status,enabled from v$tempfile

  4  union all

  5  select 'logfile',group# file#,member FILE_NAME,status,'' from v$logfile

  6  union all

  7  select 'controlfile', to_number('') ,name FILE_NAME,status,'' from v$controlfile

  8  ;

 

FILE_TYPE        FILE# FILE_NAME                                                    STATUS  ENABLED

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

datafile             1 /u02/app/oracle/oradata/oratest/system01.dbf                 SYSTEM  READ WRITE

datafile             2 /u02/app/oracle/oradata/oratest/sysaux01.dbf                 ONLINE  READ WRITE

datafile             3 /u02/app/oracle/oradata/oratest/undotbs01.dbf                ONLINE  READ WRITE

datafile             4 /u02/app/oracle/oradata/oratest/users01.dbf                  ONLINE  READ WRITE

datafile             5 /u02/app/oracle/oradata/oratest/example01.dbf                ONLINE  READ WRITE

tempfile             1 /u02/app/oracle/oradata/oratest/temp01.dbf                   ONLINE  READ WRITE

logfile              3 /u02/app/oracle/oradata/oratest/redo03.log

logfile              2 /u02/app/oracle/oradata/oratest/redo02.log

logfile              1 /u02/app/oracle/oradata/oratest/redo01.log

controlfile            /u02/app/oracle/oradata/oratest/control01.ctl

controlfile            /u02/app/oracle/flash_recovery_area/oratest/control02.ctl

 

11 rows selected.

 

SQL>

 

SQL> create table aa  as select * from dba_objects;

 

Table created.

 

SQL> insert into  aa select * from aa;

 

75203 rows created.

 

SQL>

SQL> select count(1) from aa;

 

  COUNT(1)

----------

    150406

 

SQL>

 

 

 

這裡不提交,,,我們看看資料是否可以恢復。 

 

2  模擬rm -rf誤操作

 

 

 

 

 

SQL> ! rm -rf /u02/app/oracle/oradata/oratest/*

 

SQL> ! rm -rf /u02/app/oracle/flash_recovery_area/oratest/*

 

SQL> ! ls -l  /u02/app/oracle/oradata/oratest/*

ls: cannot access /u02/app/oracle/oradata/oratest/*: No such file or directory

 

SQL>

 

 

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

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

[oracle@orcltest ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Tue May 5 13:58:54 2015

 

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

 

 

Connected to:

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

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

 

 

SQL> select count(*) from dba_objects;

 

  COUNT(*)

----------

     75202

 

 

 

SQL>  select status from v$instance;

 

STATUS

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

OPEN

 

SQL> select open_mode from v$database;

select open_mode from v$database

                      *

ERROR at line 1:

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u02/app/oracle/oradata/oratest/control01.ctl'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

 

SQL> create table aa as select * from  dba_objects;

create table aa as select * from  dba_objects

                                  *

ERROR at line 1:

ORA-00604: error occurred at recursive SQL level 1

ORA-01116: error in opening database file 1

ORA-01110: data file 1: '/u02/app/oracle/oradata/oratest/system01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

 

 

SQL>

 

 

 

由於資料檔案都被刪除,其中包括,是存放資料字典的容器,想要再訪問資料字典中得檢視,當然是不可能的了,所以這裡會報錯,找不到檔案,故障出現

--檢視日誌檔案

 

Tue May 05 14:04:05 2015

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m001_30851.trc:

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u02/app/oracle/oradata/oratest/control01.ctl'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

 

 

3  開始恢復

 

3.1  判斷控制程式碼位置

 

其實這個時候,所有的程式都還在,都是以開頭的都是的後臺程式: 

SQL> ! ps -ef|grep ora_

oracle   31843     1  0 14:41 ?        00:00:00 ora_pmon_oratest

oracle   31845     1  0 14:41 ?        00:00:00 ora_psp0_oratest

oracle   31847     1  0 14:41 ?        00:00:00 ora_vktm_oratest

oracle   31851     1  0 14:41 ?        00:00:00 ora_gen0_oratest

oracle   31853     1  0 14:41 ?        00:00:00 ora_diag_oratest

oracle   31855     1  0 14:41 ?        00:00:00 ora_dbrm_oratest

oracle   31857     1  0 14:41 ?        00:00:00 ora_dia0_oratest

oracle   31859     1  0 14:41 ?        00:00:00 ora_mman_oratest

oracle   31861     1  0 14:41 ?        00:00:00 ora_dbw0_oratest

oracle   31863     1  0 14:41 ?        00:00:00 ora_lgwr_oratest

oracle   31865     1  0 14:41 ?        00:00:00 ora_ckpt_oratest

oracle   31867     1  0 14:41 ?        00:00:00 ora_smon_oratest

oracle   31869     1  0 14:41 ?        00:00:00 ora_reco_oratest

oracle   31871     1  0 14:41 ?        00:00:00 ora_mmon_oratest

oracle   31873     1  0 14:41 ?        00:00:00 ora_mmnl_oratest

oracle   31875     1  0 14:41 ?        00:00:00 ora_d000_oratest

oracle   31877     1  0 14:41 ?        00:00:00 ora_s000_oratest

oracle   31927     1  0 14:41 ?        00:00:00 ora_arc0_oratest

oracle   31935     1  0 14:41 ?        00:00:00 ora_arc1_oratest

oracle   31937     1  0 14:41 ?        00:00:00 ora_arc2_oratest

oracle   31939     1  0 14:41 ?        00:00:00 ora_arc3_oratest

oracle   31941     1  0 14:41 ?        00:00:00 ora_qmnc_oratest

oracle   31957     1  0 14:41 ?        00:00:00 ora_cjq0_oratest

oracle   31967     1  0 14:42 ?        00:00:00 ora_q000_oratest

oracle   31969     1  0 14:42 ?        00:00:00 ora_q001_oratest

oracle   31976     1  0 14:45 ?        00:00:00 ora_smco_oratest

oracle   31978     1  0 14:46 ?        00:00:00 ora_w000_oratest

oracle   32013     1  0 14:50 ?        00:00:00 ora_w001_oratest

oracle   32063 31989  0 14:57 pts/4    00:00:00 /bin/bash -c  ps -ef|grep ora_

oracle   32065 32063  0 14:57 pts/4    00:00:00 grep ora_

 

SQL>

 

 

 

--檢視程式,判斷需要恢復檔案控制程式碼所在目錄

 

SQL> !ps -ef|grep ora_lgwr

oracle   31863     1  0 14:41 ?        00:00:00 ora_lgwr_oratest

oracle   31995 31989  0 14:48 pts/4    00:00:00 /bin/bash -c ps -ef|grep ora_lgwr

oracle   31997 31995  0 14:48 pts/4    00:00:00 grep ora_lgwr

 

SQL>

 

 

 

 

由此可知,我們需要的被刪除的檔案控制程式碼在/proc/31863/fd 

 

此時,告警日誌:Tue May 05 14:09:05 2015

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m000_30871.trc:

ORA-01116: error in opening database file 1

ORA-01110: data file 1: '/u02/app/oracle/oradata/oratest/system01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m000_30871.trc:

ORA-01116: error in opening database file 2

ORA-01110: data file 2: '/u02/app/oracle/oradata/oratest/sysaux01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m000_30871.trc:

ORA-01116: error in opening database file 4

ORA-01110: data file 4: '/u02/app/oracle/oradata/oratest/users01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m000_30871.trc:

ORA-01116: error in opening database file 5

ORA-01110: data file 5: '/u02/app/oracle/oradata/oratest/example01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m000_30871.trc:

ORA-01116: error in opening database file 201

ORA-01110: data file 201: '/u02/app/oracle/oradata/oratest/temp01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m000_30871.trc:

ORA-01116: error in opening database file 3

ORA-01110: data file 3: '/u02/app/oracle/oradata/oratest/undotbs01.dbf'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

Tue May 05 14:09:05 2015

Errors in file /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_m001_30873.trc:

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u02/app/oracle/oradata/oratest/control01.ctl'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

3.2  恢復資料檔案、控制檔案、tmp檔案和online log檔案

 

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

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

[oracle@orcltest ~]$ cd /proc/31863/fd

-bash: cd: /proc/30335/fd: Permission denied

[oracle@orcltest ~]$ cd /proc/31863/

[oracle@orcltest 30335]$ su - root

Password:

[root@orcltest ~]# cd /proc/31863/fd

[root@orcltest fd]# ll

total 0

lr-x------ 1 oracle oinstall 64 May  5 14:48 0 -> /dev/null

l-wx------ 1 oracle oinstall 64 May  5 14:48 1 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 10 -> /dev/zero

lr-x------ 1 oracle oinstall 64 May  5 14:48 11 -> /dev/zero

lrwx------ 1 oracle oinstall 64 May  5 14:48 12 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lr-x------ 1 oracle oinstall 64 May  5 14:48 13 -> /u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

lr-x------ 1 oracle oinstall 64 May  5 14:48 14 -> /proc/31863/fd

lr-x------ 1 oracle oinstall 64 May  5 14:48 15 -> /dev/zero

lrwx------ 1 oracle oinstall 64 May  5 14:48 16 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lrwx------ 1 oracle oinstall 64 May  5 14:48 17 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/lkORATEST

lr-x------ 1 oracle oinstall 64 May  5 14:48 18 -> /u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

l-wx------ 1 oracle oinstall 64 May  5 14:48 2 -> /dev/null

lrwx------ 1 oracle oinstall 64 May  5 14:48 256 -> /u02/app/oracle/oradata/oratest/control01.ctl (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 257 -> /u02/app/oracle/flash_recovery_area/oratest/control02.ctl (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 258 -> /u02/app/oracle/oradata/oratest/redo01.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 259 -> /u02/app/oracle/oradata/oratest/redo02.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 260 -> /u02/app/oracle/oradata/oratest/redo03.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 261 -> /u02/app/oracle/oradata/oratest/system01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 262 -> /u02/app/oracle/oradata/oratest/sysaux01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 263 -> /u02/app/oracle/oradata/oratest/undotbs01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 264 -> /u02/app/oracle/oradata/oratest/users01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 265 -> /u02/app/oracle/oradata/oratest/example01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 266 -> /u02/app/oracle/oradata/oratest/temp01.dbf (deleted)

lr-x------ 1 oracle oinstall 64 May  5 14:48 3 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 4 -> /dev/null

lrwx------ 1 oracle oinstall 64 May  5 14:48 5 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lr-x------ 1 oracle oinstall 64 May  5 14:48 6 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 7 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 8 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 9 -> /dev/null

[root@orcltest fd]#

 

[root@orcltest fd]# ll | grep deleted

lrwx------ 1 oracle oinstall 64 May  5 14:48 256 -> /u02/app/oracle/oradata/oratest/control01.ctl (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 257 -> /u02/app/oracle/flash_recovery_area/oratest/control02.ctl (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 258 -> /u02/app/oracle/oradata/oratest/redo01.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 259 -> /u02/app/oracle/oradata/oratest/redo02.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 260 -> /u02/app/oracle/oradata/oratest/redo03.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 261 -> /u02/app/oracle/oradata/oratest/system01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 262 -> /u02/app/oracle/oradata/oratest/sysaux01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 263 -> /u02/app/oracle/oradata/oratest/undotbs01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 264 -> /u02/app/oracle/oradata/oratest/users01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 265 -> /u02/app/oracle/oradata/oratest/example01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 266 -> /u02/app/oracle/oradata/oratest/temp01.dbf (deleted)

[root@orcltest fd]#

 

256266的檔案末尾被標記,這是由剛才的操作所導致的,誤刪除後只要資料庫未重啟,程式就不會停止,那麼就可以透過 DBWn程式號目錄中的檔案控制程式碼號,來對這些被的檔案進行恢復,方法就是檔案控制程式碼到原路徑,注意一點這裡如果不是在目錄,那就要用絕對路徑來指定檔案控制程式碼,如果刪除檔案後就,又對資料庫進行了關閉操作,那就無解了,只能想想了。 

 

如果採用軟體來作為終端檢視的話,可以看到這幾個的檔案是一直閃動的,截了張圖:
wps76ED.tmp 

 

 

wps76FD.tmp 

 

 

執行恢復,執行如下指令碼:cp 256 /u02/app/oracle/oradata/oratest/control01.ctl cp 257 /u02/app/oracle/flash_recovery_area/oratest/control02.ctl cp 258 /u02/app/oracle/oradata/oratest/redo01.log cp 259 /u02/app/oracle/oradata/oratest/redo02.log cp 260 /u02/app/oracle/oradata/oratest/redo03.log cp 261 /u02/app/oracle/oradata/oratest/system01.dbf cp 262 /u02/app/oracle/oradata/oratest/sysaux01.dbf cp 263 /u02/app/oracle/oradata/oratest/undotbs01.dbf cp 264 /u02/app/oracle/oradata/oratest/users01.dbf cp 265 /u02/app/oracle/oradata/oratest/example01.dbf cp 266 /u02/app/oracle/oradata/oratest/temp01.dbf  

 

注意,這裡一定要注意許可權問題,要用oracle使用者去cp,如果用rootcp出來的檔案,oracle程式是沒有許可權操作的,當然,你也可以在用root恢復完後,再chown一下:
[root@ora10g fd]# chown oracle.oinstall /u01/app/oracle -R

但是一定要注意,必須等全部資料檔案恢復後才可以做chown操作,因為一旦執行了該操作,原來的ora_程式會停止!!!你再也無法恢復丟失的資料了!!!這也是為什麼推薦用oralce使用者來cp的原因有的時候oracle的許可權不足,就只能使用rootcopy了。

 

 

[root@orcltest fd]# cp 256 /u02/app/oracle/oradata/oratest/control01.ctl

[root@orcltest fd]# cp 257 /u02/app/oracle/flash_recovery_area/oratest/control02.ctl

[root@orcltest fd]# cp 258 /u02/app/oracle/oradata/oratest/redo01.log

[root@orcltest fd]# cp 259 /u02/app/oracle/oradata/oratest/redo02.log

[root@orcltest fd]# cp 260 /u02/app/oracle/oradata/oratest/redo03.log

[root@orcltest fd]# cp 261 /u02/app/oracle/oradata/oratest/system01.dbf

[root@orcltest fd]# cp 262 /u02/app/oracle/oradata/oratest/sysaux01.dbf

[root@orcltest fd]# cp 263 /u02/app/oracle/oradata/oratest/undotbs01.dbf

[root@orcltest fd]# cp 264 /u02/app/oracle/oradata/oratest/users01.dbf

[root@orcltest fd]# cp 265 /u02/app/oracle/oradata/oratest/example01.dbf

[root@orcltest fd]# cp 266 /u02/app/oracle/oradata/oratest/temp01.dbf

 

[root@orcltest fd]# chown oracle.oinstall /u02/app/oracle/oradata/oratest/*

[root@orcltest fd]# chown oracle.oinstall /u02/app/oracle/flash_recovery_area/oratest/control02.ctl

 

 

 

 

 

 

 

對檔案進行恢復以後,直接查詢目錄下的檔案狀態,依然可以看到是的,但是沒關係,實際上檔案已經恢復成功了 

 

[root@orcltest fd]# ll

total 0

lr-x------ 1 oracle oinstall 64 May  5 14:48 0 -> /dev/null

l-wx------ 1 oracle oinstall 64 May  5 14:48 1 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 10 -> /dev/zero

lr-x------ 1 oracle oinstall 64 May  5 14:48 11 -> /dev/zero

lrwx------ 1 oracle oinstall 64 May  5 14:48 12 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lr-x------ 1 oracle oinstall 64 May  5 14:48 13 -> /u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

lr-x------ 1 oracle oinstall 64 May  5 14:48 14 -> /proc/31863/fd

lr-x------ 1 oracle oinstall 64 May  5 14:48 15 -> /dev/zero

lrwx------ 1 oracle oinstall 64 May  5 14:48 16 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lrwx------ 1 oracle oinstall 64 May  5 14:48 17 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/lkORATEST

lr-x------ 1 oracle oinstall 64 May  5 14:48 18 -> /u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

l-wx------ 1 oracle oinstall 64 May  5 14:53 19 -> /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_lgwr_31863.trc

l-wx------ 1 oracle oinstall 64 May  5 14:48 2 -> /dev/null

l-wx------ 1 oracle oinstall 64 May  5 14:53 20 -> /u02/app/oracle/diag/rdbms/oratest/oratest/trace/oratest_lgwr_31863.trm

lrwx------ 1 oracle oinstall 64 May  5 14:48 256 -> /u02/app/oracle/oradata/oratest/control01.ctl (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 257 -> /u02/app/oracle/flash_recovery_area/oratest/control02.ctl (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 258 -> /u02/app/oracle/oradata/oratest/redo01.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 259 -> /u02/app/oracle/oradata/oratest/redo02.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 260 -> /u02/app/oracle/oradata/oratest/redo03.log (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 261 -> /u02/app/oracle/oradata/oratest/system01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 262 -> /u02/app/oracle/oradata/oratest/sysaux01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 263 -> /u02/app/oracle/oradata/oratest/undotbs01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 264 -> /u02/app/oracle/oradata/oratest/users01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 265 -> /u02/app/oracle/oradata/oratest/example01.dbf (deleted)

lrwx------ 1 oracle oinstall 64 May  5 14:48 266 -> /u02/app/oracle/oradata/oratest/temp01.dbf (deleted)

lr-x------ 1 oracle oinstall 64 May  5 14:48 3 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 4 -> /dev/null

lrwx------ 1 oracle oinstall 64 May  5 14:48 5 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lr-x------ 1 oracle oinstall 64 May  5 14:48 6 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 7 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 8 -> /dev/null

lr-x------ 1 oracle oinstall 64 May  5 14:48 9 -> /dev/null

[root@orcltest fd]#

 

 

此時,不用管了,只要我們保證所有的檔案以及到制定位置就可以了,下邊關閉資料庫即可。

 

3.3  如果資料庫還沒有關掉則關閉資料庫

[oracle@orcltest fd]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Tue May 5 15:01:54 2015

 

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

 

 

Connected to:

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

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

 

SQL> archive log list;

ORA-03113: end-of-file on communication channel

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

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

[oracle@orcltest fd]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.3.0 Production on Tue May 5 15:03:40 2015

 

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

 

 

Connected to:

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

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

 

 

SQL> set line 9999

SQL> col HOST_NAME format a10

SQL> select INSTANCE_NAME,HOST_NAME,VERSION,STARTUP_TIME,STATUS,ACTIVE_STATE,INSTANCE_ROLE,DATABASE_STATUS from gv$INSTANCE;

 

INSTANCE_NAME    HOST_NAME  VERSION           STARTUP_TIME        STATUS       ACTIVE_ST INSTANCE_ROLE      DATABASE_STATUS

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

oratest          orcltest   11.2.0.3.0        2015-05-05 15:03:11 OPEN         NORMAL    PRIMARY_INSTANCE   ACTIVE

 

 

SQL> select sysdate from dual;

 

SYSDATE

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

2015-05-05 15:06:48

 

SQL>

SQL> ! ps -ef|grep ora_lgwr_

oracle  32173     1  0 15:03 ?        00:00:00 ora_lgwr_oratest

oracle   32285 32274  0 15:09 pts/4    00:00:00 /bin/bash -c  ps -ef|grep ora_lgwr_

oracle   32287 32285  0 15:09 pts/4    00:00:00 grep ora_lgwr_

 

SQL> select count(1) from aa;

 

  COUNT(1)

----------

    150406

 

SQL>

 

資料庫自動重啟了,而且資料也沒有丟失,如果沒有重啟,我們可以手動重啟一下,我們再次檢視目錄。

 

 

 

[root@orcltest ~]# cd /proc/32173/fd

[root@orcltest fd]# ll

total 0

lr-x------ 1 root root 64 May  5 15:10 0 -> /dev/null

l-wx------ 1 root root 64 May  5 15:10 1 -> /dev/null

lr-x------ 1 root root 64 May  5 15:10 10 -> /dev/null

lrwx------ 1 root root 64 May  5 15:10 11 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lr-x------ 1 root root 64 May  5 15:10 12 -> /dev/null

lr-x------ 1 root root 64 May  5 15:10 13 -> /dev/null

lr-x------ 1 root root 64 May  5 15:10 14 -> /dev/null

lr-x------ 1 root root 64 May  5 15:10 15 -> /dev/null

lr-x------ 1 root root 64 May  5 15:10 16 -> /dev/zero

lr-x------ 1 root root 64 May  5 15:10 17 -> /u01/app/11.2.0/grid/dbs/hc_+ASM.dat

l-wx------ 1 root root 64 May  5 15:10 18 -> /u01/app/11.2.0/grid/log/orcltest/alertorcltest.log

lr-x------ 1 root root 64 May  5 15:10 19 -> /dev/zero

l-wx------ 1 root root 64 May  5 15:10 2 -> /dev/null

lrwx------ 1 root root 64 May  5 15:10 20 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lr-x------ 1 root root 64 May  5 15:10 21 -> /u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

lr-x------ 1 root root 64 May  5 15:10 22 -> /proc/32173/fd

lr-x------ 1 root root 64 May  5 15:10 23 -> /dev/zero

lrwx------ 1 root root 64 May  5 15:10 24 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/hc_oratest.dat

lrwx------ 1 root root 64 May  5 15:10 25 -> /u02/app/oracle/product/11.2.0/dbhome_1/dbs/lkORATEST

lrwx------ 1 root root 64 May  5 15:10 256 -> /u02/app/oracle/oradata/oratest/control01.ctl

lrwx------ 1 root root 64 May  5 15:10 257 -> /u02/app/oracle/flash_recovery_area/oratest/control02.ctl

lrwx------ 1 root root 64 May  5 15:10 258 -> /u02/app/oracle/oradata/oratest/redo01.log

lrwx------ 1 root root 64 May  5 15:10 259 -> /u02/app/oracle/oradata/oratest/redo02.log

lr-x------ 1 root root 64 May  5 15:10 26 -> /u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg/oraus.msb

lrwx------ 1 root root 64 May  5 15:10 260 -> /u02/app/oracle/oradata/oratest/redo03.log

lrwx------ 1 root root 64 May  5 15:10 261 -> /u02/app/oracle/oradata/oratest/system01.dbf

lrwx------ 1 root root 64 May  5 15:10 262 -> /u02/app/oracle/oradata/oratest/sysaux01.dbf

lrwx------ 1 root root 64 May  5 15:10 263 -> /u02/app/oracle/oradata/oratest/undotbs01.dbf

lrwx------ 1 root root 64 May  5 15:10 264 -> /u02/app/oracle/oradata/oratest/users01.dbf

lrwx------ 1 root root 64 May  5 15:10 265 -> /u02/app/oracle/oradata/oratest/example01.dbf

lrwx------ 1 root root 64 May  5 15:10 266 -> /u02/app/oracle/oradata/oratest/temp01.dbf

lrwx------ 1 root root 64 May  5 15:10 3 -> /u01/app/11.2.0/grid/log/orcltest/agent/ohasd/oraagent_grid/oraagent_gridOUT.log

l-wx------ 1 root root 64 May  5 15:10 4 -> /u01/app/11.2.0/grid/log/orcltest/agent/ohasd/oraagent_grid/oraagent_grid.log

lr-x------ 1 root root 64 May  5 15:10 5 -> /dev/null

lrwx------ 1 root root 64 May  5 15:10 6 -> socket:[25060]

lrwx------ 1 root root 64 May  5 15:10 7 -> socket:[25061]

lrwx------ 1 root root 64 May  5 15:10 8 -> socket:[25062]

lrwx------ 1 root root 64 May  5 15:10 9 -> socket:[25063]

[root@orcltest fd]#

[root@orcltest ~]# cd /proc/31863/fd

-bash: cd: /proc/31863/fd: No such file or directory

 

 

此時資料檔案都已經正常了,每次啟動資料庫例項後,程式都會再下生成一個相應的以程式號命名的目錄,存放操作中涉及到的檔案控制程式碼,此時程式對應的目錄已經變為,而原來的目錄已經不存在了 

 

4  總結:

 

當我們進行作業系統命令的時候,切忌不可隨意加引數,就算一定要用,也要確定再三後才能執行,否則對於資料庫而言,可以說是災難性的。這裡只是測試了一下刪除下的全部檔案,試想一下,如果你當初執行的是呢?可能情況就要更加複雜一點了,恢復需要的步驟也就更多了。 

由於是在資料庫狀態下直接進行了破壞性操作,對於還來不及寫入的那部分操作,肯定是會丟失的,因為我們透過檔案控制程式碼號恢復出來的日誌檔案中,並不一定包含資料庫的最新變更,即便如此,對於誤操作的恢復,還是有一定意義的,至少可以在你沒有任何備份的情況下,多提供了一根救命稻草來拯救你的資料庫,再次強調一下,後,千萬不要著急地關閉資料庫重啟!!!否則就等著哭吧!!! 

 

 

 

 

5  其他相關文章連結

RMAN相關連線:

【RMAN】利用備份片還原資料庫(上): http://blog.itpub.net/26736162/viewspace-1621581/ 

【RMAN】利用備份片還原資料庫(中):http://blog.itpub.net/26736162/viewspace-1621661/ 

【RMAN】利用備份片還原資料庫(下):http://blog.itpub.net/26736162/viewspace-1621672/ 

【RMAN】利用備份片還原資料庫(中)-附加 http://blog.itpub.net/26736162/viewspace-1621938/

 

 

Rman跨版本恢復:

關於10g的跨小版本恢復參考:http://blog.chinaunix.net/uid-26736162-id-4942816.html

關於11g的跨小版本恢復參考:http://blog.itpub.net/26736162/viewspace-1565655/

關於在不同版本和平臺之間進行還原或複製的常見問題 :http://blog.itpub.net/26736162/viewspace-1549041/

RMAN跨版本恢復(下)--大版本異機恢復: http://blog.itpub.net/26736162/viewspace-1562583/

 

undo表空間的恢復:

undo表空間檔案丟失恢復(1)--有備份的情況下恢復:http://blog.itpub.net/26736162/viewspace-1458654/ 

undo表空間檔案丟失恢復(2)--無備份有redo的情況下恢復:http://blog.itpub.net/26736162/viewspace-1458663/ 

undo表空間檔案丟失恢復(3)--無備份無redo的情況下恢復:http://blog.itpub.net/26736162/viewspace-1458750/ 

undo表空間檔案丟失恢復(4)--無備份無recover的情況下恢復http://blog.itpub.net/26736162/viewspace-1458787/

 




About Me

...............................................................................................................................

● 本文作者:小麥苗,只專注於資料庫的技術,更注重技術的運用

● 本文在itpub(http://blog.itpub.net/26736162)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/viewspace-1623938/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● QQ群:230161599     微信群:私聊

● 聯絡我請加QQ好友(646634621),註明新增緣由

● 於 2017-07-01 09:00 ~ 2017-07-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

...............................................................................................................................

拿起手機使用微信客戶端掃描下邊的左邊圖片來關注小麥苗的微信公眾號:xiaomaimiaolhr,掃描右邊的二維碼加入小麥苗的QQ群,學習最實用的資料庫技術。

【RMAN】rm -rf 誤操作的恢復過程
DBA筆試面試講解
歡迎與我聯絡

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28628435/viewspace-1984446/,如需轉載,請註明出處,否則將追究法律責任。

相關文章