【備份恢復】非歸檔模式下丟失任意資料檔案 恢復操作

不一樣的天空w發表於2016-10-20

非歸檔模式下丟失任意資料檔案
前提需要有備份檔案

1) 檢視資料庫歸檔模式,修改為非歸檔模式

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            /u01/app/backup

Oldest online log sequence     1

Next log sequence to archive   2

Current log sequence           2

SQL> alter database noarchivelog;

 

Database altered.

 

SQL> archive log list;

Database log mode              No Archive Mode

Automatic archival             Disabled

Archive destination            /u01/app/backup

Oldest online log sequence     1

Current log sequence           2

 

2) 資料庫啟動到 mount 模式

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area  830930944 bytes

Fixed Size                  2257800 bytes

Variable Size             503319672 bytes

Database Buffers          322961408 bytes

Redo Buffers                2392064 bytes

Database mounted.

 

3) 備份資料庫(在非歸檔模式下, rman 備份需要資料庫在 mount 模式下,以將冷備的資訊記錄到控制檔案中,控制檔案資料檔案庫

[oracle@wang ORA11GR2]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 23 13:45:13 2016

 

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

 

connected to target database: ORA11GR2 (DBID=237843809, not open)

 

RMAN> backup database format '/u01/app/backup/db_%U.rmn';

 

Starting backup at 23-SEP-16

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=/u01/app/oracle/oradata/ORA11GR2/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/ORA11GR2/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/ORA11GR2/users01.dbf

channel ORA_DISK_1: starting piece 1 at 23-SEP-16

channel ORA_DISK_1: finished piece 1 at 23-SEP-16

piece handle=/u01/app/backup/db_06rghfmn_1_1.rmn tag=TAG20160923T134702 comment=NONE

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

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 23-SEP-16

channel ORA_DISK_1: finished piece 1 at 23-SEP-16

piece handle=/u01/app/backup/db_07rghfo4_1_1.rmn tag=TAG20160923T134702 comment=NONE

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

Finished backup at 23-SEP-16

 

4) 開啟資料庫

SQL> alter database open;

 

Database altered.

 

5) 刪除所有資料檔案

[oracle@wang trace]$ cd /u01/app/oracle/oradata/ORA11GR2/

[oracle@wang ORA11GR2]$ ls *.dbf

example01.dbf  system01.dbf  undotbs01.dbf

sysaux01.dbf   temp01.dbf    users01.dbf

[oracle@wang ORA11GR2]$

[oracle@wang ORA11GR2]$ rm *.dbf

[oracle@wang ORA11GR2]$

[oracle@wang ORA11GR2]$ ls *.dbf

ls: *.dbf: No such file or directory

[oracle@wang ORA11GR2]$

 

6) 此時再登陸 sqlplus 會出現如下錯誤:

[oracle@wang ORA11GR2]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 23 13:55:08 2016

 

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

 

ERROR:

ORA-01075: you are currently logged on

 

Enter user-name:

注:由於所有資料檔案全部丟失,但資料庫的後臺程式都啟動著,所以會出現如上錯誤,解決辦法是 kill掉所有資料庫的程式和分配的記憶體


7) Kill
程式和記憶體,再次登陸 sqlplus,沒有任何問題

[oracle@wang ~]$  ps -ef |grep $ORACLE_SID |grep -v grep|awk '{print $2}' | xargs kill -9

[oracle@wang ~]$

[oracle@wang ~]$  ipcs -m | grep oracle | awk '{print $2}' | xargs ipcrm shm

resource(s) deleted

[oracle@wang ~]$

[oracle@wang ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 23 13:57:38 2016

 

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

 

Connected to an idle instance.

 

SQL> startup mount;  (在mount狀態下修復)   

ORACLE instance started.

 

Total System Global Area  830930944 bytes

Fixed Size                  2257800 bytes

Variable Size             503319672 bytes

Database Buffers          322961408 bytes

Redo Buffers                2392064 bytes

Database mounted.

 

1)  透過 rman 恢復丟失的資料檔案

[oracle@wang dbs]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 23 15:26:22 2016

 

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

 

connected to target database: ORA11GR2 (DBID=237843809, not open)

 

RMAN> restore database;(重儲)

 

Starting restore at 23-SEP-16

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=18 device type=DISK

 

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/ORA11GR2/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORA11GR2/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/ORA11GR2/example01.dbf

channel ORA_DISK_1: reading from backup piece /u01/app/backup/db_06rghfmn_1_1.rmn

channel ORA_DISK_1: piece handle=/u01/app/backup/db_06rghfmn_1_1.rmn tag=TAG20160923T134702

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:45

Finished restore at 23-SEP-16

 

RMAN> recover database;(恢復)

 

Starting recover at 23-SEP-16

using channel ORA_DISK_1

 

starting media recovery

 

archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/oradata/ORA11GR2/redo01_a.log

archived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/oradata/ORA11GR2/redo02.log

archived log file name=/u01/app/oracle/oradata/ORA11GR2/redo02.log thread=1 sequence=2

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

Finished recover at 23-SEP-16

 

2)  resetlogs 方式開啟資料庫

RMAN> alter database open resetlogs;

 

database opened

 

RMAN> host 'ls /u01/app/oracle/oradata/ORA11GR2/*.dbf';

rman下只認host

/u01/app/oracle/oradata/ORA11GR2/example01.dbf

/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf

/u01/app/oracle/oradata/ORA11GR2/system01.dbf

/u01/app/oracle/oradata/ORA11GR2/temp01.dbf

/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf

/u01/app/oracle/oradata/ORA11GR2/users01.dbf

host command complete

資料檔案全部恢復回來了!!!!!!!!!!!

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

相關文章