Oracle:只有rman備份(資料,參數,日誌,控制檔案全丟失)的恢複,oraclerman

來源:互聯網
上載者:User

Oracle:只有rman備份(資料,參數,日誌,控制檔案全丟失)的恢複,oraclerman
Oracle:只有rman備份(資料,參數,日誌,控制檔案全丟失)的恢複
只有rman的備份檔案恢複過程Created by foway in uplooking.com 2008: 歡迎轉載,但請保留本行說明,謝謝!

1.        通過rman備份檔案恢複spfile
2.        通過rman備份檔案恢複controlfile
3.        通過rman備份檔案恢複datafile
4.        利用恢複回來的controlfile和datafile產生redolog
5.        測試交易是否存在,並全備

我系統內容所有的檔案如下:

[oracle@foway dbs]$ pwd
/opt/oracle/10g/dbs
[oracle@foway dbs]$ ls
initdw.ora   init.ora
[oracle@foway dbs]$ls /opt/oracle/oradata
已沒有任何資料
[oracle@foway dbs]$ls /opt/oracle/admin
已沒有任何資料
[oracle@foway dbs] ls /opt/oracle/flash_recovery_area/
ORCL
[oracle@foway dbs]ls /opt/oracle/flash_recovery_area/ORCL/backupset/
2008_07_18
[oracle@foway dbs]ls /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/
o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp
o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp

在我這台電腦上, ,系統中所有的ORCL相關的資料檔案,參數檔案,記錄檔,控制檔案全部不在了, 沒有其他可用的備份檔案了,只有rman備份的檔案在,這可怎麼辦呢?

沒辦法只能恢複了,可怎麼恢複呢?

要恢複資料檔案用rman備份? 能嗎? 當然不能了,因為restore必須在mount or open狀態下.
參數檔案,控制檔案都沒有怎麼mount?

要mount必須有參數檔案,控制檔案,為此我們必須解決這2個難題了.
在解決難題前先準備ORCL的必須的目錄:
[oracle@foway dbs]mkdir /opt/oracle/oradata/orcl
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/adump –p
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/cdump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/bdump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/udump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/dpdump
[oracle@foway dbs]mkdir /opt/oracle/admin/orcl/pfile


難題1:spfile
有人說沒參數檔案我建立立一個pfile,當然這個辦法是可行的,不過在10g中rman備份是自動備份了spfile的,所以我們可以利用rman來恢複spfile了.
[oracle@foway dbs]rman target / nocatalog
Recovery Manager: Release 10.2.0.4.0 - Production on Fri Jul 18 21:21:47 2008

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

connected to target database (not started)

RMAN> list backup;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 07/18/2008 21:24:37
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directorylist copy;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 07/18/2008 21:24:51
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory

看到上面的是正常的,因為資料庫沒有啟動呢.
於是我們先啟動資料庫到nomout下
RMAN>startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/10g/dbs/initorcl.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area     159383552 bytes

Fixed Size                   1218268 bytes
Variable Size                 54528292 bytes
Database Buffers          100663296 bytes
Redo Buffers                2973696 bytes

RMAN>list backup;
RMAN>list copy;
將與上次執行看到的一樣,此時也是正常的,不必擔心,下面就是利用rman備份檔案來解決難題1了.
RMAN> restore spfile
from '/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp';
Starting restore at 18-JUL-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 18-JUL-08

下面是來驗證spfileorcl.ora檔案是否已存在:
[oracle@foway dbs]$ pwd
/opt/oracle/10g/dbs
[oracle@foway dbs]$ ls
initdw.ora   init.ora   spfileorcl.ora
恭喜你:spfile已恢複了
有了參數檔案,就需要解決控制檔案恢複了

難題2. 控制檔案恢複
這個又怎麼恢複呢? 用rman的自動備份控制檔案的rman備份嗎? 是的沒錯,只有從rman備份檔案中提取出來的controlfile才能使用rman備份檔案恢複datafile的.

那麼這裡有來種辦法來實現從rman備份檔案中提取出controlfie了.
方法1.
RMAN>restore controlfile from ‘/…備份檔案..’;
恢複的控制檔案將放在$ORACLE_HOME/dbs/cncontrl.dbf不過這個方法有時恢複的控制檔案中記錄的dbname與實際不一致.

方法2: 利用dbms_backup_restore提取controlfile
步驟:
[oracle@foway dbs]$sqlplus /nolog
SQL*Plus: Release 10.2.0.4.0 - Production on Fri Jul 18 21:38:21 2008

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

SQL> conn /as sysdba
Connected.
由於在剛才使用rman時執行了startup nomount,所以這裡是connected,下面我們到nomount狀態
SQL> startup force nomount
ORACLE instance started.

Total System Global Area   167772160 bytes
Fixed Size                1218316 bytes
Variable Size              62916852 bytes
Database Buffers       100663296 bytes
Redo Buffers             2973696 bytes
SQL>DECLARE
2devtype varchar2(256);
3done boolean;
4BEGIN
5devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');
6sys.dbms_backup_restore.restoreSetDatafile;
7sys.dbms_backup_restore.restoreControlfileTo(cfname=>'/opt/oracle/oradata/orcl/control01.ctl');
8sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp',params=>null);
9 sys.dbms_backup_restore.deviceDeallocate;
10 end;
11/

PL/SQL procedure successfully completed.

下面驗證control01.ctl是否恢複:
[oracle@foway dbs]$ ls /opt/oracle/oradata/orcl/
control01.ctl
[oracle@foway dbs]$
看到了control01.ctl 恭喜你:難題2 解決了.
於是我們可以啟動資料庫到mount狀態了.
[oracle@foway dbs]$sqlplus /nolog

SQL*Plus: Release 10.2.0.4   - Production on Fri Jul 18 21:45:32 2008

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

SQL> conn /as sysdba
Connected.
SQL> startup force mount
ORACLE instance started.

Total System Global Area   167772160 bytes
Fixed Size                1218316 bytes
Variable Size              62916852 bytes
Database Buffers       100663296 bytes
Redo Buffers             2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info

我們已經恢複了控制檔案了,怎麼還是有錯誤呢,其實不用擔心,看看spfile中的記錄先
SQL> show parameter control_files

NAME                               TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                      string    /opt/oracle/oradata/orcl/contr
                                             ol01.ctl, /opt/oracle/oradata/
                                             orcl/control02.ctl, /opt/oracl
                                             e/oradata/orcl/control03.ctl
SQL>
既然如此,我們就把控制檔案同步下好了.
SQL> ho cp /opt/oracle/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/control02.ctl
SQL> ho cp /opt/oracle/oradata/orcl/control01.ctl /opt/oracle/oradata/orcl/control03.ctl
SQL> alter database mount;

Database altered.

SQL> ho ls /opt/oracle/oradata/orcl/
control01.ctl   control02.ctl   control03.ctl

好了到這裡我們已經成功解決了難題2了.

有了恢複後的控制檔案,我們就可以使用rman查看與使用以前的rman備份了.

恢複datafile 步驟:
rman target / nocatalog

Recovery Manager: Release 10.2.0.4 - Production on Fri Jul 18 21:49:10 2008

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

connected to target database: ORCL (DBID=1188209463, not open)
using target database control file instead of recovery catalog

RMAN>
看到了 紅色部分了嗎,太好了終於看到了正常的rman登陸資訊了.
那就list copy|backup 看看能找到我們的
o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp
o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp
檔案嗎.
RMAN> list copy;

specification does not match any archive log in the recovery catalog

RMAN> list backup;


List of Backup Sets
===================

BS Key   Type LV Size    Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1    Full 495.41M DISK        00:00:41     18-JUL-08   
       BP Key: 1 Status: AVAILABLE   Compressed: NO   Tag: TAG20080718T203240
       Piece Name: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp
   List of Datafiles in backup set 1
   File LV Type Ckp SCN Ckp Time   Name
   ---- -- ---- ---------- --------- ----
   1    Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/system01.dbf
   2    Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/undotbs01.dbf
   3    Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/sysaux01.dbf
   4    Full 453304     18-JUL-08 /opt/oracle/oradata/orcl/users01.dbf

RMAN>
太好了,總於可以使用restore,recover來恢複datafile了.
RMAN> restore database;

Starting restore at 18-JUL-08
Starting implicit crosscheck backup at 18-JUL-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 18-JUL-08

Starting implicit crosscheck copy at 18-JUL-08
using channel ORA_DISK_1
Finished implicit crosscheck copy at 18-JUL-08

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_ncsnf_TAG20080718T203240_482fls2h_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /opt/oracle/oradata/orcl/system01.dbf
restoring datafile 00002 to /opt/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /opt/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /opt/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/opt/oracle/flash_recovery_area/ORCL/backupset/2008_07_18/o1_mf_nnndf_TAG20080718T203240_482fkb0k_.bkp tag=TAG20080718T203240
channel ORA_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 18-JUL-08

RMAN>
此時可以在$ORACLE_BASE/oradata/orcl/下看到期望已久的datafile了.
[oracle@foway dbs] ls /opt/oracle/oradata/orcl/
control01.ctl   control02.ctl   control03.ctl   sysaux01.dbf   system01.dbf   undotbs01.dbf   users01.dbf
[oracle@foway dbs]
不過此時還沒有完哈,需要在接在勵.

由於沒有redo log記錄檔所以我們不應用日誌恢複:
RMAN> recover database noredo;

Starting recover at 18-JUL-08
using channel ORA_DISK_1
Finished recover at 18-JUL-08

RMAN>

到目前我們已經擁有了參數檔案,控制檔案,資料檔案了:
[oracle@foway dbs] ls /opt/oracle/oradata/orcl/
ls /opt/oracle/oradata/orcl/
control01.ctl   control02.ctl   control03.ctl   sysaux01.dbf   system01.dbf  
undotbs01.dbf   users01.dbf
[oracle@foway dbs] ls /opt/oracle/10g/dbs/
alert_orcl.log   hc_orcl.dat   initdw.ora   init.ora   lkORCL   spfileorcl.ora
還差一個密碼檔案,以及相關的記錄檔了.
先解決密碼檔案:
[oracle@foway dbs] orapwd file=/opt/oracle/10g/dbs/orapworcl password=uplooking entries=5
[oracle@foway dbs] ls /opt/oracle/10g/dbs/
ls /opt/oracle/10g/dbs/
alert_orcl.log   initdw.ora   lkORCL     spfileorcl.ora
hc_orcl.dat     init.ora orapworcl

下面需要大家堅持不懈的完成最後一個工作了.
那就是通過已經恢複的controlfile and datafile 來演算出redo log file了.
步驟:
[oracle@foway dbs]sqlplus /nolog
SQL*Plus: Release 10.2.0.4 - Production on Fri Jul 18 21:58:05 2008

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

SQL> conn /as sysdba
Connected.
SQL> startup force mount
ORACLE instance started.

Total System Global Area   167772160 bytes
Fixed Size                1218316 bytes
Variable Size              62916852 bytes
Database Buffers       100663296 bytes
Redo Buffers             2973696 bytes
Database mounted.
SQL>alter system set "_allow_resetlogs_corruption"=TRUE;
alter system set "_allow_resetlogs_corruption"=TRUE
                *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified

SQL> alter system set "_allow_resetlogs_corruption"=TRUE scope=spfile;

System altered.

SQL>ho ls /opt/oracle/oradata/orcl/
control01.ctl   control03.ctl   sysaux01.dbf   undotbs01.dbf
control02.ctl   orapworcl    system01.dbf   users01.dbf

下面沒有redo log file ,下面我將演算出redo log
SQL>startup force
ORACLE instance started.

Total System Global Area   167772160 bytes
Fixed Size                1218316 bytes
Variable Size              62916852 bytes
Database Buffers       100663296 bytes
Redo Buffers             2973696 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL>alter database open resetlogs;

Database altered.
SQL> ho ls /opt/oracle/oradata/orcl/
control01.ctl   orapworcl redo03.log temp01.dbf
control02.ctl   redo01.log   sysaux01.dbf   undotbs01.dbf
control03.ctl   redo02.log   system01.dbf   users01.dbf

SQL>
好了到這裡,非常高興了,你已經成功的從只有rman備份檔案中恢複了參數檔案,控制檔案,所有資料檔案,記錄檔了.

通常到這裡還需要你全備資料庫的哈,別忘了!原文地址 http://www.oracle.com.cn/viewthread.php?tid=136013

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.